Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Help me find the reason why these LCD codes don't work

Status
Not open for further replies.

simonwai999

Advanced Member level 4
Joined
Jun 30, 2008
Messages
114
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,296
Activity points
2,175
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
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
 

Re: lcd codes

I 'just' started transformation from assembler to c, but if you can't compile, are you using same compiler as them(css, Hitech PICC, Microchip C) they have some hidden functions and are not fully ANSI compatible, although they say they are.

And why don't you ask on that other forum?, it doesn't have any sense to ask here if they wrote it.
 

Re: lcd codes

hi

i did post some lines in that forum but up to now
i have not got any replies from them
and i wanna make this work that's why i asked here
i even asked in some other forums to get info as a whole and solve this problem
i do not think it is wrong to do so

anyway
if noone can help me with the codes forget it then
and i thank you
regards
 

Re: lcd codes

You misunderstood, I said to ask there because no one can know better then the one who wrote it.

Look if you are using same compiler.
 

Re: lcd codes

This code compile.
I upload the hex in zip file.
 

Re: lcd codes

Try this code.
I had written this code with pic 16f876 and 18f8520 microconroller in 8 bit mode.
you will have to make minor changes.
The code works best.



#define clock portb.f1
#define command portb.f0

//portb is data port
unsigned short ddd=0x41;

void main()
{
portb=0;
portc=0;
trisc=0;
trisb=0;

delay_ms(30); command=0;
portc=0x30;
clock=1;delay_ms(1);clock=0;
delay_ms(10);

clock=0; command=0;
portc=0x30;
clock=1;delay_ms(1);clock=0;
delay_ms(10);

clock=0; command=0;
portc=0x30;
clock=1;delay_ms(1);clock=0;
delay_ms(10);

//***********************Set interface length
clock=0; command=0;
portc=0x38;
clock=1;delay_ms(1);clock=0;
delay_ms(10);

//*****************************Mov cursor/ shift display
clock=0; command=0;
portc=0x1C;
clock=1;delay_ms(1);clock=0;
delay_ms(10);

//****************************Cursor mov direction
clock=0; command=0;
portc=0x06;
clock=1;delay_ms(1);clock=0;
delay_ms(10);

//****************************Display On
clock=0; command=0;
portc=0x0C; //cursor off, cursor blink off
clock=1;delay_ms(1);clock=0;
delay_ms(10);
//*****************************Set Curser Position
clock=0; command=0;
portc=0x81;
clock=1;delay_ms(1);clock=0;
delay_ms(10);

//*****************************Display
for(ddd=65;ddd<81;ddd++){
clock=0;
command=1;
portc=ddd;//0x41;
clock=1;delay_ms(1);clock=0;
delay_ms(5); }

}
 

Re: lcd codes

hi fellows
thanks all for your great help
the codes worked well now
i was stupid to leave a * in the programme only
thanks to this warm forum
regards to all
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top