Firehawk734
Technical User
Hey ,
I am trying to write a program for this pic (see subject) to interface with a HD44780 based LCD. The interface will be 4-bit. I cannot get the damn thing to respond for the life of me. Coudl someone please check my code and tell me what im missing? Also what does R=DEC mean? I can send the ASM file if it would be easier. It kinda scrambled a bit when i paste it here. THANK YOU!
; Port B goes to the LCD. Bit 0 is not used. Bit 1 is RS , Bit 2 is RW,
and Bit 3 is Enable.
; Bits 4-7 are the data bits to the LCD.
; Port A 0-3 are toggle output bits to a mutliplexor, for numbers 0-15. The
multiplexor
; output is PortA bit 4.
; This is just an initialization and an attempt to print a > arrow on the
LCD.
LIST P=16f84a, R=DEC ; 16C84 Runs at 4 MHz what does
R=DEC MEAN???
#include <p16f84a.inc>
__CONFIG _CP_OFF &_PWRTE_ON &_WDT_OFF
org 0
W EQU 0h
LCDRS EQU 1
LCDRW EQU 2
LCDE EQU 3
DELAY EQU 0x023 ; Used in DELAYxxx routines
X_DELAY EQU 0x024 ; Used in X_DELAYxxx routines
bcf STATUS, RP0 ;bank 0
clrf PORTA ;initialize portA
clrf PORTB ;initialize portB
bsf STATUS, RP0 ;switch to bank 1
clrf TRISA
clrf TRISB
movlw b'10000' ;set pin 4 in, rest out
movwf TRISA ;set portA appropriately
movlw b'00000000' ;set 8-bit portB to outputs
movwf TRISB ;set portB to all outputs
bcf STATUS,RP0 ;switch back to bank 0 begin working
bsf PORTB, LCDE ;toggle enable to low
call LCDINITIAL ;start initializing the LCD
call dispRarrow ;attempt to display the arrow
goto DONE
dispRarrow movlw 0x001 ;1*.5ms = 500us only need 160us tho
call X_DELAY500
bsf PORTB, 1 ;RS is high
movf PORTB, W
movlw b'00111010'
movlw 0x001 ;1*.5ms = 500us only need 160us tho
call X_DELAY500
movf PORTB, W
movlw b'11101010'
bcf PORTB, 3
return
LCDINITIAL
clrf PORTB ;done to clear ctrl lines
movlw 0x01E ;load 30*.5ms = 15ms delay
call X_DELAY500 ;500us delay routine
;busy flag valid now
movf PORTB, W
movlw b'00111000' ;set 4-bit interface
movlw 0x00A ;load 10*.5ms = 5ms delay
call X_DELAY500 ;500us delay routine
movf PORTB, W
movlw b'00111000' ;repeat this
movlw 0x001 ;1*.5ms = 500us only need 160us tho
call X_DELAY500
movf PORTB, W
movlw b'00111000'
movlw 0x001 ;1*.5ms = 500us only need 160us tho
call X_DELAY500
movf PORTB, W
movlw b'00101000' ;this enables 4-bit mode
movlw 0x001 ;1*.5ms = 500us only need 160us tho
call X_DELAY500
;set interface length
movf PORTB, W
movlw b'00111000' ;set 2 lines and 5x7 font
movlw 0x001 ;1*.5ms = 500us only need 160us tho
call X_DELAY500
movf PORTB, W
movlw b'10001000' ;set 2 lines and 5x7 font
movlw 0x001 ;1*.5ms = 500us only need 160us tho
call X_DELAY500
;set so that display doesnt shift
movf PORTB, W
movlw b'00011000' ;set no display shifting
movlw 0x001 ;1*.5ms = 500us only need 160us tho
call X_DELAY500
movf PORTB, W
movlw b'00001000' ;set no display shifting
movlw 0x001 ;1*.5ms = 500us only need 160us tho
call X_DELAY500
;clears display
movf PORTB, W
movlw b'00001000' ;upper nibble clears display
movlw 0x001 ;1*.5ms = 500us only need 160us tho
call X_DELAY500
movf PORTB, W
movlw b'00011000' ;lower nibble clears display
movlw 0x001 ;1*.5ms = 500us only need 160us tho
call X_DELAY500
;set cursor move behavior
movf PORTB, W
movlw b'00001000' ;upper nibble sets to shift cursor not
display
movlw 0x001 ;1*.5ms = 500us only need 160us tho
call X_DELAY500
movf PORTB, W
movlw b'01101000' ;lower nibble sets to shift cursor not
display
movlw 0x001 ;1*.5ms = 500us only need 160us tho
call X_DELAY500
;turn display on/off with optional cursor
movf PORTB, W
movlw b'00001000' ;upper nibble sets to shift cursor not
display
movlw 0x001 ;1*.5ms = 500us only need 160us tho
call X_DELAY500
movf PORTB, W
movlw b'11001000' ;turn on display and cursor off
movlw 0x001 ;1*.5ms = 500us only need 160us tho
call X_DELAY500
return
;*********************************** a 500uS delay @ 4MHz X-tal
DELAY500
MOVLW D'165' ; +1 1 cycle
MOVWF DELAY ; +2 1 cycle
DELAY500_LOOP
DECFSZ DELAY, F ; step1 1 cycle
GOTO DELAY500_LOOP ; step2 2 cycles
DELAY500_END
RETURN ; +3 2 cycles
;*********************************** a delay of 'W' * 500mS
X_DELAY500
MOVWF X_DELAY ; +1 1 cycle
X_DELAY500_LOOP
CALL DELAY500 ; step1 wait 500uSec
DECFSZ X_DELAY, F ; step2 1 cycle
GOTO X_DELAY500_LOOP ; step3 2 cycles
X_DELAY500_END
RETURN ; +2 2 cycles
DONE nop
end
I am trying to write a program for this pic (see subject) to interface with a HD44780 based LCD. The interface will be 4-bit. I cannot get the damn thing to respond for the life of me. Coudl someone please check my code and tell me what im missing? Also what does R=DEC mean? I can send the ASM file if it would be easier. It kinda scrambled a bit when i paste it here. THANK YOU!
; Port B goes to the LCD. Bit 0 is not used. Bit 1 is RS , Bit 2 is RW,
and Bit 3 is Enable.
; Bits 4-7 are the data bits to the LCD.
; Port A 0-3 are toggle output bits to a mutliplexor, for numbers 0-15. The
multiplexor
; output is PortA bit 4.
; This is just an initialization and an attempt to print a > arrow on the
LCD.
LIST P=16f84a, R=DEC ; 16C84 Runs at 4 MHz what does
R=DEC MEAN???
#include <p16f84a.inc>
__CONFIG _CP_OFF &_PWRTE_ON &_WDT_OFF
org 0
W EQU 0h
LCDRS EQU 1
LCDRW EQU 2
LCDE EQU 3
DELAY EQU 0x023 ; Used in DELAYxxx routines
X_DELAY EQU 0x024 ; Used in X_DELAYxxx routines
bcf STATUS, RP0 ;bank 0
clrf PORTA ;initialize portA
clrf PORTB ;initialize portB
bsf STATUS, RP0 ;switch to bank 1
clrf TRISA
clrf TRISB
movlw b'10000' ;set pin 4 in, rest out
movwf TRISA ;set portA appropriately
movlw b'00000000' ;set 8-bit portB to outputs
movwf TRISB ;set portB to all outputs
bcf STATUS,RP0 ;switch back to bank 0 begin working
bsf PORTB, LCDE ;toggle enable to low
call LCDINITIAL ;start initializing the LCD
call dispRarrow ;attempt to display the arrow
goto DONE
dispRarrow movlw 0x001 ;1*.5ms = 500us only need 160us tho
call X_DELAY500
bsf PORTB, 1 ;RS is high
movf PORTB, W
movlw b'00111010'
movlw 0x001 ;1*.5ms = 500us only need 160us tho
call X_DELAY500
movf PORTB, W
movlw b'11101010'
bcf PORTB, 3
return
LCDINITIAL
clrf PORTB ;done to clear ctrl lines
movlw 0x01E ;load 30*.5ms = 15ms delay
call X_DELAY500 ;500us delay routine
;busy flag valid now
movf PORTB, W
movlw b'00111000' ;set 4-bit interface
movlw 0x00A ;load 10*.5ms = 5ms delay
call X_DELAY500 ;500us delay routine
movf PORTB, W
movlw b'00111000' ;repeat this
movlw 0x001 ;1*.5ms = 500us only need 160us tho
call X_DELAY500
movf PORTB, W
movlw b'00111000'
movlw 0x001 ;1*.5ms = 500us only need 160us tho
call X_DELAY500
movf PORTB, W
movlw b'00101000' ;this enables 4-bit mode
movlw 0x001 ;1*.5ms = 500us only need 160us tho
call X_DELAY500
;set interface length
movf PORTB, W
movlw b'00111000' ;set 2 lines and 5x7 font
movlw 0x001 ;1*.5ms = 500us only need 160us tho
call X_DELAY500
movf PORTB, W
movlw b'10001000' ;set 2 lines and 5x7 font
movlw 0x001 ;1*.5ms = 500us only need 160us tho
call X_DELAY500
;set so that display doesnt shift
movf PORTB, W
movlw b'00011000' ;set no display shifting
movlw 0x001 ;1*.5ms = 500us only need 160us tho
call X_DELAY500
movf PORTB, W
movlw b'00001000' ;set no display shifting
movlw 0x001 ;1*.5ms = 500us only need 160us tho
call X_DELAY500
;clears display
movf PORTB, W
movlw b'00001000' ;upper nibble clears display
movlw 0x001 ;1*.5ms = 500us only need 160us tho
call X_DELAY500
movf PORTB, W
movlw b'00011000' ;lower nibble clears display
movlw 0x001 ;1*.5ms = 500us only need 160us tho
call X_DELAY500
;set cursor move behavior
movf PORTB, W
movlw b'00001000' ;upper nibble sets to shift cursor not
display
movlw 0x001 ;1*.5ms = 500us only need 160us tho
call X_DELAY500
movf PORTB, W
movlw b'01101000' ;lower nibble sets to shift cursor not
display
movlw 0x001 ;1*.5ms = 500us only need 160us tho
call X_DELAY500
;turn display on/off with optional cursor
movf PORTB, W
movlw b'00001000' ;upper nibble sets to shift cursor not
display
movlw 0x001 ;1*.5ms = 500us only need 160us tho
call X_DELAY500
movf PORTB, W
movlw b'11001000' ;turn on display and cursor off
movlw 0x001 ;1*.5ms = 500us only need 160us tho
call X_DELAY500
return
;*********************************** a 500uS delay @ 4MHz X-tal
DELAY500
MOVLW D'165' ; +1 1 cycle
MOVWF DELAY ; +2 1 cycle
DELAY500_LOOP
DECFSZ DELAY, F ; step1 1 cycle
GOTO DELAY500_LOOP ; step2 2 cycles
DELAY500_END
RETURN ; +3 2 cycles
;*********************************** a delay of 'W' * 500mS
X_DELAY500
MOVWF X_DELAY ; +1 1 cycle
X_DELAY500_LOOP
CALL DELAY500 ; step1 wait 500uSec
DECFSZ X_DELAY, F ; step2 1 cycle
GOTO X_DELAY500_LOOP ; step3 2 cycles
X_DELAY500_END
RETURN ; +2 2 cycles
DONE nop
end