Guest User

Untitled

a guest
Apr 22nd, 2018
180
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MPASM 17.53 KB | None | 0 0
  1. ;*************************************************************************************
  2. ;*************************************************************************************
  3. ;**                                             **
  4. ;**                 Driver For Toshiba T6963                    **
  5. ;**                       Graphics LCD Display Controller                   **
  6. ;**                        For the Microchip PIC 16F887                 **
  7. ;**                          By Jon Wilder                  **
  8. ;**                    V1.1 Date: 12/06/2011                    **
  9. ;**                                             **
  10. ;*************************************************************************************
  11. ;**                                             **
  12. ;**                 Header Information                      **
  13. ;**                                             **
  14. ;*************************************************************************************
  15. ;**                                             **
  16. ;** Processor Type: PIC 16F887                                  **
  17. ;** Default Radix: Decimal                                      **
  18. ;** Error Level: Suppress all assembler bank select warnings                        **
  19. ;** Reference header file P16F887.INC for all SFR and configuration word labels             **
  20. ;**                                             **
  21. ;** Configuration Word 1                                        **
  22. ;**                                             **
  23. ;** Debug Mode Off (Default)                                    **
  24. ;** Low Voltage Programming Off                                 **
  25. ;** Fail Safe Clock Monitor Off                                 **
  26. ;** Internal External Switchover Off                                    **
  27. ;** Brown Out Reset Off                                     **
  28. ;** Data Code Protect Off (Default)                                 **
  29. ;** Code Protect Off (Default)                                  **
  30. ;** RA5 is MCLRE (Default)                                      **
  31. ;** Power Up Timer On                                       **
  32. ;** Watchdog Timer Off                                      **
  33. ;** High Speed Oscillator                                       **
  34. ;**                                             **
  35. ;** Configuration Word 2                                        **
  36. ;** Flash Write Protect Off (Default)                                   **
  37. ;** Brown Out Reset 4V (Default - Disabled in Configuration Word 1)                 **
  38. ;**                                             **
  39. ;** Fosc = 16MHz                                            **
  40. ;**                                             **
  41. ;*************************************************************************************
  42. ;*************************************************************************************
  43.  
  44.             list        p=16F887, r=dec, w=-302
  45.             include     <P16F887.INC>
  46.             __config        _CONFIG1, _LVP_OFF & _FCMEN_OFF & _IESO_OFF & _BOR_OFF & _PWRTE_ON & _WDT_OFF & _HS_OSC
  47.  
  48. ;*************************************************************************************
  49. ;**                                             **
  50. ;**                 Control/Data Line Labels                    **
  51. ;**                                             **
  52. ;*************************************************************************************
  53.  
  54. ;nemonics for enabling/disabling read/write modes
  55.  
  56. WRT_EN          EQU     2           ;write mode enable
  57. WRT_DIS         EQU     7           ;write mode disable
  58. RD_EN           EQU     1           ;read mode enable
  59. RD_DIS          EQU     7           ;read mode disable
  60.  
  61. ;control line labels
  62.  
  63. #define         CD      PORTA,RA0       ;command(high)/data(low) mode select
  64. #define         RST     PORTA,RA1       ;reset (active low)
  65. #define         FONT        PORTA,RA2       ;6x8 (high)/8x8 (low) font select
  66. #define         WRITE       PORTC,RC0       ;write enable (low)/disable (high)
  67. #define         READ        PORTC,RC1       ;read enable (low)/disable (high)
  68. #define         CE      PORTC,RC2       ;chip enable (active low)
  69.  
  70. ;bi-directional data port
  71.  
  72. #define         D0      PORTD,RD0       ;data port bit 0
  73. #define         D1      PORTD,RD1       ;data port bit 1
  74. #define         D2      PORTD,RD2       ;data port bit 2
  75. #define         D3      PORTD,RD3       ;data port bit 3
  76. #define         D4      PORTD,RD4       ;data port bit 4
  77. #define         D5      PORTD,RD5       ;data port bit 5
  78. #define         D6      PORTD,RD6       ;data port bit 6
  79. #define         D7      PORTD,RD7       ;data port bit 7
  80.  
  81. ;*************************************************************************************
  82. ;**                                             **
  83. ;**                 RAM Buffer Labels                       **
  84. ;**                                             **
  85. ;*************************************************************************************
  86.  
  87.             cblock      0x20
  88.                     TEMP            ;temp buffer
  89.                     DATAL           ;GLCD data low byte buffer
  90.                     DATAH           ;GLCD data high byte buffer
  91.                     COMMAND     ;GLCD instruction buffer
  92.                     MIDI_TEMP       ;MIDI data buffer
  93.             endc
  94.  
  95.             cblock      0x70
  96.                     W_TEMP          ;interrupt context save for W
  97.                     STATUS_TEMP     ;interrupt context save for STATUS
  98.                     PCLATH_TEMP     ;interrupt context save for PCLATH
  99.                     COUNT1          ;delay counter 1
  100.                     COUNT2          ;delay counter 2
  101.                     COUNT3          ;delay counter 3
  102.                     COUNT4          ;general purpose counter
  103.                     COUNT5          ;general purpose counter
  104.                     COUNT6          ;general purpose counter
  105.                     DATA_EE_ADDR        ;data EEPROM address buffer
  106.                     DATA_EE_DATA        ;data EEPROM data buffer
  107.             endc
  108.  
  109. ;*************************************************************************************
  110. ;**                                             **
  111. ;**                 Start of Main Code                      **
  112. ;**                                             **
  113. ;*************************************************************************************
  114.  
  115.             org     0x000           ;reset vector
  116.             goto        START           ;jump to start of main code
  117.  
  118.             org     0x004           ;interrupt vector
  119.             goto        ISR         ;jump to start of interrupt handler
  120.  
  121. ;*************************************************************************************
  122. ;**                                             **
  123. ;**                 Data Tables                     **
  124. ;**                                             **
  125. ;*************************************************************************************
  126.  
  127. ;letter table
  128.  
  129. ALPHA           addwf       PCL,F
  130.             retlw       0           ;space
  131.             retlw       0x21            ;A
  132.             retlw       0x22            ;B
  133.             retlw       0x23            ;C
  134.             retlw       0x24            ;D
  135.             retlw       0x25            ;E
  136.             retlw       0x26            ;F
  137.             retlw       0x27            ;G
  138.             retlw       0x28            ;H
  139.             retlw       0x29            ;I
  140.             retlw       0x2A            ;J
  141.             retlw       0x2B            ;K
  142.             retlw       0x2C            ;L
  143.             retlw       0x2D            ;M
  144.             retlw       0x2E            ;N
  145.             retlw       0x2F            ;O
  146.             retlw       0x30            ;P
  147.             retlw       0x31            ;Q
  148.             retlw       0x32            ;R
  149.             retlw       0x33            ;S
  150.             retlw       0x34            ;T
  151.             retlw       0x35            ;U
  152.             retlw       0x36            ;V
  153.             retlw       0x37            ;W
  154.             retlw       0x38            ;X
  155.             retlw       0x39            ;Y
  156.             retlw       0x3A            ;Z
  157.  
  158. ;digit table
  159.  
  160. DIGIT           addwf       PCL,F
  161.             retlw       0x10            ;0
  162.             retlw       0x11            ;1
  163.             retlw       0x12            ;2
  164.             retlw       0x13            ;3
  165.             retlw       0x14            ;4
  166.             retlw       0x15            ;5
  167.             retlw       0x16            ;6
  168.             retlw       0x17            ;7
  169.             retlw       0x18            ;8
  170.             retlw       0x19            ;9
  171.             retlw       0x21            ;A
  172.             retlw       0x22            ;B
  173.             retlw       0x23            ;C
  174.             retlw       0x24            ;D
  175.             retlw       0x25            ;E
  176.             retlw       0x26            ;F
  177.  
  178. ;punctuation table
  179.  
  180. PUNC            addwf       PCL,F
  181.             retlw       0x01            ; !
  182.             retlw       0x02            ; "
  183.             retlw       0x03            ; #
  184.             retlw       0x04            ; $
  185.             retlw       0x05            ; %
  186.             retlw       0x06            ; &
  187.             retlw       0x07            ; '
  188.             retlw       0x08            ; (
  189.             retlw       0x09            ; )
  190.             retlw       0x0A            ; *
  191.             retlw       0x0B            ; +
  192.             retlw       0x0C            ; ,
  193.             retlw       0x0D            ; -
  194.             retlw       0x0E            ; .
  195.             retlw       0x0F            ; /
  196.             retlw       0x1A            ; :
  197.             retlw       0x1B            ; ;
  198.             retlw       0x1C            ; <
  199.             retlw       0x1D            ; =
  200.             retlw       0x1E            ; >
  201.             retlw       0x1F            ; ?
  202.             retlw       0x20            ; @
  203.             retlw       0x3B            ; [
  204.             retlw       0x3C            ; \
  205.             retlw       0x3D            ; ]
  206.             retlw       0x3E            ; ^
  207.             retlw       0x3F            ; _
  208.  
  209. ;*************************************************************************************
  210. ;**                                             **
  211. ;**                 Interrupt Handler                       **
  212. ;**                                             **
  213. ;*************************************************************************************
  214.  
  215. ;interrupt context save
  216.  
  217. ISR         movwf       W_TEMP          ;save W
  218.             swapf       STATUS,W        ;save STATUS
  219.             banksel     0           ;bank 0
  220.             movwf       STATUS_TEMP
  221.             movfw       PCLATH          ;save PCLATH
  222.             movwf       PCLATH_TEMP
  223.  
  224. ;place interrupt code here
  225.  
  226. ;interrupt context restore
  227.  
  228. ISRExit         movfw       PCLATH_TEMP     ;restore PCLATH
  229.             movwf       PCLATH
  230.             swapf       STATUS_TEMP,W       ;restore STATUS
  231.             movwf       STATUS
  232.             swapf       W_TEMP,F        ;restore W
  233.             swapf       W_TEMP,W
  234.             retfie                  ;return from interrupt
  235.  
  236. ;*************************************************************************************
  237. ;**                                             **
  238. ;**                 Two Data Byte Instructions                  **
  239. ;**                                             **
  240. ;*************************************************************************************
  241.  
  242. CSR_PTR         movlw       0x21            ;set cursor pointer
  243.             goto        InstSend
  244. OFST_PTR        movlw       0x22            ;set offset register
  245.             goto        InstSend
  246. ADDR_PTR        movlw       0x24            ;set address pointer
  247.             goto        InstSend
  248. TXTHome     movlw       0x40            ;set text home address
  249.             goto        InstSend
  250. TXTArea         movlw       0x41            ;set text area
  251.             goto        InstSend
  252. GRPHHome        movlw       0x42            ;set graphics home address
  253.             goto        InstSend
  254. GRPHArea        movlw       0x43            ;set graphics area
  255.             goto        InstSend
  256. InstSend            movwf       COMMAND     ;load instruction to COMMAND buffer
  257.             call        TwoData         ;send instruction to GLCD
  258.             return
  259.  
  260. ;*************************************************************************************
  261. ;**                                             **
  262. ;**                  Instruction Send Routines                      **
  263. ;**                                             **
  264. ;*************************************************************************************
  265.            
  266. TwoData         call        LCDStat         ;check STA0 and STA1
  267.             movfw       DATAL           ;preload W with DATAL buffer data
  268.             call        DWrite          ;send data
  269. OneData         call        LCDStat         ;check STA0 and STA1
  270.             movfw       DATAH           ;preload W with DATAH buffer data
  271.             call        DWrite          ;send data
  272. NoData          call        LCDStat         ;check STA0 and STA1
  273.             movfw       COMMAND     ;preload W with COMMAND buffer data        
  274.             call        CWrite          ;send instruction
  275.             return                  ;done
  276.            
  277. ;*************************************************************************************
  278. ;**                                             **
  279. ;**             Status Read Mode Enable/Disable                 **
  280. ;**                                             **
  281. ;*************************************************************************************
  282.            
  283. StatReadEn      bsf     CD          ;command mode
  284.             movlw       RD_EN           ;enable status read mode
  285.             goto        $+2
  286. StatReadDis     movlw       RD_DIS          ;disable status read mode          
  287.             movwf       PORTC
  288.             return                  ;done
  289.  
  290. ;*************************************************************************************
  291. ;**                                             **
  292. ;**                GLCD Status Check Routines                   **
  293. ;**                                             **
  294. ;*************************************************************************************
  295.  
  296. ;data auto write status check
  297.  
  298. DAWStat         call        StatReadEn      ;enable status read mode
  299.             btfss       D3          ;DARRDY = 1?
  300.             goto        $-1         ;no, check again
  301.             goto        StatDis         ;yes, jump to StatDis
  302.            
  303. ;data auto read status check
  304.            
  305. DARStat         call        StatReadEn      ;enable status read mode
  306.             btfss       D2          ;DAWRDY = 1?
  307.             goto        $-1         ;no, check again
  308.             goto        StatDis         ;yes, jump to StatDis
  309.            
  310. ;GLCD general status check         
  311.            
  312. LCDStat         call        StatReadEn      ;enable status read mode
  313.             btfsc       D0          ;STA0 = 1?
  314.             btfss       D1          ;STA1 = 1?
  315.             goto        $-2         ;no, check again
  316. StatDis         call        StatReadDis     ;yes, disable status read mode
  317.             return                  ;done
  318.            
  319. ;*************************************************************************************
  320. ;**                                             **
  321. ;**                  Command/Data Write                     **
  322. ;**                                             **
  323. ;*************************************************************************************
  324.  
  325. CWrite          bsf     CD          ;command mode
  326.             goto        $+2
  327. DWrite          bcf     CD          ;data mode
  328.             movwf       PORTD           ;load data port latch
  329.             movlw       WRT_EN          ;enable write mode
  330.             movwf       PORTC
  331.             banksel     TRISD           ;bank 1
  332.             clrf        TRISD           ;PORTD output
  333.             banksel     0           ;bank 0
  334.             movlw       WRT_DIS         ;disable write mode
  335.             movwf       PORTC
  336.             banksel     TRISD           ;bank 1
  337.             comf        TRISD,F         ;PORTD input
  338.             banksel     0           ;bank 0
  339.             return                  ;done          
  340.  
  341. ;*************************************************************************************
  342. ;**                                             **
  343. ;**                  Data Auto Write Routines                       **
  344. ;**                                             **
  345. ;*************************************************************************************
  346.            
  347. ;data auto write set
  348.  
  349. DAWSet          call        LCDStat         ;check STA0 and STA1
  350.             movlw       0xB0            ;send data auto write set instruction
  351.             movwf       COMMAND
  352.             call        NoData
  353.             call        LCDStat         ;check STA0 and STA1
  354.             return                  ;done
  355.            
  356. ;*************************************************************************************
  357.  
  358. ;data auto write byte send
  359.  
  360. DAWWrite        call        DAWStat         ;check DAWRDY status
  361.             movfw       DATAL           ;preload W with write data
  362.             call        DWrite          ;write data
  363.             return                  ;done
  364.  
  365. ;*************************************************************************************
  366.  
  367. ;data table auto write
  368.  
  369. DAWDLoad        call        DIGIT           ;fetch digit from digit table
  370.             goto        TData          
  371. DAWPLoad        call        PUNC            ;fetch punctuation from punctuation table
  372.             goto        TData
  373. DAWALoad        call        ALPHA           ;fetch letter from letter table
  374. TData           movwf       DATAL
  375.             call        DAWWrite        ;write character to display
  376.             return                  ;done
  377.  
  378. ;*************************************************************************************
  379.  
  380. ;data auto write unset
  381.  
  382. DAWReset        call        DAWStat         ;check DAWRDY status
  383.             movlw       0xB2            ;send data auto write reset instruction
  384.             movwf       COMMAND
  385.             call        NoData
  386.             return                  ;done
  387.    
  388. ;*************************************************************************************
  389. ;**                                             **
  390. ;**                 Address Pointer Reset                   **
  391. ;**                                             **
  392. ;*************************************************************************************
  393.  
  394. GADDRRst        movlw       0x00            ;reset address pointer to graphics home address
  395.             goto        $+2
  396. TADDRRst        movlw       0x17            ;reset address pointer to text home address
  397.             movwf       DATAH
  398.             movlw       0x00           
  399.             movwf       DATAL
  400.             call        ADDR_PTR
  401.             return
  402.            
  403. ;*************************************************************************************
  404. ;**                                             **
  405. ;**                       Graphics/Text RAM Clear                   **
  406. ;**                                             **
  407. ;*************************************************************************************         
  408.            
  409. GRAMClear       call        GADDRRst    ;set address pointer to graphics RAM home address
  410.             movlw       128     ;init RAM counter
  411.             goto        $+3
  412. TRAMClear       call        TADDRRst    ;set address pointer to text RAM home address
  413.             movlw       32      ;init RAM counter
  414.             movwf       COUNT5
  415.             call        VRAMClear   ;clear text RAM
  416.             return              ;done  
  417.            
  418. ;*************************************************************************************
  419. ;**                                             **
  420. ;**                 VRAM Clear                      **
  421. ;**                                             **
  422. ;*************************************************************************************
  423.  
  424. VRAMClear       call        DAWSet          ;set data auto write mode
  425.             movlw       40          ;init counter
  426.             movwf       COUNT4
  427.             movlw       0           ;write 0 to GLCD
  428.             movwf       DATAL
  429.             call        DAWWrite
  430.             decfsz      COUNT4,F        ;decrement counter
  431.             goto        $-2         ;continue until COUNT4 = 0
  432.             decfsz      COUNT5,F        ;decrement counter
  433.             goto        $-8         ;continue until COUNT5 = 0
  434.             call        DAWReset        ;unset data auto write mode
  435.             return                  ;done
  436.            
  437. ;*************************************************************************************
  438. ;**                                             **
  439. ;**                 Delay Routines                      **
  440. ;**                                             **
  441. ;*************************************************************************************
  442.  
  443. ;fixed 50mS delay
  444.            
  445. Delay50mS       movlw       0xFF            ;init counters
  446.             movwf       COUNT1
  447.             movwf       COUNT2
  448.             decfsz      COUNT1,F        ;decrement counter 1
  449.             goto        $-1         ;continue until counter 1 = 0
  450.             decfsz      COUNT2,F        ;decrement counter 2
  451.             goto        $-3         ;continue decrementing counter 1 until counter 2 = 0
  452.             return                  ;done
  453.  
  454. ;*************************************************************************************
  455.  
  456. ;variable delay
  457.  
  458. Delay           movwf       COUNT3          ;load counter 3
  459.             call        Delay50mS       ;run 50mS delay
  460.             decfsz      COUNT3,F        ;decrement counter 3
  461.             goto        $-2         ;continue running 50mS delay until counter 3 = 0
  462.             return                  ;done
  463.  
  464. ;*************************************************************************************
  465. ;**                                             **
  466. ;**             PIC Initialization Routine                      **
  467. ;**                                             **
  468. ;*************************************************************************************
  469.  
  470. START           movlw       5       ;command mode, reset active, 6x8 font
  471.             movwf       PORTA
  472.             clrf        PORTB       ;clear PORTB output latch
  473.             movlw       7       ;CE disable, read/write disable
  474.             movwf       PORTC      
  475.             clrf        PORTD       ;clear PORTD output latch
  476.             clrf        PORTE       ;clear PORTE output latch
  477.             banksel     ANSEL       ;bank 3
  478.             clrf        ANSEL       ;all ports digital I/O mode
  479.             clrf        ANSELH
  480.             banksel     TRISA       ;bank 1
  481.             clrf        TRISA       ;ports A, B, C and E output
  482.             clrf        TRISB       ;port D defaults to input as bi-directional data port
  483.             clrf        TRISC
  484.             clrf        TRISE
  485.             banksel     0       ;bank 0
  486.  
  487. ;*************************************************************************************
  488. ;**                                             **
  489. ;**                   GLCD Initialization Routine                   **
  490. ;**                                             **
  491. ;*************************************************************************************
  492.  
  493. ;Display Init Parameters -
  494.  
  495. ;Text XOR'ed with graphics, Character Generator ROM active
  496. ;Text and Graphics RAM on with no cursor
  497. ;Graphics Area - X = 40 columns at 6 pixels per column, Y = 64 lines per screen for a total of 2 screens available
  498. ;Text Area - X = 40 character positions per line, Y = 8 lines per screen for a total of 4 screens available
  499.  
  500. ;GLCD hard reset
  501.  
  502. GLCDReset       bcf     RST     ;GLCD reset active
  503.             call        Delay50mS   ;wait 50mS
  504.             bsf     RST     ;GLCD reset disable
  505.            
  506. ;begin GLCD initialization
  507.  
  508. GLCDInit
  509.  
  510. ;mode select
  511.            
  512.             movlw       0x81        ;XOR text with graphics
  513.             movwf       COMMAND
  514.             call        NoData
  515.  
  516. ;graphics home address set
  517.  
  518.             movlw       0x00        ;set graphics home address to 0x0000
  519.             movwf       DATAL
  520.             movlw       0x00
  521.             movwf       DATAH
  522.             call        GRPHHome
  523.  
  524. ;set graphics area
  525.  
  526.             movlw       0x28        ;40 columns, 6 pixel bits per column
  527.             movwf       DATAL
  528.             movlw       0
  529.             movwf       DATAH
  530.             call        GRPHArea
  531.  
  532. ;text home address set 
  533.  
  534.             movlw       0x00        ;set text home address to 0x1700
  535.             movwf       DATAL
  536.             movlw       0x17
  537.             movwf       DATAH
  538.             call        TXTHome
  539.  
  540. ;set text area
  541.    
  542.             movlw       0x28        ;40 columns, 8 lines
  543.             movwf       DATAL
  544.             movlw       0
  545.             movwf       DATAH
  546.             call        TXTArea
  547.  
  548. ;set offset pointer
  549.  
  550.             movlw       0x03        ;CG RAM occupies 0x1800 - 0x1FFF
  551.             movlw       DATAL
  552.             movlw       0
  553.             movwf       DATAH
  554.             call        OFST_PTR
  555.            
  556. ;clear graphics RAM
  557.             call        GRAMClear  
  558.            
  559. ;clear text RAM
  560.  
  561.             call        TRAMClear
  562.            
  563. ;set address pointer to graphics RAM home address
  564.  
  565.             call        GADDRRst
  566.            
  567. ;display on
  568.             movlw       0x9C        ;text and graphics RAM on, no cursor
  569.             movwf       COMMAND
  570.             call        NoData
  571.            
  572. ;*************************************************************************************
  573. ;**                                             **
  574. ;**                 Begin Main Program                  **
  575. ;**                                             **
  576. ;*************************************************************************************
  577.            
  578. MAIN            goto        $
  579.    
  580.             end
Add Comment
Please, Sign In to add comment