Hey guys, I'm having some problems getting my lcd (CFAG160160B) to initialize (Right now its constantly display a black line that goes across the screen).
I know you guys have the some code in C but I am not familiar with it at all. I'm trying to code using assembly using the 9s12 as the micro processor.
Here is how I have it set up, just need another set of eyes to see if I've done something wrong or not
Notes: the delayby1ms is actually a 10ms delay
I know you guys have the some code in C but I am not familiar with it at all. I'm trying to code using assembly using the 9s12 as the micro processor.
Here is how I have it set up, just need another set of eyes to see if I've done something wrong or not
Code:
;Testing
;Trying to output characters to my GLCD
;Port K will be the control of the GLCD
;Port B will be the data input
#include D_variant_registers.inc
DATA equ $1000
PROG equ $2000
STACK equ $2000
REGBLK: equ $0000
lcd_CTRL equ PORTK
lcd_DAT equ PORTB
lcd_dir equ DDRK
lcd_E equ $02
lcd_RS equ $08
lcd_CS equ $04
lcd_RW equ $01
lcd_RST equ $10
; LCD INSTRUCTIONS
;lcd_mode equ $00
;lcd_setCharPitch equ $01
;lcd_setNumOfChar equ $02
;lcd_setTimeDivNum equ $03
;lcd_setCursorPos equ $04
;lcd_setDispStartLower equ $08
;lcd_setDispStartUpper equ $09
;lcd_setCursorLowerAddress equ $0A
;lcd_setCursorUpperAddress equ $0B
org #DATA
counter: rmb 1
;Program start
start:
org #PROG ;
lds #STACK
;INITIALIZATION
movb #$ff,DDRB ; port b = output
movb #$ff,lcd_DIR ; port k = output
clr LCD_CTRL ; Initialize everything in portk K to 0
clr LCD_DAT
bset LCD_CTRL, lcd_RST ; set reset to be high
jsr open_lcd
;trying to output a single character
bset LCD_CTRL, lcd_RS
bset LCD_CTRL, lcd_E
ldaa #$0C
staa LCD_DAT
jsr delayby1ms
bclr LCD_CTRL, lcd_E + lcd_RS
jsr delayby1ms
bset LCD_CTRL, LCD_E
ldaa #%00100000
staa LCD_DAT
jsr delayby1ms
bclr LCD_CTRL, lcd_E
end
open_lcd:
bclr lcd_CTRL,lcd_RS
bclr lcd_CTRL, lcd_E
ldaa #$00 ;data command to set lcd mode
ldab #$2C ;
jsr cmd2lcd
ldaa #$01 ;data command to set lcd CharPitch
ldab #%10000111 ; 8horz, 8vert dots
jsr cmd2lcd
ldaa #$02 ;data command to set lcd NumOfChar/line
ldab #$04 ; num of chars on 1 line
jsr cmd2lcd
ldaa #$03 ;data command to set lcd TimeDivNum
ldab #$9F
jsr cmd2lcd
ldaa #$04 ;data command to set lcd Cursor Position
ldab #%00000111
jsr cmd2lcd
ldaa #$08 ;data command to set lcd Display Start (Lower)
ldab #$00
jsr cmd2lcd
ldaa #$09 ;data command to set lcd Dispplay Start (Upper)
ldab #$00
jsr cmd2lcd
ldaa #$0A ;data command to set lcd Cursor (Lower) Address
ldab #$00
jsr cmd2lcd
ldaa #$0B ;data command to set lcd Cursor (Upper) Address
ldab #$00
jsr cmd2lcd
cmd2lcd:
bclr lcd_CTRL, lcd_RW
bset lcd_CTRL, lcd_RS
bset lcd_CTRL, lcd_E
staa lcd_DAT
bclr lcd_CTRL, lcd_E
jsr delayby1ms
bclr lcd_CTRL, lcd_RS
bset lcd_CTRL, lcd_E
stab lcd_DAT
jsr delayby1ms
bclr lcd_CTRL, lcd_E
rts
delayby1ms:
psha
ldaa #10 ; delay 1 ms
staa counter
d1: ldy #6000 ; 6000 x 4 = 24,000 cycles = 1ms
d: dey ; this instruction takes 1 cycle
bne d ; this instruction takes 3 cycles
dec counter
bne d1 ; not 5ms yet, delay again
Looking for additional LCD resources? Check out our LCD blog for the latest developments in LCD technology.
Last edited: