CAI_Support
Senior Member
START
CALLSUB LCD_INIT
DELAY 4
SET RAM20 0x80 # address first line, first byte
CALLSUB LCD_CMD
SET RAM20 0x4F # data byte ascii code for O
CALLSUB LCD_DATA
SET RAM20 0x4B # data byte ascii code for K
CALLSUB LCD_DATA
TASKS:
SET VAR2 T1
GOTO TASKS
END
LCD_INIT:
DELAY 20
I2CWRITE 1 0 78 #I2C address
I2CWRITE 0 0 0x38 #write 0x3 lit on
I2CWRITE 0 0 0x3C #E bit on
I2CWRITE 0 0 0x38 #write 0x3
DELAY 7
I2CWRITE 0 0 0x38 #write 0x3
I2CWRITE 0 0 0x3C #E bit on
I2CWRITE 0 0 0x38 #write 0x3
DELAY 1
SET RAM20 0x32 # still part of init
CALLSUB LCD_CMD
DELAY 5
SET RAM20 0x28 # 4 bit, 2 line, font size 5x8
CALLSUB LCD_CMD
DELAY 5
SET RAM20 8 #display off
CALLSUB LCD_CMD
DELAY 5
SET RAM20 1 # return home
CALLSUB LCD_CMD
DELAY 5
SET RAM20 6 # entry mode on
CALLSUB LCD_CMD
DELAY 5
SET RAM20 0xF #display on, cursor on, blink on
CALLSUB LCD_CMD
RET
LCD_CMD:
ANDB RAM20 0xF0 RAM21 #upper nibble
ORB RAM21 8 RAM21 #turn on lit
ORB RAM21 4 RAM22 #E bit on
I2CWRITE 0 0 RAM21
I2CWRITE 0 0 RAM22
I2CWRITE 0 0 RAM21
DELAY 1
ROTL RAM20 4 RAM21 #move to upper nibble
ANDB RAM21 0xF0 RAM21 #only upper 4 bit
ORB RAM21 8 RAM21 #turn on lit
ORB RAM21 4 RAM22 #E bit on
I2CWRITE 0 0 RAM21
I2CWRITE 0 0 RAM22
I2CWRITE 0 0 RAM21
DELAY 1
RET
LCD_DATA:
ANDB RAM20 0xF0 RAM21 #upper nibble
ORB RAM21 9 RAM21 #turn on lit, R/S bit on
I2CWRITE 0 0 RAM21
ORB RAM21 4 RAM22 #E bit on
I2CWRITE 0 0 RAM22
I2CWRITE 0 0 RAM21
DELAY 1
ROTL RAM20 4 RAM21 #move up 4 bits
ANDB RAM21 0xF0 RAM21 #upper nibble
ORB RAM21 9 RAM21 #turn on lit, R/S bit on
I2CWRITE 0 0 RAM21
ORB RAM21 4 RAM22 #E bit on
I2CWRITE 0 0 RAM22
I2CWRITE 0 0 RAM21
DELAY 1
RET
If continuously writing bytes to the same line, you do not have to set cursor position between write byte
CALLSUB LCD_INIT
DELAY 4
SET RAM20 0x80 # address first line, first byte
CALLSUB LCD_CMD
SET RAM20 0x4F # data byte ascii code for O
CALLSUB LCD_DATA
SET RAM20 0x4B # data byte ascii code for K
CALLSUB LCD_DATA
TASKS:
SET VAR2 T1
GOTO TASKS
END
LCD_INIT:
DELAY 20
I2CWRITE 1 0 78 #I2C address
I2CWRITE 0 0 0x38 #write 0x3 lit on
I2CWRITE 0 0 0x3C #E bit on
I2CWRITE 0 0 0x38 #write 0x3
DELAY 7
I2CWRITE 0 0 0x38 #write 0x3
I2CWRITE 0 0 0x3C #E bit on
I2CWRITE 0 0 0x38 #write 0x3
DELAY 1
SET RAM20 0x32 # still part of init
CALLSUB LCD_CMD
DELAY 5
SET RAM20 0x28 # 4 bit, 2 line, font size 5x8
CALLSUB LCD_CMD
DELAY 5
SET RAM20 8 #display off
CALLSUB LCD_CMD
DELAY 5
SET RAM20 1 # return home
CALLSUB LCD_CMD
DELAY 5
SET RAM20 6 # entry mode on
CALLSUB LCD_CMD
DELAY 5
SET RAM20 0xF #display on, cursor on, blink on
CALLSUB LCD_CMD
RET
LCD_CMD:
ANDB RAM20 0xF0 RAM21 #upper nibble
ORB RAM21 8 RAM21 #turn on lit
ORB RAM21 4 RAM22 #E bit on
I2CWRITE 0 0 RAM21
I2CWRITE 0 0 RAM22
I2CWRITE 0 0 RAM21
DELAY 1
ROTL RAM20 4 RAM21 #move to upper nibble
ANDB RAM21 0xF0 RAM21 #only upper 4 bit
ORB RAM21 8 RAM21 #turn on lit
ORB RAM21 4 RAM22 #E bit on
I2CWRITE 0 0 RAM21
I2CWRITE 0 0 RAM22
I2CWRITE 0 0 RAM21
DELAY 1
RET
LCD_DATA:
ANDB RAM20 0xF0 RAM21 #upper nibble
ORB RAM21 9 RAM21 #turn on lit, R/S bit on
I2CWRITE 0 0 RAM21
ORB RAM21 4 RAM22 #E bit on
I2CWRITE 0 0 RAM22
I2CWRITE 0 0 RAM21
DELAY 1
ROTL RAM20 4 RAM21 #move up 4 bits
ANDB RAM21 0xF0 RAM21 #upper nibble
ORB RAM21 9 RAM21 #turn on lit, R/S bit on
I2CWRITE 0 0 RAM21
ORB RAM21 4 RAM22 #E bit on
I2CWRITE 0 0 RAM22
I2CWRITE 0 0 RAM21
DELAY 1
RET
If continuously writing bytes to the same line, you do not have to set cursor position between write byte