Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

can anyone send lcd code using pic 16f877a

Status
Not open for further replies.

anil

New Member
i have got some code from internet its not working.

can anyone send the assembly language code with which they have worked with please
 
i have got some code from internet its not working.

can anyone send the assembly language code with which they have worked with please

hi,
We need to see your circuit diagram also post a link to the source of the code that 'dosnt work'
 
this is the code which i have used. this code is o display a character S on the lcd.

we got many black patches on lcd.

















List p=16f877A
#include p16f877A.inc
org 0x00
goto start
org 0x20
start

LCD_DATA EQU PORTB ;
LCD_DATA_TRIS EQU TRISB
LCD_CTRL EQU PORTC ;
LCD_TEMP EQU 0x20 ;
DELAY EQU 0x23 ;
X_DELAY EQU 0x24 ;

; PORTC control bits
LCD_E EQU 2 ;
LCD_RW EQU 1 ;
LCD_RS EQU 0 ;

GOTO LCDINIT
LCDBUSY
BSF STATUS,RP0 ;
MOVLW 0xFF ;
MOVWF LCD_DATA_TRIS
BCF STATUS, RP0 ;
BCF LCD_CTRL, LCD_RS ;
BSF LCD_CTRL, LCD_RW ;
BSF LCD_CTRL, LCD_E ;
MOVF LCD_DATA, W ;
BCF LCD_CTRL, LCD_E ;
ANDLW 0x80 ;
BTFSS STATUS, Z
GOTO LCDBUSY
LCDNOTBUSY
BCF LCD_CTRL, LCD_RW
BSF STATUS, RP0 ;
MOVLW 0x00
MOVWF LCD_DATA_TRIS ;
BCF STATUS, RP0 ;
RETURN

LCDCLEAR
MOVLW 0x01
CALL LCDPUTCMD
RETURN

LCDHOME
MOVLW 0x02
CALL LCDPUTCMD
RETURN

LCDEMODE
ANDLW 0x03 ;
IORLW 0x04 ;
CALL LCDPUTCMD
RETURN

LCDDMODE
ANDLW 0x07 ;
IORLW 0x08 ;
CALL LCDPUTCMD
RETURN

LCDSCGA
ANDLW 0x3F ;
IORLW 0x40 ;
CALL LCDPUTCMD
RETURN

LCDSDDA
IORLW 0x80 ;
CALL LCDPUTCMD
RETURN

LCDGADDR
BSF STATUS,RP0 ;
MOVLW 0xFF ;
MOVWF LCD_DATA_TRIS
BCF STATUS, RP0 ;
BCF LCD_CTRL, LCD_RS ;
BSF LCD_CTRL, LCD_RW ;
BSF LCD_CTRL, LCD_E ;
MOVF LCD_DATA, W ;
BCF LCD_CTRL, LCD_E ;
ANDLW 0x7F ;
BCF LCD_CTRL, LCD_RW
BSF STATUS, RP0 ;
MOVLW 0x00
MOVWF LCD_DATA_TRIS ;
BCF STATUS, RP0 ;
RETURN

LCDPUTCHAR
MOVWF LCD_TEMP ;
CALL LCDBUSY ;
BCF LCD_CTRL, LCD_RW ;
BSF LCD_CTRL, LCD_RS ;
BSF LCD_CTRL, LCD_E ;
MOVF LCD_TEMP, W
MOVWF LCD_DATA ;
BCF LCD_CTRL, LCD_E ;
RETURN

LCDPUTCMD
MOVWF LCD_TEMP ;
CALL LCDBUSY ;
BCF LCD_CTRL, LCD_RW ;
BCF LCD_CTRL, LCD_RS ;
BSF LCD_CTRL, LCD_E ;
MOVF LCD_TEMP, W
MOVWF LCD_DATA ;
BCF LCD_CTRL, LCD_E ;
RETURN

;*********************************** a 500uS delay @ 4MHz X-tal
DELAY500
MOVLW D'255' ; +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

LCDINIT

CLRF LCD_CTRL ;
BSF STATUS,RP0
MOVLW 0X00
MOVWF TRISC
BCF STATUS,RP0
MOVLW 0x1E
CALL X_DELAY500 ;
MOVLW 0x038 ;
CALL LCDPUTCMD
MOVLW 0x000 ;
CALL LCDDMODE
CALL LCDCLEAR
MOVLW 0x004 ;
CALL LCDDMODE
MOVLW 0x002 ;
CALL LCDEMODE
MOVLW B'01010011'
;CALL LCDPUTCMD
CALL LCDPUTCHAR
END
 
hi,
Your program runs OK in the Oshonsoft simulator, see this image, I added the 'Hello' message.

You are not initialising the LCD correctly, so when you run the program with real hardware you will see black blocks.

Look at Nigels tutorials on how to do this, use the link shown near my signature st the bottom of this post.
 

Attachments

  • AAesp04.gif
    AAesp04.gif
    6 KB · Views: 215
Last edited:
Status
Not open for further replies.

New Articles From Microcontroller Tips

Back
Top