Problem with LCD & PIC16C54C

Hi All,

Just bought a BATRON 4 line LCD. Tried to get it moving by displaying a character. However, to no avail, all it displays are black boxes. Below is the code I used for the PIC16C54C.

LIST P=16C54 ;This tells the assembler which device is required

;***************** Hardware Definitions - Specific to the PIC

****************

PORTA EQU 0x05 ; Physical Address on PIC PORTB EQU 0x06 ; Physical Address on PIC STATUS EQU 0x03 ; Physical Address on PIC STAT_BANK EQU 0x05 ; Bit 5 to switch bank

;************** Hardware Definitions - Specific to the Circuit

***************

LCD_RS EQU 0 LCD_EN EQU 1

; LCD SET DDRAM Address LCD_LINE1 EQU 0x80 LCD_LINE2 EQU 0xC0 LCD_LINE3 EQU 0x94 LCD_LINE4 EQU 0xD4

;************************** GENERAL PURPOSE REGISTERS

************************

COUNTHIGH EQU 0x08 COUNTLOW EQU 0x09 ;LCD_DATA EQU 0x0A

;******************************** CONSTANTS

**********************************

timehigh EQU 0xFF timelow EQU 0xFF

;**************************************************************************** ;*************************** Start of the Program

*************************** ;****************************************************************************

ORG 1ffh ;This tells the assembler where to place the code goto START ;1ffh is the Reset Vector (Startup location) for PIC

16C5x's

ORG 0h goto START

;**************************************************************************** ; SUBROUTINES ;****************************************************************************

DELAY ;delay 20mS movlw timehigh movwf COUNTHIGH movlw timelow movwf COUNTLOW delayloop decfsz COUNTLOW,f goto delayloop

movlw timelow movwf COUNTLOW decfsz COUNTHIGH,f goto delayloop RETURN

SDELAY ;delay movlw timelow movwf COUNTLOW sdelayloop decfsz COUNTLOW,f goto sdelayloop RETURN

FUNCTIONSET CALL SDELAY MOVLW 0x38 MOVWF PORTB BSF PORTA,LCD_EN CALL SDELAY NOP BCF PORTA,LCD_EN RETURN

SENDTOLCD CALL SDELAY ; MOVWF PORTB BSF PORTA,LCD_EN CALL SDELAY NOP BCF PORTA,LCD_EN RETURN START

;***************************** Initialize PIC

*******************************

CLRF PORTA CLRF PORTB

BSF STATUS,STAT_BANK ; At Bank 1 now MOVLW 00H TRIS PORTB ; Port B all o/p MOVLW 00H TRIS PORTA ; Port A i/o = 0000 0000 BCF STATUS,STAT_BANK ; At Bank 0 now

;***************************** Initialize LCD

*******************************

CALL DELAY BCF PORTA,LCD_RS CALL FUNCTIONSET CALL FUNCTIONSET CALL FUNCTIONSET CALL FUNCTIONSET

CALL SDELAY MOVLW 0x08 ; Display ON/OFF = display off, cursor off, blink off MOVWF PORTB CALL SENDTOLCD

MOVLW 0x01 ; Clear Display MOVWF PORTB CALL SENDTOLCD

MOVLW 0x07 ; Entry Mode Set MOVWF PORTB CALL SENDTOLCD

;****************************** SEND DATA TO LCD

*****************************

MOVLW 0x0F ; Display on, curson on, blink on MOVWF PORTB CALL SENDTOLCD

MOVLW LCD_LINE1 ; DDRAM Set MOVWF PORTB CALL SENDTOLCD

;***********END OF INSTRUCTION SET, START OF DATA************************* BSF PORTA,LCD_RS MOVLW 41h MOVWF PORTB CALL SENDTOLCD

END

*************************************************************************************************************

I am not sure what went wrong. As for the circuit, i tied a crystal at the OSC1 & OCS2 of the PIC with 2 caps.

Thanks in advance ywz

Reply to
ydoubleuz
Loading thread data ...

are you talking about a hd44780 or equivalent alphanumeric display?If yes the black boxes are commonly due to wrong initialization.Can you post a link to the display datasheet? anyway if you are not still shure about your firmware how can you use a

16C?If i remember it is One Time Programmable.I think the use of a 16F should be better. Correct me if i am wrong.

Diego

Reply to
blisca

Hi Diego,

The datasheet link ->

formatting link

The 16C has a cerdip version where i can erase it with UV.

I followed the initialization in the datasheet of the LCD controller, however it still does not work. You can refer to the code posted previously if there is any mistake.

Could it be due to the Vo and Vdd of the LCD? I had 2 separate power supply for these two pins. Vo=5.35V, Vdd=5V with both ground tied to Vss.

Reply to
ydoubleuz

;***************************************************************************

*

;***************************************************************************

*

;***************************************************************************

*

;***************************************************************************

*

CALL Delay???

CALL Delay????

CALL delay????

CALL Delay??????

**************************************************************************** *********************************

look for the KS0066 initialization sequence,i guess you have to add some delay after LCD_EN is turned low.At a certain point the busy check at bit 7 can be performed,i suggesto to use it.The software will be more complicated ,but you will improve speed and avoid conflicts

well,if the Vo is too close to ground the background appears very dark but you should be able to see the characters,anyway put a trimmer(10 Kohms or even 47Kohms) between ground vdd,cursor to Vo

Reply to
blisca

CALL FUNCTIONSET

CALL Delay??? look for the KS0066 initialization sequence,i guess you have to add some

The sequence which I used is smilar to that of the KS0066.

No effect, still same black boxes.

Reply to
ydoubleuz

bit 7

complicated

but

or

strange,at least turning pot towards VDD should turn the display white

Reply to
blisca

haha, I just tried that before reading this post. But still same results... ;)

Reply to
ydoubleuz

btw, when I run the program with MPLAB SIM, when the code runs till the end, "Stack underflow" occurs. Is it what it should be?

Reply to
ydoubleuz

formatting link

Reply to
ydoubleuz

DO you have the spec sheet for the display? Some of them require a negative contrast voltage - usually the extended temp range ones.

Reply to
Dennis

For the display you are using, note Vlcd. Note that this requires V0, to be -3v typically. Note also, that the Samsung controllers, typically need slightly longer after boot, before being ready to operate, that the Hitachi controllers, which are the 'standard', which most of these emulate. Something like 30mSec after power is applied, is needed to be 'safe'.

Best Wishes

Reply to
Roger Hamlett

Hi,

Yup the contrast voltage is -3V. The PIC is working becoz I tied a LED to one of the o/p. However, the LCD still does not display. It could be due to the wrong init. sequences or that data are not sent to the LCD correctly.

;***************************** Initialize LCD

*******************************

CALL DELAY CALL DELAY CALL DELAY BCF PORTA,LCD_RS BCF PORTA,LCD_RW CALL DELAY CALL FUNCTIONSET CALL FUNCTIONSET CALL FUNCTIONSET CALL SDELAY MOVLW 0x3F ; Function set MOVWF PORTB CALL SENDTOLCD

CALL SDELAY MOVLW 0x08 ; Display ON/OFF = display off, cursor off, blink off MOVWF PORTB CALL SENDTOLCD

CALL SDELAY MOVLW 0x01 ; Clear Display MOVWF PORTB CALL SENDTOLCD CALL DELAY CALL DELAY CALL DELAY CALL DELAY CALL DELAY MOVLW 0x06 ; Entry Mode Set MOVWF PORTB CALL SENDTOLCD CALL SDELAY

;************************************ FUNCTIONSET CALL SDELAY MOVLW 0x30 ; 2 line, display on MOVWF PORTB

BSF PORTA,LCD_EN CALL SDELAY NOP BCF PORTA,LCD_EN CALL SDELAY RETLW 0

SENDTOLCD CALL SDELAY BSF PORTA,LCD_EN CALL SDELAY NOP BCF PORTA,LCD_EN CALL SDELAY RETLW 0

///////////////////////////////////////////////////

Any help is appreciated. btw .... could the problem be due to the 4Mhz osc i am using becoz the datasheet has a condition Fosc=270KHz

ywz

Reply to
ydoubleuz

Hi Guys,

Finally got the LCD to display a couple of chars. The problem actually lies in the initialization part of the datasheet. However the display only shows:

A A A A A A A A x x x x x x x x x x x x

_ _ _ _ _ _ _ _ x x x x x x x x x x x x

x x x x x x x x x x x x x x x x x x x x

x x x x x x x x x x x x x x x x x x x x

x denotes black boxes.

_ denotes blanks.

How come these boxes exist?

Reply to
ydoubleuz

You still have not initialized the display correctly.

The data sheet is most likly correct, your code is not correct yet.

donald

Reply to
Donald

ElectronDepot website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.