Skip to content

Instantly share code, notes, and snippets.

@neuro-sys
Created November 19, 2011 02:33
Show Gist options
  • Save neuro-sys/1378346 to your computer and use it in GitHub Desktop.
Save neuro-sys/1378346 to your computer and use it in GitHub Desktop.
LCD HD44780 PIC
; PORTC is connected to D4:D7 as C0:C3
; PORTA is connected to RS/RW/E as A0/A1/A2
#include p16f690.inc
PROCESSOR p16f690
__CONFIG _INTRC_OSC_NOCLKOUT&_FCMEN_ON&_IESO_ON&_BOR_ON&_CPD_OFF&_CP_OFF&_MCLRE_OFF&_PWRTE_OFF&_WDT_OFF
RS EQU 5
RW EQU 1
E EQU 2
dcount EQU 0x20
dcount2 EQU 0x21
temp EQU 0x22
i EQU 0x23
ptr EQU 0x24
ORG 0x0
bsf STATUS,RP0
clrf TRISA
clrf TRISC
bcf STATUS,RP0
clrf ADCON0 ;no analog input
call LCD_reset
call LCD_init
movlw 1
call LCD_set_ad
call LCD_String
goto $
Text1:
addwf PCL,F
dt b'10011101',"ALL N00BZ!!!",b'10011101',0
;3n+1 cycles
Delay:
movwf dcount
decfsz dcount,F
goto $-1
return
;766*n cycles
Delay_lng:
movwf dcount2
movlw 0
Dl: call Delay ; 766 * dcount2
decfsz dcount2,F
goto Dl
return
LCD_Shift_L:
movlw 0x18
call LCD_Com
movlw d'14'
call Delay
return
LCD_Shift_R:
movlw 0x1c
call LCD_Com
movlw d'14'
call Delay
return
LCD_init:
movlw 0x28 ;4-bits, DL
call LCD_Com
movlw d'14' ; t > 40 us.
call Delay
movlw 0x0c ;Display on, Blink, Underline
call LCD_Com
movlw d'14'
call Delay
call LCD_clr
return
LCD_reset:
movlw d'40'
call Delay_lng
movlw 0x20 ; set to 4-bit
call LCD_Com
movlw d'34'
call Delay
return
LCD_set_ad:
iorlw 0x80
call LCD_Com
return
LCD_clr:
movlw 0x01 ;Clear screen
call LCD_Com
movlw d'3'
call Delay_lng
return
LCD_Command:
movwf PORTC
bcf PORTA,RS ; 0 for command
bcf PORTA,RW ; 0 for write
bsf PORTA,E
bcf PORTA,E
return
;high nibble first, low nibble later, 4-bit interface.
LCD_Com:
bcf PORTA,RS
bcf PORTA,RW
movwf temp
swapf temp,W
andlw 0x0f
movwf PORTC
bsf PORTA,E
bcf PORTA,E
movf temp,W
andlw 0x0f
movwf PORTC
bsf PORTA,E
bcf PORTA,E
return
LCD_Putc:
bsf PORTA,RS
bcf PORTA,RW
movwf temp
swapf temp,W
andlw 0x0f
movwf PORTC
bsf PORTA,E
bcf PORTA,E
bsf PORTA,RS
movf temp,W
andlw 0x0f
movwf PORTC
bsf PORTA,E
bcf PORTA,E
return
LCD_String:
clrf i
L: movf i,W
call Text1
addlw 0
btfsc STATUS,Z
return
call LCD_Putc
incf i,F
movlw d'14'
call Delay
goto L
ENDM
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment