Electronics4you
Member
Can someone provide me with a simple code for writing just one dot on a GLCD in assembler? The KS0108 control is used.
Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
Plot call SetLCDAddress
clrf Mask
movfw YPos
andlw 0x07
movwf Count
bsf STATUS,C
GetBit rlf Mask,F
decf Count,F
btfss Count,7
goto GetBit
call ReadData ;dummy read
call ReadData
iorwf Mask,F
movfw XPos
andlw 0x3f
iorlw 0x40
call WriteCMD
movfw Mask
call WriteData
return
Cls_1 bsf b_LCD_CS1
bsf b_LCD_CS2
movlw 0x08
movwf ForI
ClsLoopI movlw 0x40
movwf ForJ
call WriteCMD
decf ForI,W
iorlw 0xb8
call WriteCMD
ClsLoopK movlw 0x00
call WriteData
decfsz ForJ,F
goto ClsLoopK
decfsz ForI,F
goto ClsLoopI
clrf XPos
clrf YPos
return
InitLCD_1 bsf b_LCD_CS1
bsf b_LCD_CS2
movlw 0x3f
call WriteCMD
movlw 0xc0
call WriteCMD
movlw 0x40
call WriteCMD
movlw 0xb8
call WriteCMD
return
WaitNotBusy bsf STATUS,RP0
movlw 0xff
movwf TRISB
bcf STATUS,RP0
bsf b_LCD_RW
bcf b_LCD_RS
btfss b_LCD_CS1
goto Skip_CS1
bcf b_CS2
btfsc b_LCD_CS2
bsf b_CS2
bcf b_LCD_CS2
WNB1_Loop bsf b_LCD_E
btfsc PORTB,7
goto WNB1_Loop
bcf b_LCD_E
btfsc b_CS2
bsf b_LCD_CS2
Skip_CS1 btfss b_LCD_CS2
goto Skip_CS2
bcf b_CS1
btfsc b_LCD_CS1
bsf b_CS1
bcf b_LCD_CS1
WNB2_Loop bsf b_LCD_E
btfsc PORTB,7
goto WNB2_Loop
bcf b_LCD_E
btfsc b_CS1
bsf b_LCD_CS1
Skip_CS2 bsf STATUS,RP0
clrf TRISB
bcf STATUS,RP0
return
ReadLCD bsf b_LCD_E
movfw PORTB
bcf b_LCD_E
btfsc b_Inverted
xorlw 0xff
return
WriteCMD movwf LCDTemp
call WaitNotBusy
movfw LCDTemp
movwf PORTB
bcf b_LCD_RW
bcf b_LCD_RS
bsf b_LCD_E
bcf b_LCD_E
return
WriteData movwf LCDTemp
call WaitNotBusy
movfw LCDTemp
btfsc b_Inverted
xorlw 0xff
movwf PORTB
bcf b_LCD_RW
bsf b_LCD_RS ;rs=1 rw=0
bsf b_LCD_E
bcf b_LCD_E
return
ReadData call WaitNotBusy
bsf STATUS,RP0
movlw 0xff
movwf TRISB
bcf STATUS,RP0
bsf b_LCD_RW
bsf b_LCD_RS
bsf b_LCD_E
movfw PORTB
bcf b_LCD_E
btfsc b_Inverted
xorlw 0xff
bsf STATUS,RP0
clrf TRISB
bcf STATUS,RP0
return
SetLCDAddress bcf b_LCD_CS1
bcf b_LCD_CS2
btfss XPos,6
bsf b_LCD_CS1
btfsc XPos,6
bsf b_LCD_CS2
movfw XPos
andlw 0x3f
iorlw 0x40
call WriteCMD
movfw YPos
movwf Row
rrf Row,F
rrf Row,F
rrf Row,F
movfw Row
andlw 0x7
iorlw 0xb8
goto WriteCMD
#define b_CS1 Flags,0
#define b_CS2 Flags,1
#define b_Inverted Flags,2
#define b_Font Flags,3
#define b_Fixed Flags,4
#define b_LineWidth Flags,5
#define b_LCD_CS1 PORTA,2
#define b_LCD_CS2 PORTA,3
#define b_LCD_RS PORTC,5
#define b_LCD_RW PORTC,0
#define b_LCD_E PORTC,2