Guest User

Untitled

a guest
Dec 4th, 2017
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MPASM 5.50 KB | None | 0 0
  1. ;*************************************************************************************************
  2. ;**                                                                                             **
  3. ;**                                     Header Information                                      **
  4. ;**                                                                                             **
  5. ;*************************************************************************************************
  6.  
  7.                 list            p=16F877A, r=dec, w=-302
  8.                 include         <P16F877A.INC>
  9.                 __config        _WRT_OFF & _LVP_OFF & _BODEN_OFF & _PWRTE_ON & _WDT_OFF & _HS_OSC
  10.  
  11. ;Processor is 16F877A
  12. ;Default radix is decimal unless otherwise noted
  13. ;Suppress assembler bank select messages
  14.  
  15. ;Program Code Protection Off (CP1/CP0)
  16. ;Data Code Protection Off (CPD)
  17. ;DEBUG OFf (DEBUG)
  18. ;Program ROM Write Enable Off (WRT)
  19. ;Low Voltage Programming Off (LVP)
  20. ;Brown Out Detection Off (BODEN)
  21. ;Power Up Timer On (PWRTE)
  22. ;Watchdog Timer Off (WDT)
  23. ;High Speed Crystal Oscillator (HS)
  24.  
  25. ;Fosc = 20MHz
  26.  
  27. ;*************************************************************************************************
  28. ;**                                                                                             **
  29. ;**                             Variable Definitions                                            **
  30. ;**                                                                                             **
  31. ;*************************************************************************************************
  32.  
  33.                 cblock          0x70
  34.                                 TABLECOUNT  ;used in looping routines
  35.                 COUNT1      ;used in delay routine
  36.                 COUNT2      ;used in delay routine
  37.                 COUNT3      ;used in delay routine
  38.                 TMP1        ;temporary storage
  39.                 TMP2
  40.                 TEMPLCD1    ;temp store for 4 bit mode 
  41.                 TEMPLCD2
  42.                 endc
  43.  
  44. ;*************************************************************************************************
  45. ;**                                                                                             **
  46. ;**                                     LCD Handshake Lines                                     **
  47. ;**                                                                                             **
  48. ;*************************************************************************************************
  49.  
  50. LCD_DATAPORT    EQU     PORTD
  51. LCD_DATATRIS    EQU     TRISD
  52. LCD_FNPORT  EQU     PORTE
  53. LCD_FNTRIS  EQU     TRISE  
  54.  
  55. #define     LCD_RS      PORTE,0
  56. #define     LCD_RW      PORTE,1
  57. #define     LCD_E       PORTE,2  
  58.  
  59. ;*************************************************************************************************
  60. ;**                                                                                             **
  61. ;**                             Initialization Routine                                          **
  62. ;**                                                                                             **
  63. ;*************************************************************************************************
  64.  
  65.                 org             0x000                   ;reset vector
  66.                 goto            START
  67.  
  68. START           clrf            PORTA                   ;init all ports
  69.                 clrf            PORTB
  70.                 clrf            PORTC
  71.                 clrf            PORTD
  72.                 clrf        PORTE
  73.         clrf        count
  74.                 banksel         ADCON1                  ;bank 1
  75.                 movlw           b'00000110'             ;AN0-AN7 digital I/O
  76.                 movwf           ADCON1
  77.                 movlw           b'00000000'             ;all ports output
  78.                 movwf           TRISD
  79.         movwf       TRISE
  80.                 banksel         0x00                    ;bank 0
  81.         call        LCD_Init        ;setup LCD
  82.         goto        $           ;done
  83.  
  84.  
  85. ;*************************************************************************************************
  86. ;**                                                                                             **
  87. ;**                                     Subroutines                                             **
  88. ;**                                                                                             **
  89. ;*************************************************************************************************
  90.  
  91. ;Delays
  92.  
  93. Delay125uS  movlw       113
  94.         movwf       COUNT1
  95.         decfsz      COUNT1,F
  96.         goto        $-1
  97.         return
  98.  
  99. Delay5mS    movlw       0xFF            ;init delay counters 1 and 2
  100.         movwf       COUNT1
  101.         movlw       0x20
  102.         movwf       COUNT2
  103.         decfsz      COUNT1,F        ;decrement COUNT1 until COUNT1 = 0
  104.         goto        $-1
  105.         decfsz      COUNT2,F        ;decrement COUNT1 again until COUNT2 = 0
  106.         goto        $-3
  107.         return
  108.  
  109. Delay       movwf       COUNT3
  110.         call        Delay40mS
  111.         decfsz      COUNT3,F
  112.         goto        $-2
  113.         return
  114.  
  115. ;*************************************************************************************************
  116.  
  117. ;LCD Initialization
  118.  
  119. LCD_Init    bcf     LCD_E           ;e line low
  120.         bcf     LCD_RS          ;RS line low, set up for control
  121.         call        Delay125uS      ;delay 125uS
  122.         movlw       0x38            ;8-bit, 5x7
  123.         movwf       LCD_DATAPORT        ;0011 1000
  124.         call        Pulse           ;pulse and delay
  125.         movlw       0x0F            ;display on, cursor blinking]
  126.         movwf       LCD_DATAPORT        ;0000 1111
  127.         call        Pulse
  128.         movlw       0x01            ;clear display
  129.         movwf       LCD_DATAPORT        ;0000 0001
  130.         call        Pulse
  131.         call        Delay5mS        ;delay 5mS after init
  132.         return
  133.  
  134. ;*************************************************************************************************
  135.  
  136.                 end                                    ;end of file
Add Comment
Please, Sign In to add comment