⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 lcd.sdi

📁 PROTEUS仿真PIC16F877的例子
💻 SDI
字号:
,,,;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
,,,;
,,,;       LCD.ASM         MPB     Ver 1.0         28-8-05
,,,;
,,,;       Outputs fixed and variable characters
,,,;       to 16x2 LCD in 4-bit mode
,,,;
,,,;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
,,,
,,,        PROCESSOR 16F877A
,,,;       Clock = XT 4MHz, standard fuse settings
00002007,3731,,        __CONFIG 0x3731
,,,
,,,; LABEL EQUATES ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
,,,
,,,        INCLUDE "P16F877A.INC"  ; Standard register labels
,,,
,,,Timer1  EQU     20              ; 1ms count register
,,,TimerX  EQU     21              ; Xms count register
,,,Var     EQU     22              ; Output variable
,,,Point   EQU     23              ; Program table pointer
,,,Select  EQU     24              ; Copy of RS bit
,,,OutCod  EQU     25              ; Temp store for output code
,,,
,,,RS      EQU     1               ; Register select output bit
,,,E       EQU     2               ; Display enable
,,,
,,,; PROGRAM BEGINS ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
,,,
,,,        ORG     0               ; Place machine code
00000000,0000,,        NOP                     ; for ICD mode
,,,
00000001,1683 1303,,        BANKSEL TRISD           ; Select bank 1
00000003,0103,,        CLRW                    ; All outputs
00000004,0088,,        MOVWF   TRISD           ; Initialise display port
00000005,1283 1303,,        BANKSEL PORTD           ; Select bank 0
00000007,0188,,        CLRF    PORTD           ; Clear display outputs
,,,
00000008,288A,,        GOTO    Start           ; Jump to main program
,,,
,,,
,,,; SUBROUTINES ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
,,,
,,,; 1ms delay with 1us cycle time (1000 cycles)...............
,,,
00000009,30F9,Onems,Onems   MOVLW   D'249'          ; Count for 1ms delay
0000000A,00A0,,        MOVWF   Timer1          ; Load count
0000000B,0000,Loop1,Loop1   NOP                     ; Pad for 4 cycle loop
0000000C,0BA0,,        DECFSZ  Timer1          ; Count
0000000D,280B,,        GOTO    Loop1           ; until Z
0000000E,0008,,        RETURN                  ; and finish
,,,
,,,
,,,; Delay Xms, X received in W ...............................
,,,
0000000F,00A1,Xms,Xms     MOVWF   TimerX          ; Count for X ms
00000010,2009,LoopX,LoopX   CALL    Onems           ; Delay 1ms
00000011,0BA1,,        DECFSZ  TimerX          ; Repeat X times
00000012,2810,,        GOTO    LoopX           ; until Z
00000013,0008,,        RETURN                  ; and finish
,,,
,,,
,,,; Generate data/command clock siganl E .....................
,,,
00000014,1508,PulseE,PulseE  BSF     PORTD,E         ; Set E high
00000015,2009,,        CALL    Onems           ; Delay 1ms
00000016,1108,,        BCF     PORTD,E         ; Reset E low
00000017,2009,,        CALL    Onems           ; Delay 1ms
00000018,0008,,        RETURN                  ; done
,,,
,,,
,,,; Send a command byte in two nibbles from RB4 - RB7 ........
,,,
00000019,00A5,Send,Send    MOVWF   OutCod          ; Store output code
0000001A,39F0,,        ANDLW   0F0             ; Clear low nybble
0000001B,0088,,        MOVWF   PORTD           ; Output high nybble
0000001C,18A4,,        BTFSC   Select,RS       ; Test RS bit
0000001D,1488,,        BSF     PORTD,RS        ; and set for data
0000001E,2014,,        CALL    PulseE          ; and clock display register
0000001F,2009,,        CALL    Onems           ; wait 1ms for display
,,,
00000020,0EA5,,        SWAPF   OutCod          ; Swap low and high nybbles
00000021,0825,,        MOVF    OutCod,W        ; Retrieve output code
00000022,39F0,,        ANDLW   0F0             ; Clear low nybble
00000023,0088,,        MOVWF   PORTD           ; Output low nybble
00000024,18A4,,        BTFSC   Select,RS       ; Test RS bit
00000025,1488,,        BSF     PORTD,RS        ; and set for data
00000026,2014,,        CALL    PulseE          ; and clock display register
00000027,2009,,        CALL    Onems           ; wait 1ms for display
00000028,0008,,        RETURN                  ; done
,,,
,,,
,,,;       Table of fixed characters to send ..................
,,,
00000029,0782,Line1,Line1   ADDWF   PCL             ; Modify program counter
0000002A,3443,,        RETLW   'C'             ; Pointer = 0
0000002B,344F,,        RETLW   'O'             ; Pointer = 1
0000002C,344E,,        RETLW   'N'             ; Pointer = 2
0000002D,3453,,        RETLW   'S'             ; Pointer = 3
0000002E,3454,,        RETLW   'T'             ; Pointer = 4
0000002F,343A,,        RETLW   ':'             ; Pointer = 5
00000030,3430,,        RETLW   '0'             ; Pointer = 6
00000031,3431,,        RETLW   '1'             ; Pointer = 7
00000032,3432,,        RETLW   '2'             ; Pointer = 8
00000033,3433,,        RETLW   '3'             ; Pointer = 9
00000034,3434,,        RETLW   '4'             ; Pointer = 10
00000035,3435,,        RETLW   '5'             ; Pointer = 11
00000036,3436,,        RETLW   '6'             ; Pointer = 12
00000037,3437,,        RETLW   '7'             ; Pointer = 13
00000038,3438,,        RETLW   '8'             ; Pointer = 14
00000039,3439,,        RETLW   '9'             ; Pointer = 15
,,,
0000003A,0782,Line2,Line2   ADDWF   PCL             ; Modify program counter
0000003B,3456,,        RETLW   'V'             ; Pointer = 0
0000003C,3441,,        RETLW   'A'             ; Pointer = 1
0000003D,3452,,        RETLW   'R'             ; Pointer = 2
0000003E,3449,,        RETLW   'I'             ; Pointer = 3
0000003F,3441,,        RETLW   'A'             ; Pointer = 4
00000040,3442,,        RETLW   'B'             ; Pointer = 5
00000041,344C,,        RETLW   'L'             ; Pointer = 6
00000042,3445,,        RETLW   'E'             ; Pointer = 7
00000043,3420,,        RETLW   ' '             ; Pointer = 8
00000044,343D,,        RETLW   '='             ; Pointer = 9
00000045,3420,,        RETLW   ' '             ; Pointer = 10
,,,
,,,
,,,; Initialise the display....................................
,,,
00000046,3064,Init,Init    MOVLW   D'100'          ; Load count for 100ms delay
00000047,200F,,        CALL    Xms             ; and wait for display start
00000048,30F0,,        MOVLW   0F0             ; Mask for select code
00000049,00A4,,        MOVWF   Select          ; High nybble not masked
,,,
0000004A,3030,,        MOVLW   0x30            ; Load initial nibble
0000004B,0088,,        MOVWF   PORTD           ; and output it to display
0000004C,2014,,        CALL    PulseE          ; Latch initial code
0000004D,3005,,        MOVLW   D'5'            ; Set delay 5ms
0000004E,200F,,        CALL    Xms             ; and wait
0000004F,2014,,        CALL    PulseE          ; Latch initial code again
00000050,2009,,        CALL    Onems           ; Wait 1ms
00000051,2014,,        CALL    PulseE          ; Latch initial code again
00000052,1208,,        BCF     PORTD,4         ; Set 4-bit mode
00000053,2014,,        CALL    PulseE          ; Latch it
,,,
00000054,3028,,        MOVLW   0x28            ; Set 4-bit mode, 2 lines
00000055,2019,,        CALL    Send            ; and send code
00000056,3008,,        MOVLW   0x08            ; Switch off display
00000057,2019,,        CALL    Send            ; and send code
00000058,3001,,        MOVLW   0x01            ; Code to clear display
00000059,2019,,        CALL    Send            ; and send code
0000005A,3006,,        MOVLW   0x06            ; Enable cursor auto inc
0000005B,2019,,        CALL    Send            ; and send code
0000005C,3080,,        MOVLW   0x80            ; Zero display address
0000005D,2019,,        CALL    Send            ; and send code
0000005E,300C,,        MOVLW   0x0C            ; Turn on display
0000005F,2019,,        CALL    Send            ; and send code
,,,
00000060,0008,,        RETURN                  ; Done
,,,
,,,
,,,; Send the fixed message to the display.....................
,,,
00000061,01A3,OutMes,OutMes  CLRF    Point           ; Reset table pointer
00000062,14A4,,        BSF     Select,RS       ; Select data mode
,,,
00000063,0823,Mess1,Mess1   MOVF    Point,W         ; and load it
00000064,2029,,        CALL    Line1           ; Get ASCII code from table
00000065,2019,,        CALL    Send            ; and do it
00000066,0AA3,,        INCF    Point           ; point to next character
00000067,0823,,        MOVF    Point,W         ; and load the pointer
00000068,3C10,,        SUBLW   D'16'           ; check for last table item
00000069,1D03,,        BTFSS   STATUS,Z        ; and finish if 16 done
0000006A,2863,,        GOTO    Mess1           ; Output character code
,,,
0000006B,30C0,,        MOVLW   0xC0            ; Move cursor to line 2
0000006C,10A4,,        BCF     Select,RS       ; Select command mode
0000006D,2019,,        CALL    Send            ; and send code
0000006E,01A3,,        CLRF    Point           ; Reset table pointer
0000006F,0823,Mess2,Mess2   MOVF    Point,W         ; and load it
00000070,203A,,        CALL    Line2           ; Get fixed character
00000071,14A4,,        BSF     Select,RS       ; Select data mode
00000072,2019,,        CALL    Send            ; and send code
00000073,0AA3,,        INCF    Point           ; next character
00000074,0823,,        MOVF    Point,W         ; Reload pointer
00000075,3C0B,,        SUBLW   D'11'           ; and check for last
00000076,1D03,,        BTFSS   STATUS,Z        ; Skip if last
00000077,286F,,        GOTO    Mess2           ; or send next
00000078,0008,,        RETURN                  ; done
,,,
,,,
,,,; Output variable count to display (0-9) endlessly..........
,,,
00000079,01A2,OutVar,OutVar  CLRF    Var             ; Clear variable number
0000007A,3030,,        MOVLW   0X30            ; Load offset to be added
0000007B,07A2,,        ADDWF   Var             ; to make ASCII code (30-39)
,,,
0000007C,0822,Next,Next    MOVF    Var,W           ; Load the code
0000007D,14A4,,        BSF     Select,RS       ; Select data mode
0000007E,2019,,        CALL    Send            ; and send code
,,,
0000007F,30CB,,        MOVLW   0xCB            ; code to move cursor back
00000080,10A4,,        BCF     Select,RS       ; Select command mode
00000081,2019,,        CALL    Send            ; and send code
00000082,30FA,,        MOVLW   D'250'          ; Load count to wait 250ms
00000083,200F,,        CALL    Xms             ; so numbers are visible
,,,
00000084,0AA2,,        INCF    Var             ; Next number
00000085,0822,,        MOVF    Var,W           ; Load number
00000086,3C3A,,        SUBLW   0x3A            ; Check for last (10=A)
00000087,1D03,,        BTFSS   STATUS,Z        ; and skip if last
00000088,287C,,        GOTO    Next            ; or do next number
00000089,2879,,        GOTO    OutVar          ; Repeat from number Z
,,,
,,,
,,,; MAIN PROGRAM ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
,,,
0000008A,2046,Start,Start   CALL    Init            ; Initialise the display
0000008B,2061,,        CALL    OutMes          ; Display fixed characters
0000008C,2879,,        GOTO    OutVar          ; Display an endless count
,,,
,,,        END                     ; of source code

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -