Y
[email protected]
- Jan 1, 1970
- 0
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
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