
Issue with the Arithmetic Shift Left instruction on a W65C816S processor
I am currently developing an LCD library using the I2C functions I have already developed.
As far as sending data via I2C is concerned, everything is working; I have already tested it on other components and can already write to the screen using this programme
; ==================================================
; Write data to CGRAM/DDRAM
; ==================================================
LDA #%01001001 ; DB7/DB4 -> 0100 Backlight = 1, E = 0, RW = 0, RS = 1
JSR I2C_SEND
LDA #%01001101 ; DB7/DB4 -> 0100 Backlight = 1, E = 1, RW = 0, RS = 1
JSR I2C_SEND
LDA #%01001001 ; DB7/DB4 -> 0100 Backlight = 1, E = 0, RW = 0, RS = 1
JSR I2C_SEND
LDA #%01011001 ; DB7/DB4 -> 1000 Backlight = 1, E = 0, RW = 0, RS = 1
JSR I2C_SEND
LDA #%01011101 ; DB7/DB4 -> 1000 Backlight = 1, E = 1, RW = 0, RS = 1
JSR I2C_SEND
LDA #%01011001 ; DB7/DB4 -> 1000 Backlight = 1, E = 0, RW = 0, RS = 1
JSR I2C_SEND
This piece of code allows the character ‘E’ to be sent to the LCD screen.
I tried to create a function to simply load the desired character into the accumulator and then send it to the screen.
Here is that function:
LCD_WRITE_CHARACTER:
STA $0010
; ======================================
; Envoie des 4 bits de poids fort
; ======================================
AND #%11110000
ORA #%00001001 ; DB7/DB4 -> poids fort Backlight = 1, E = 0, RW = 0, RS = 1
JSR I2C_SEND
ORA #%00000100 ; DB7/DB4 -> poids fort Backlight = 1, E = 1, RW = 0, RS = 1
JSR I2C_SEND
AND #%11111011 ; DB7/DB4 -> poids fort Backlight = 1, E = 0, RW = 0, RS = 1
JSR I2C_SEND
; ======================================
; Envoie des 4 bits de poids faible
; ======================================
LDA $0010
;décalage des 4 bits de poids faible vers poids fort
ASL
ASL
ASL
ASL
AND #%11110000
ORA #%00001001 ; DB7/DB4 -> poids faible Backlight = 1, E = 0, RW = 0, RS = 1
JSR I2C_SEND
ORA #%00000100 ; DB7/DB4 -> poids faible Backlight = 1, E = 0, RW = 0, RS = 1
JSR I2C_SEND
AND #%11111011 ; DB7/DB4 -> poids faible Backlight = 1, E = 0, RW = 0, RS = 1
JSR I2C_SEND
RTS
The address $0010 is used to store the character to be sent so that it can be retrieved after the most significant bit has been sent.
The problem here is that the screen LEDs go out just as the character is sent. I therefore assume that the byte created to match the screen’s 4-bit operation is incorrect. But I can’t see what the problem is here.
According to what I’ve read in the CPU documentation, the Arithmetic Shift Left sets the least significant bit to 0, so this shouldn’t be a carry issue.
On initialisation, the CPU is in Emulation mode (8-bit) and at no point in my programme do I switch to 16-bit mode.
I’m just starting to use the assembler and I might not understand everything, so thank you for taking the time to read this.