Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ;*************************************************************************************************
- ;*************************************************************************************************
- ;** **
- ;** 16F887 Graphic LCD Driver **
- ;** For Toshiba T6963C 240 x 64 GLCD **
- ;** By Jon Wilder **
- ;** Date: 12/01/2011 **
- ;** **
- ;*************************************************************************************************
- ;*************************************************************************************************
- ;** **
- ;** Header Information/Config Options **
- ;** **
- ;** **
- ;** **
- ;** Processor Type: PIC 16F887 **
- ;** Default Radix: Decimal **
- ;** Error Level: -302/Suppress all assembler bank select warnings **
- ;** Reference header file P16F887.INC for SFR and Config option labels **
- ;** **
- ;** Configuration Word 1 **
- ;** **
- ;** In Circuit Debug Off (Default) **
- ;** Low Voltage Programming Off **
- ;** Fail Safe Clock Monitor Off **
- ;** Internal External Switchover Off **
- ;** Brown Out Reset Off **
- ;** Data Code Protection Off (Default) **
- ;** Code Protection Off (Default) **
- ;** RA5 has MCLR Function (Default) **
- ;** Power Up Timer On **
- ;** Watchdog Timer Off **
- ;** High Speed XT Oscillator **
- ;** **
- ;** Configuration Word 2 **
- ;** **
- ;** Program ROM Write Protection Off (Default) **
- ;** Brown Out Reset 4.0V (Default) **
- ;** **
- ;** Fosc = 16MHz **
- ;** **
- ;*************************************************************************************************
- ;*************************************************************************************************
- list p=16F887, r=dec, w=-302
- include <P16F887.INC>
- include "T6963CGLCD.INC"
- __config _CONFIG1, _LVP_OFF & _FCMEN_OFF & _IESO_OFF & _BOR_OFF & _PWRTE_ON & _WDT_OFF & _FOSC_HS
- ;*************************************************************************************************
- ;** **
- ;** RAM Location Constants **
- ;** **
- ;*************************************************************************************************
- cblock 0x20
- TEMP ;temp buffer
- DATAL ;instruction data low byte
- DATAH ;instruction data high byte
- COMMAND ;instruction
- TABLECOUNT ;table counter
- endc
- cblock 0x70
- W_TEMP ;interrupt context save for W
- STATUS_TEMP ;interrupt context save for STATUS
- PCLATH_TEMP ;interrupt context save for PCLATH
- COUNT1 ;delay counter 1
- COUNT2 ;delay counter 2
- COUNT3 ;delay counter 3
- DATA_EE_ADDR ;data EEPROM address buffer
- DATA_EE_DATA ;data EEPROM data buffer
- CASEFLAGS ;used to indicate upper/lower case
- endc
- ;*************************************************************************************************
- ;** **
- ;** Control/Data Line Labels **
- ;** **
- ;*************************************************************************************************
- ;nemonics used for read/write enable/disable
- WR_EN EQU 2 ;write mode enable
- WR_DIS EQU 7 ;write mode disable
- RD_EN EQU 1 ;read mode enable
- RD_DIS EQU 7 ;read mode disable
- ;control lines
- #define CD PORTA,RA0 ;GLCD command/data
- #define RST PORTA,RA1 ;GLCD reset
- #define FONT PORTA,RA2 ;GLCD font select (6x8 or 8x8)
- #define WRITE PORTC,RC0 ;GLCD write enable/disable (active low)
- #define READ PORTC,RC1 ;GLCD read enable/disable (active low)
- #define CE PORTC,RC2 ;GLCD chip enable/disable (active low)
- ;data port
- #define D0 PORTD,RD0 ;GLCD data port bit 0
- #define D1 PORTD,RD1 ;GLCD data port bit 1
- #define D2 PORTD,RD2 ;GLCD data port bit 2
- #define D3 PORTD,RD3 ;GLCD data port bit 3
- #define D4 PORTD,RD4 ;GLCD data port bit 4
- #define D5 PORTD,RD5 ;GLCD data port bit 5
- #define D6 PORTD,RD6 ;GLCD data port bit 6
- #define D7 PORTD,RD7 ;GLCD data port bit 7
- ;*************************************************************************************************
- ;** **
- ;** Start of Main Code **
- ;** **
- ;*************************************************************************************************
- org 0x000 ;reset vector
- goto START ;jump to start of main code
- org 0x004 ;interrupt vector
- goto ISR ;jump to start of interrupt handler
- ;digit look up table
- DIGIT addwf PCL,F
- retlw 0x10 ;0
- retlw 0x11 ;1
- retlw 0x12 ;2
- retlw 0x13 ;3
- retlw 0x14 ;4
- retlw 0x15 ;5
- retlw 0x16 ;6
- retlw 0x17 ;7
- retlw 0x18 ;8
- retlw 0x19 ;9
- retlw 0x21 ;A
- retlw 0x22 ;B
- retlw 0x23 ;C
- retlw 0x24 ;D
- retlw 0x25 ;E
- retlw 0x26 ;F
- ;upper case look up table
- ;(add offset of 0x20 to fetched table value to convert to lower case)
- ALPHA addwf PCL,F
- retlw 0 ;space
- retlw 0x21 ;A
- retlw 0x22 ;B
- retlw 0x23 ;C
- retlw 0x24 ;D
- retlw 0x25 ;E
- retlw 0x26 ;F
- retlw 0x27 ;G
- retlw 0x28 ;H
- retlw 0x29 ;I
- retlw 0x2A ;J
- retlw 0x2B ;K
- retlw 0x2C ;L
- retlw 0x2D ;M
- retlw 0x2E ;N
- retlw 0x2F ;O
- retlw 0x30 ;P
- retlw 0x31 ;Q
- retlw 0x32 ;R
- retlw 0x33 ;S
- retlw 0x34 ;T
- retlw 0x35 ;U
- retlw 0x36 ;V
- retlw 0x37 ;W
- retlw 0x38 ;X
- retlw 0x39 ;Y
- retlw 0x3A ;Z
- ;*************************************************************************************************
- ;** **
- ;** Initialization Routine **
- ;** **
- ;*************************************************************************************************
- START clrf PORTA ;init ports
- clrf PORTB
- clrf PORTC
- clrf PORTD
- clrf PORTE
- banksel ANSEL ;bank 3
- clrf ANSEL ;all ports digital I/O
- clrf ANSELH
- banksel TRISA ;bank 1
- clrf TRISA ;PORTA, PORTB, PORTC, and PORTE outputs
- clrf TRISB ;PORTD defaults to input
- clrf TRISC
- clrf TRISE
- banksel 0 ;bank 0
- clrf CASEFLAGS
- GLCD_INIT bcf RST ;reset GLCD
- movlw 5 ;Command mode and 6x8 font
- movwf PORTA
- movlw 7 ;disable read, write, and chip enable
- movwf PORTC
- call Delay50mS ;wait 50mS
- bsf RST ;disable reset
- ;set operating mode
- ModeSet movlw XOR_CGROM ;text attribute mode with CG ROM on
- movwf COMMAND
- call NoData
- ;graphics RAM start address 0x0000
- GraphicsHome movlw 0
- movwf DATAL
- movlw 0
- movwf DATAH
- call GRPHHome
- ;graphics area 40 rows for 240x64 display
- GraphicsArea movlw 0x28
- movwf DATAL
- movlw 0
- movwf DATAH
- call GRPHArea
- ;text RAM start address 0x1700
- TextHome movlw 0
- movwf DATAL
- movlw 0x17
- movwf DATAH
- call TXTHome
- ;text area 40 rows for 240x64 display
- TextArea movlw 0x28
- movwf DATAL
- movlw 0
- movwf DATAH
- call TXTArea
- ;set offset register
- CGROMSet movlw 0x03
- movwf DATAL
- movlw 0
- movwf DATAH
- call CGROM
- ;clear graphics RAM
- movlw 0 ;set start address to 0x00
- movwf DATAL
- movlw 0
- movwf DATAH
- movlw 20
- movwf COUNT2
- call DisplayClear
- ;clear text RAM
- movlw 0 ;set start address to 0x17
- movwf DATAL
- movlw 0x17
- movwf DATAH
- movlw 2
- movwf COUNT2
- call DisplayClear
- ;single line cursor
- CSRPattern movlw 0xA0
- movwf COMMAND
- call NoData
- ;set cursor pointer on line 0 column 0
- CSRPointer movlw 26
- movwf DATAL
- movlw 5
- movwf DATAH
- call CSR_PTR
- ;text and graphics RAM on, cursor on with cursor blink
- DisplayOn movlw 0x9F
- movwf COMMAND
- call NoData
- ;position address pointer on line 0, column 6
- movlw 240
- movwf COUNT1
- movlw 20
- movwf COUNT2
- movlw 0 ;set address pointer
- movwf DATAL
- movlw 0x0
- movwf DATAH
- call ADDR_PTR
- call DAWSet ;enable data auto write
- movlw 0xFF ;back shade display
- movwf DATAL
- call DAWrite
- decfsz COUNT1,F
- goto $-2
- decfsz COUNT2,F
- goto $-4
- call DAWReset ;disable auto write
- movlw 46 ;set address pointer
- movwf DATAL
- movlw 0x17
- movwf DATAH
- call ADDR_PTR
- call DAWSet ;enable data auto write
- movlw 16 ;P
- call DAWALoad
- movlw 9 ;I
- call DAWALoad
- movlw 3 ;C
- call DAWALoad
- movlw 1 ;1
- call DAWDLoad
- movlw 6 ;6
- call DAWDLoad
- movlw 6 ;F
- call DAWALoad
- movlw 8 ;8
- call DAWDLoad
- movlw 8 ;8
- call DAWDLoad
- movlw 7 ;7
- call DAWDLoad
- movlw 0 ;
- call DAWALoad
- movlw 7 ;G
- call DAWALoad
- movlw 18 ;R
- call DAWALoad
- movlw 1 ;A
- call DAWALoad
- movlw 16 ;P
- call DAWALoad
- movlw 8 ;H
- call DAWALoad
- movlw 9 ;I
- call DAWALoad
- movlw 3 ;C
- call DAWALoad
- movlw 0 ;
- call DAWALoad
- movlw 12 ;L
- call DAWALoad
- movlw 3 ;C
- call DAWALoad
- movlw 4 ;D
- call DAWALoad
- movlw 0 ;
- call DAWALoad
- movlw 4 ;D
- call DAWALoad
- movlw 18 ;R
- call DAWALoad
- movlw 9 ;I
- call DAWALoad
- movlw 22 ;V
- call DAWALoad
- movlw 5 ;E
- call DAWALoad
- movlw 18 ;R
- call DAWALoad
- call DAWReset ;disable data auto write
- movlw 125 ;set address pointer
- movwf DATAL
- movlw 0x17
- movwf DATAH
- call ADDR_PTR
- call DAWSet ;enable data auto write
- movlw 6 ;F
- call DAWALoad
- movlw 15 ;O
- call DAWALoad
- movlw 18 ;R
- call DAWALoad
- movlw 0 ;
- call DAWALoad
- movlw 20 ;T
- call DAWALoad
- movlw 15 ;O
- call DAWALoad
- movlw 19 ;S
- call DAWALoad
- movlw 8 ;H
- call DAWALoad
- movlw 9 ;I
- call DAWALoad
- movlw 2 ;B
- call DAWALoad
- movlw 1 ;A
- call DAWALoad
- movlw 0 ;
- call DAWALoad
- movlw 20 ;T
- call DAWALoad
- movlw 6 ;6
- call DAWDLoad
- movlw 9 ;9
- call DAWDLoad
- movlw 6 ;6
- call DAWDLoad
- movlw 3 ;3
- call DAWDLoad
- movlw 3 ;C
- call DAWALoad
- movlw 0 ;
- call DAWALoad
- movlw 2 ;2
- call DAWDLoad
- movlw 4 ;4
- call DAWDLoad
- movlw 0 ;0
- call DAWDLoad
- bsf CASEFLAGS,0
- movlw 24 ;x
- call DAWALoad
- movlw 6 ;6
- call DAWDLoad
- movlw 4 ;4
- call DAWDLoad
- movlw 0 ;
- call DAWALoad
- movlw 7 ;G
- call DAWALoad
- movlw 12 ;L
- call DAWALoad
- movlw 3 ;C
- call DAWALoad
- movlw 4 ;D
- call DAWALoad
- call DAWReset ;disable data auto write
- movlw 213 ;set address pointer
- movwf DATAL
- movlw 0x17
- movwf DATAH
- call ADDR_PTR
- call DAWSet ;enable data auto write
- movlw 2 ;B
- call DAWALoad
- movlw 25 ;Y
- call DAWALoad
- movlw 0 ;
- call DAWALoad
- movlw 10 ;J
- call DAWALoad
- movlw 15 ;O
- call DAWALoad
- movlw 14 ;N
- call DAWALoad
- movlw 0 ;
- call DAWALoad
- movlw 23 ;W
- call DAWALoad
- movlw 9 ;I
- call DAWALoad
- movlw 12 ;L
- call DAWALoad
- movlw 4 ;D
- call DAWALoad
- movlw 5 ;E
- call DAWALoad
- movlw 18 ;R
- call DAWALoad
- call DAWReset ;disable data auto write
- goto $
- ;*************************************************************************************************
- ;** **
- ;** Delay Loops **
- ;** **
- ;*************************************************************************************************
- ;fixed 50mS delay
- Delay50mS movlw 0xFF
- movwf COUNT1
- movwf COUNT2
- decfsz COUNT1,F
- goto $-1
- decfsz COUNT2,F
- goto $-3
- return
- ;*************************************************************************************************
- ;variable delay
- Delay movwf COUNT3
- call Delay50mS
- decfsz COUNT3,F
- goto $-2
- return
- ;*************************************************************************************************
- ;** **
- ;** Two Data Byte Instructions **
- ;** **
- ;*************************************************************************************************
- CGROM movlw 0x22
- goto CSend
- ADDR_PTR movlw 0x24
- goto CSend
- CSR_PTR movlw 0x21
- goto CSend
- GRPHHome movlw 0x42
- goto CSend
- GRPHArea movlw 0x43
- goto CSend
- TXTHome movlw 0x40
- goto CSend
- TXTArea movlw 0x41
- goto CSend
- CSend movwf COMMAND
- call TwoData
- return
- ;*************************************************************************************************
- ;** **
- ;** Data Auto Read/Write Routines **
- ;** **
- ;*************************************************************************************************
- DAWSet movlw 0xB0
- movwf COMMAND
- call NoData
- call LCDStat
- call DAWStat
- return
- ;*************************************************************************************************
- DAWReset call DAWStat
- movlw 0xB2
- movwf COMMAND
- call NoData
- return
- ;*************************************************************************************************
- ;check data auto write ready bit
- DAWStat call StatReadEn ;enable status read
- btfss D3 ;auto write ready?
- goto $-1
- call StatReadDis ;disable status read
- return
- ;*************************************************************************************************
- DAWrite call DAWStat
- movfw DATAL
- call DWrite
- return
- ;*************************************************************************************************
- DAWALoad call ALPHA
- btfsc CASEFLAGS,0
- addlw 0x20
- goto $+2
- DAWDLoad call DIGIT
- movwf DATAL
- call DAWrite
- bcf CASEFLAGS,0
- return
- ;*************************************************************************************************
- ;** **
- ;** Command Send Routines **
- ;** **
- ;*************************************************************************************************
- TwoData call LCDStat
- movfw DATAL
- call DWrite
- OneData call LCDStat
- movfw DATAH
- call DWrite
- NoData call LCDStat
- movfw COMMAND
- call Command
- return
- ;*************************************************************************************************
- ;** **
- ;** GLCD Read/Write/Status Check **
- ;** **
- ;*************************************************************************************************
- ;command/data write
- Command bsf CD ;command mode
- goto $+2
- DWrite bcf CD ;data mode
- movwf PORTD ;place write data on data port latch
- movlw WR_EN ;chip enable low
- movwf PORTC ;enable write
- banksel TRISD ;bank 1
- clrf TRISD ;RD0-RD7 output
- banksel 0 ;bank 0
- movlw WR_DIS ;disable write
- movwf PORTC ;chip enable high
- banksel TRISD ;bank 1
- comf TRISD,F ;RD0-RD7 input
- banksel 0 ;bank 0
- return
- ;*************************************************************************************************
- ;check GLCD status
- LCDStat call StatReadEn ;enable status read
- btfsc D0 ;is GLCD ready?
- btfss D1
- goto $-2 ;no, check again
- call StatReadDis ;disable status read
- return
- ;*************************************************************************************************
- ;GLCD status read enable
- StatReadEn bsf CD ;command mode
- movlw RD_EN ;enable read
- movwf PORTC
- return
- ;*************************************************************************************************
- ;GLCD status read disable
- StatReadDis movlw RD_DIS ;disable read
- movwf PORTC
- return
- ;*************************************************************************************************
- ;** **
- ;** Clear Display **
- ;** **
- ;*************************************************************************************************
- DisplayClear movlw 160 ;init counters
- movwf COUNT1 ;to clear 320 VRAM locations
- call ADDR_PTR ;set address pointer
- call DAWSet
- call DAWStat
- movlw 0 ;write 0 to display
- call DWrite
- decfsz COUNT1,F ;decrement COUNT1 and continue writing
- goto $-4 ;data if COUNT1 > 0
- movlw 160 ;re-init COUNT1
- movwf COUNT1 ;decrement COUNT2 and continue writing
- decfsz COUNT2,F ;data if COUNT2 > 0
- goto $-8
- call DAWReset
- return ;done
- ;*************************************************************************************************
- ;** **
- ;** Interrupt Handler **
- ;** **
- ;*************************************************************************************************
- ;interrupt context save
- ISR movwf W_TEMP
- swapf STATUS,W
- banksel 0 ;bank 0
- movwf STATUS_TEMP
- movfw PCLATH
- movwf PCLATH_TEMP
- ;interrupt code goes here
- ;interrupt context restore
- ISRExit movfw PCLATH_TEMP
- movwf PCLATH
- swapf STATUS_TEMP,W
- movwf STATUS
- swapf W_TEMP,F
- swapf W_TEMP,W
- retfie
- end
Add Comment
Please, Sign In to add comment