simonwai999
Advanced Member level 4
hi
i am just a newbie to LCD programming
so i searched and found these follow codes in a forum
all people in the forum said these codes worked , but
i can never complie it i wonder why
i am just a newbie to LCD programming
so i searched and found these follow codes in a forum
all people in the forum said these codes worked , but
i can never complie it i wonder why
Code:
list p=16f690
#include <p16F690.inc>
__config ( _WDT_OFF & _PWRTE_OFF & _MCLRE_OFF & _CP_OFF & _BOR_OFF & _IESO_OFF & _FCMEN_OFF)
#define E PORTC,0 ; Define Enable function on bit 0 of PORTC
#define RW PORTC,1 ; Define R/W function on bit 1 of PORTC
#define RS PORTC,2 ; Define Register Selection function on bit 2 of PORTC
temp equ 0x20 ; Temp register to hold data being sent to display
inner equ 0x21 ; Loop counter for Delay Routine
;****************************************************************************
org 0x000 ; Start program at 0x0000
BANKSEL TRISB
clrf TRISB
; Set PORTB as outputs
clrf TRISC ; Set PORTC as outputs
BANKSEL PORTB
bsf E ; Initialize Enable to Logic High State
bcf RW ; Initialize RW to Logic Low (Write)
call InitDisp ; Put display into 4-bit mode
movlw 0x28 ; Send Entry Mode Set command for 4-bit mode
call LCDCommand ; and 2-line display
movlw 0x0E ; Send command to turn on display and cursor
call LCDCommand
movlw 0x06 ; Send Entry Mode Set command to increment address
call LCDCommand ; by one and shift the cursor to the right
movlw 0x80 ; Send Set DDRAM Address to address 0x00
call LCDCommand
movlw 'A' ; Send an 'A' Character to the display on first line
call LCDData
movlw 0xC0 ; Send Set DDRAM Address to address 0x40
call LCDCommand
movlw 'B' ; Send a 'B' Character to the display on second line
call LCDData
Self:
goto Self ; Loop in place
; ***************************************************
; * To initialize display, we send one 8-bit *
; * to display to put it into 4-bit mode. *
; ***************************************************
InitDisp:
BANKSEL PORTB
movlw 0x02 ; Function set for 4-bit interface
movwf PORTB ; Move command to LSB's of PORTB
bcf RS ; Clear RS (indicates command)
bcf E ; Strobe Enable
bsf E
call Delay ; Allow display to process command
return ; Return to caller
; ***************************************************
; * To send command to the display, load data into *
; * W_REG and call LCDCommand *
; ***************************************************
LCDCommand:
bcf RS ; Clear RS line for command
goto SendToLCD
; ***************************************************
; * To send data to the display, load data into *
; * W_REG and call LCDData *
; ***************************************************
LCDData:
bsf RS ; Set RS line for data
; ***************************************************
; * Universal subroutine to send a byte to the LCD, *
; * passed in through the W_REG. *
; ***************************************************
SendToLCD:
movwf temp ; Save our data in temp register
swapf temp,W ; Swap nybbles and place result in W
movwf PORTB ; Move upper nybble of data in LSB's of PORTB
bcf E ; Strobe Enable
bsf E
movf temp,W ; Retrieve our original data byte into W
movwf PORTB ; Move to PORTB, essentially placing lower nybble
; in LSB's of PORTB
bcf E ; Stobe Enable
bsf E
call Delay ; Give display time to process command or data
return ; return to caller
; ******************************************************
; * Create a delay to allow Display to process command *
; ******************************************************
Delay:
clrf inner
DLoop:
nop
nop
decfsz inner
goto DLoop
return
END
[code/]
can anyone help me with these and tell me what is wrong with the codes?
It is weird that everyone in that forum could complie it not me
by the way
i am using mplab 8.0
thanks in advanced
best regards