SHIFTOUT syntax not understood - can't send any variables contents, while text is ok
Hello,
I'm trying to send the content of a variable to a SPI LCD.
As long as I send "text", it works; the LCD shows "text".
When I try to send the content of a variable, i.e. a counter, the display goes crazy and shows sort of random characters.
Any idea what I'm doing wrong or missing?
Code:
' PIC 16F690 Fuses (MPASM)
@ __config _FCMEN_OFF &_IESO_OFF &_CPD_OFF &_WDT_OFF &_INTRC_OSC_NOCLKOUT &_BOR_OFF &_CP_OFF &_PWRTE_OFF &_MCLRE_OFF
' Registers 76543210
OPTION_REG = %10000000 'PORT A&B Pull-Ups disabled (look WPUA & WPUB)
OSCCON = %01110000 'Internal RC set to 8Mhz
ANSEL = %00000000 'Disable analog inputs Channels 0 to 7
ANSELH = %00000000 'Disable analog inputs Channels 8 to 11
WPUB = %00000000 'Disable weak pull-ups
ADCON0 = %00000000 'A/D Module is OFF
CM1CON0 = %00000000 'Comparator1 Module is OFF
CM2CON0 = %00000000 'Comparator2 Module is OFF
INTCON = %00000000 'INTerrupts CONtrol
TRISA = %00000000 'Set Input/Output (0 to 5)
PORTA = %00000000 'Ports High/Low (0 to 5)
TRISB = %00000000 'Set Input/Output (4 to 7)
PORTB = %00000000 'Ports High/Low (4 to 7)
TRISC = %00000000 'Set Input/Output (0 to 7)
PORTC = %00000000 'Ports High/Low (0 to 7)
'-------------------------------------------------------------------------------
' Defines
define OSC 8
'-------------------------------------------------------------------------------
' Variables
RS var PORTB.5 'instruction or command =0, data =1
SCK var PORTB.6 'Clock pin
SDO var PORTB.4 'Data Out pin (SI on display's side)
Reset var PORTB.7 'LCD's reset pin - could be connected to VDD (+VDC)
CSB var PORTC.7 'LOW active pin - could be connected to VSS (GND)
Mode con 1 'MSBFIRST - Clock idles low
RS_t con 1 'Set PAUSE time for RS transition
Cnt_A var byte 'just a counter variable
cnt_a = 0
'-------------------------------------------------------------------------------
INIT:
' "EA-DOGM162L-A" LCD display specific settings
pause 40 'wait for LCD to startup
high reset : pause 1
low RS : pauseus RS_t
shiftout sdo,SCK,mode,[%00111001] : pauseus 20 'Function Set/Instr. table 1
shiftout sdo,SCK,mode,[%00011100] : pauseus 20 'Bias set
shiftout sdo,SCK,mode,[%01010010] : pauseus 20 'Power control + Contrast (HiByte)
shiftout sdo,SCK,mode,[%01101001] : pauseus 20 'Follower control
shiftout sdo,SCK,mode,[%01110111] : pauseus 20 'Contrast (LowByte)
shiftout sdo,SCK,mode,[%00001100] : pauseus 20 'Display ON
'-------------------------------------------------------------------------------
MAIN:
low rs : pauseus RS_t 'set COMMAND mode
shiftout sdo,SCK,mode,[%00000010] : pause 1 'set cursor home
high RS : pauseus RS_t 'set DATA mode
shiftout sdo,SCK,mode,["test"]
pause 500
low rs : pauseus RS_t 'set COMMAND mode
shiftout sdo,SCK,mode,[%00000010] : pause 1 'set cursor home
high RS : pauseus RS_t 'set DATA mode
shiftout sdo,SCK,mode,[Cnt_A]
pause 500
cnt_a = cnt_a + 1
goto main:
Thank you
Roger
NB: most of the time, the "%" in my posts are replaced by some "double-square" symbol; how to I avoid this?
Re: SHIFTOUT syntax not understood - can't send any variables contents, while text is
Try something like
Code:
MyVar = $30+Cnt_A
shiftout sdo,SCK,mode,[MyVar]
If that does not work post exactly what the display is displaying.
SHIFTOUT syntax not understood - can't send any variables contents, while text is ok
Unfortunately it doesn't work.
I see characters, displayed one by one, just if it would be the display's internal character set that is listed. But it is not exactly following the character's set order; some characters follow correctly the table and then it jumps to some further characters and so on.
Every displayed character appears on the first position of the display which is correct according to the "set cursor home" command.
My LCD is a EA DOGM081x-A and ST7036 controlled.
Re: SHIFTOUT syntax not understood - can't send any variables contents, while text is
SHIFTOUT sends the content of the variable in "binary" format, not as ASCII text - which I believe is what the display is expecting. It's like sending a variable using HSEROUT where you use the DEC-modifer to send the content of a variable as text instead of as a "raw number".
Unfortunately SHIFTOUT does not (AFAIK) support any modifiers (DEC, HEX etc) so you need to do it manually. This compile but I can not test it.
Code:
temp = CNT_A / 1000
GOSUB SendIt
CNT_A = CNT_A - (temp * 1000)
temp = CNT_A / 100
GOSUB SendIt
CNT_A = CNT_A - (temp * 100)
temp = CNT_A / 10
GOSUB SendIt
temp = CNT_A - (temp * 10)
GOSUB SendIt
END
SendIt:
SHIFTOUT SDO, SCK, MODE, [temp + 48]
RETURN
/Henrik.
Re: SHIFTOUT syntax not understood - can't send any variables contents, while text is
Thanks a lot Henrik.
Your code works effectively ;)
I'm not used to use the SHIFTOUT command so I got to learn how it works.
Thank you.