Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ;*************************************************************************************
- ;*************************************************************************************
- ;** **
- ;** Driver For Toshiba T6963 **
- ;** Graphics LCD Display Controller **
- ;** For the Microchip PIC 16F887 **
- ;** By Jon Wilder **
- ;** V1.1 Date: 12/06/2011 **
- ;** **
- ;*************************************************************************************
- ;** **
- ;** Header Information **
- ;** **
- ;*************************************************************************************
- ;** **
- ;** Processor Type: PIC 16F887 **
- ;** Default Radix: Decimal **
- ;** Error Level: Suppress all assembler bank select warnings **
- ;** Reference header file P16F887.INC for all SFR and configuration word labels **
- ;** **
- ;** Configuration Word 1 **
- ;** **
- ;** Debug Mode Off (Default) **
- ;** Low Voltage Programming Off **
- ;** Fail Safe Clock Monitor Off **
- ;** Internal External Switchover Off **
- ;** Brown Out Reset Off **
- ;** Data Code Protect Off (Default) **
- ;** Code Protect Off (Default) **
- ;** RA5 is MCLRE (Default) **
- ;** Power Up Timer On **
- ;** Watchdog Timer Off **
- ;** High Speed Oscillator **
- ;** **
- ;** Configuration Word 2 **
- ;** Flash Write Protect Off (Default) **
- ;** Brown Out Reset 4V (Default - Disabled in Configuration Word 1) **
- ;** **
- ;** Fosc = 16MHz **
- ;** **
- ;*************************************************************************************
- ;*************************************************************************************
- list p=16F887, r=dec, w=-302
- include <P16F887.INC>
- __config _CONFIG1, _LVP_OFF & _FCMEN_OFF & _IESO_OFF & _BOR_OFF & _PWRTE_ON & _WDT_OFF & _HS_OSC
- ;*************************************************************************************
- ;** **
- ;** Control/Data Line Labels **
- ;** **
- ;*************************************************************************************
- ;nemonics for enabling/disabling read/write modes
- WRT_EN EQU 2 ;write mode enable
- WRT_DIS EQU 7 ;write mode disable
- RD_EN EQU 1 ;read mode enable
- RD_DIS EQU 7 ;read mode disable
- ;control line labels
- #define CD PORTA,RA0 ;command(high)/data(low) mode select
- #define RST PORTA,RA1 ;reset (active low)
- #define FONT PORTA,RA2 ;6x8 (high)/8x8 (low) font select
- #define WRITE PORTC,RC0 ;write enable (low)/disable (high)
- #define READ PORTC,RC1 ;read enable (low)/disable (high)
- #define CE PORTC,RC2 ;chip enable (active low)
- ;bi-directional data port
- #define D0 PORTD,RD0 ;data port bit 0
- #define D1 PORTD,RD1 ;data port bit 1
- #define D2 PORTD,RD2 ;data port bit 2
- #define D3 PORTD,RD3 ;data port bit 3
- #define D4 PORTD,RD4 ;data port bit 4
- #define D5 PORTD,RD5 ;data port bit 5
- #define D6 PORTD,RD6 ;data port bit 6
- #define D7 PORTD,RD7 ;data port bit 7
- ;*************************************************************************************
- ;** **
- ;** RAM Buffer Labels **
- ;** **
- ;*************************************************************************************
- cblock 0x20
- TEMP ;temp buffer
- DATAL ;GLCD data low byte buffer
- DATAH ;GLCD data high byte buffer
- COMMAND ;GLCD instruction buffer
- MIDI_TEMP ;MIDI data buffer
- 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
- COUNT4 ;general purpose counter
- COUNT5 ;general purpose counter
- COUNT6 ;general purpose counter
- DATA_EE_ADDR ;data EEPROM address buffer
- DATA_EE_DATA ;data EEPROM data buffer
- endc
- ;*************************************************************************************
- ;** **
- ;** 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
- ;*************************************************************************************
- ;** **
- ;** Data Tables **
- ;** **
- ;*************************************************************************************
- ;letter table
- 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
- ;digit 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
- ;punctuation table
- PUNC addwf PCL,F
- retlw 0x01 ; !
- retlw 0x02 ; "
- retlw 0x03 ; #
- retlw 0x04 ; $
- retlw 0x05 ; %
- retlw 0x06 ; &
- retlw 0x07 ; '
- retlw 0x08 ; (
- retlw 0x09 ; )
- retlw 0x0A ; *
- retlw 0x0B ; +
- retlw 0x0C ; ,
- retlw 0x0D ; -
- retlw 0x0E ; .
- retlw 0x0F ; /
- retlw 0x1A ; :
- retlw 0x1B ; ;
- retlw 0x1C ; <
- retlw 0x1D ; =
- retlw 0x1E ; >
- retlw 0x1F ; ?
- retlw 0x20 ; @
- retlw 0x3B ; [
- retlw 0x3C ; \
- retlw 0x3D ; ]
- retlw 0x3E ; ^
- retlw 0x3F ; _
- ;*************************************************************************************
- ;** **
- ;** Interrupt Handler **
- ;** **
- ;*************************************************************************************
- ;interrupt context save
- ISR movwf W_TEMP ;save W
- swapf STATUS,W ;save STATUS
- banksel 0 ;bank 0
- movwf STATUS_TEMP
- movfw PCLATH ;save PCLATH
- movwf PCLATH_TEMP
- ;place interrupt code here
- ;interrupt context restore
- ISRExit movfw PCLATH_TEMP ;restore PCLATH
- movwf PCLATH
- swapf STATUS_TEMP,W ;restore STATUS
- movwf STATUS
- swapf W_TEMP,F ;restore W
- swapf W_TEMP,W
- retfie ;return from interrupt
- ;*************************************************************************************
- ;** **
- ;** Two Data Byte Instructions **
- ;** **
- ;*************************************************************************************
- CSR_PTR movlw 0x21 ;set cursor pointer
- goto InstSend
- OFST_PTR movlw 0x22 ;set offset register
- goto InstSend
- ADDR_PTR movlw 0x24 ;set address pointer
- goto InstSend
- TXTHome movlw 0x40 ;set text home address
- goto InstSend
- TXTArea movlw 0x41 ;set text area
- goto InstSend
- GRPHHome movlw 0x42 ;set graphics home address
- goto InstSend
- GRPHArea movlw 0x43 ;set graphics area
- goto InstSend
- InstSend movwf COMMAND ;load instruction to COMMAND buffer
- call TwoData ;send instruction to GLCD
- return
- ;*************************************************************************************
- ;** **
- ;** Instruction Send Routines **
- ;** **
- ;*************************************************************************************
- TwoData call LCDStat ;check STA0 and STA1
- movfw DATAL ;preload W with DATAL buffer data
- call DWrite ;send data
- OneData call LCDStat ;check STA0 and STA1
- movfw DATAH ;preload W with DATAH buffer data
- call DWrite ;send data
- NoData call LCDStat ;check STA0 and STA1
- movfw COMMAND ;preload W with COMMAND buffer data
- call CWrite ;send instruction
- return ;done
- ;*************************************************************************************
- ;** **
- ;** Status Read Mode Enable/Disable **
- ;** **
- ;*************************************************************************************
- StatReadEn bsf CD ;command mode
- movlw RD_EN ;enable status read mode
- goto $+2
- StatReadDis movlw RD_DIS ;disable status read mode
- movwf PORTC
- return ;done
- ;*************************************************************************************
- ;** **
- ;** GLCD Status Check Routines **
- ;** **
- ;*************************************************************************************
- ;data auto write status check
- DAWStat call StatReadEn ;enable status read mode
- btfss D3 ;DARRDY = 1?
- goto $-1 ;no, check again
- goto StatDis ;yes, jump to StatDis
- ;data auto read status check
- DARStat call StatReadEn ;enable status read mode
- btfss D2 ;DAWRDY = 1?
- goto $-1 ;no, check again
- goto StatDis ;yes, jump to StatDis
- ;GLCD general status check
- LCDStat call StatReadEn ;enable status read mode
- btfsc D0 ;STA0 = 1?
- btfss D1 ;STA1 = 1?
- goto $-2 ;no, check again
- StatDis call StatReadDis ;yes, disable status read mode
- return ;done
- ;*************************************************************************************
- ;** **
- ;** Command/Data Write **
- ;** **
- ;*************************************************************************************
- CWrite bsf CD ;command mode
- goto $+2
- DWrite bcf CD ;data mode
- movwf PORTD ;load data port latch
- movlw WRT_EN ;enable write mode
- movwf PORTC
- banksel TRISD ;bank 1
- clrf TRISD ;PORTD output
- banksel 0 ;bank 0
- movlw WRT_DIS ;disable write mode
- movwf PORTC
- banksel TRISD ;bank 1
- comf TRISD,F ;PORTD input
- banksel 0 ;bank 0
- return ;done
- ;*************************************************************************************
- ;** **
- ;** Data Auto Write Routines **
- ;** **
- ;*************************************************************************************
- ;data auto write set
- DAWSet call LCDStat ;check STA0 and STA1
- movlw 0xB0 ;send data auto write set instruction
- movwf COMMAND
- call NoData
- call LCDStat ;check STA0 and STA1
- return ;done
- ;*************************************************************************************
- ;data auto write byte send
- DAWWrite call DAWStat ;check DAWRDY status
- movfw DATAL ;preload W with write data
- call DWrite ;write data
- return ;done
- ;*************************************************************************************
- ;data table auto write
- DAWDLoad call DIGIT ;fetch digit from digit table
- goto TData
- DAWPLoad call PUNC ;fetch punctuation from punctuation table
- goto TData
- DAWALoad call ALPHA ;fetch letter from letter table
- TData movwf DATAL
- call DAWWrite ;write character to display
- return ;done
- ;*************************************************************************************
- ;data auto write unset
- DAWReset call DAWStat ;check DAWRDY status
- movlw 0xB2 ;send data auto write reset instruction
- movwf COMMAND
- call NoData
- return ;done
- ;*************************************************************************************
- ;** **
- ;** Address Pointer Reset **
- ;** **
- ;*************************************************************************************
- GADDRRst movlw 0x00 ;reset address pointer to graphics home address
- goto $+2
- TADDRRst movlw 0x17 ;reset address pointer to text home address
- movwf DATAH
- movlw 0x00
- movwf DATAL
- call ADDR_PTR
- return
- ;*************************************************************************************
- ;** **
- ;** Graphics/Text RAM Clear **
- ;** **
- ;*************************************************************************************
- GRAMClear call GADDRRst ;set address pointer to graphics RAM home address
- movlw 128 ;init RAM counter
- goto $+3
- TRAMClear call TADDRRst ;set address pointer to text RAM home address
- movlw 32 ;init RAM counter
- movwf COUNT5
- call VRAMClear ;clear text RAM
- return ;done
- ;*************************************************************************************
- ;** **
- ;** VRAM Clear **
- ;** **
- ;*************************************************************************************
- VRAMClear call DAWSet ;set data auto write mode
- movlw 40 ;init counter
- movwf COUNT4
- movlw 0 ;write 0 to GLCD
- movwf DATAL
- call DAWWrite
- decfsz COUNT4,F ;decrement counter
- goto $-2 ;continue until COUNT4 = 0
- decfsz COUNT5,F ;decrement counter
- goto $-8 ;continue until COUNT5 = 0
- call DAWReset ;unset data auto write mode
- return ;done
- ;*************************************************************************************
- ;** **
- ;** Delay Routines **
- ;** **
- ;*************************************************************************************
- ;fixed 50mS delay
- Delay50mS movlw 0xFF ;init counters
- movwf COUNT1
- movwf COUNT2
- decfsz COUNT1,F ;decrement counter 1
- goto $-1 ;continue until counter 1 = 0
- decfsz COUNT2,F ;decrement counter 2
- goto $-3 ;continue decrementing counter 1 until counter 2 = 0
- return ;done
- ;*************************************************************************************
- ;variable delay
- Delay movwf COUNT3 ;load counter 3
- call Delay50mS ;run 50mS delay
- decfsz COUNT3,F ;decrement counter 3
- goto $-2 ;continue running 50mS delay until counter 3 = 0
- return ;done
- ;*************************************************************************************
- ;** **
- ;** PIC Initialization Routine **
- ;** **
- ;*************************************************************************************
- START movlw 5 ;command mode, reset active, 6x8 font
- movwf PORTA
- clrf PORTB ;clear PORTB output latch
- movlw 7 ;CE disable, read/write disable
- movwf PORTC
- clrf PORTD ;clear PORTD output latch
- clrf PORTE ;clear PORTE output latch
- banksel ANSEL ;bank 3
- clrf ANSEL ;all ports digital I/O mode
- clrf ANSELH
- banksel TRISA ;bank 1
- clrf TRISA ;ports A, B, C and E output
- clrf TRISB ;port D defaults to input as bi-directional data port
- clrf TRISC
- clrf TRISE
- banksel 0 ;bank 0
- ;*************************************************************************************
- ;** **
- ;** GLCD Initialization Routine **
- ;** **
- ;*************************************************************************************
- ;Display Init Parameters -
- ;Text XOR'ed with graphics, Character Generator ROM active
- ;Text and Graphics RAM on with no cursor
- ;Graphics Area - X = 40 columns at 6 pixels per column, Y = 64 lines per screen for a total of 2 screens available
- ;Text Area - X = 40 character positions per line, Y = 8 lines per screen for a total of 4 screens available
- ;GLCD hard reset
- GLCDReset bcf RST ;GLCD reset active
- call Delay50mS ;wait 50mS
- bsf RST ;GLCD reset disable
- ;begin GLCD initialization
- GLCDInit
- ;mode select
- movlw 0x81 ;XOR text with graphics
- movwf COMMAND
- call NoData
- ;graphics home address set
- movlw 0x00 ;set graphics home address to 0x0000
- movwf DATAL
- movlw 0x00
- movwf DATAH
- call GRPHHome
- ;set graphics area
- movlw 0x28 ;40 columns, 6 pixel bits per column
- movwf DATAL
- movlw 0
- movwf DATAH
- call GRPHArea
- ;text home address set
- movlw 0x00 ;set text home address to 0x1700
- movwf DATAL
- movlw 0x17
- movwf DATAH
- call TXTHome
- ;set text area
- movlw 0x28 ;40 columns, 8 lines
- movwf DATAL
- movlw 0
- movwf DATAH
- call TXTArea
- ;set offset pointer
- movlw 0x03 ;CG RAM occupies 0x1800 - 0x1FFF
- movlw DATAL
- movlw 0
- movwf DATAH
- call OFST_PTR
- ;clear graphics RAM
- call GRAMClear
- ;clear text RAM
- call TRAMClear
- ;set address pointer to graphics RAM home address
- call GADDRRst
- ;display on
- movlw 0x9C ;text and graphics RAM on, no cursor
- movwf COMMAND
- call NoData
- ;*************************************************************************************
- ;** **
- ;** Begin Main Program **
- ;** **
- ;*************************************************************************************
- MAIN goto $
- end
Add Comment
Please, Sign In to add comment