單片機方案開發商深圳英銳恩分享PIC單片機lcd顯示時鐘演示程序。
include
;*----
; 定義 LCD數據& 控制I/O口
LCD_DATA equ PORTB
LCD_CNTL1 equ PORTB
LCD_CNTL2 equ PORTA
; 定義 LCD控制相應的I/O引腳
RS equ 1
E equ 5
; LCD 模塊命令
DISP_ON EQU 0x00C ; 開顯示
DISP_ON_C EQU 0x00E ; 開顯示, 開指針
DISP_ON_B EQU 0x00F ; 開顯示, 開指針,開閃爍
DISP_OFF EQU 0x008 ; 關顯示
CLR_DISP EQU 0x001 ; 清顯示的操作數
ENTRY_INC EQU 0x006 ; 操作數
ENTRY_INC_S EQU 0x007 ; 操作數
ENTRY_DEC EQU 0x004 ; 操作數
ENTRY_DEC_S EQU 0x005 ; 操作數
DD_RAM_ADDR EQU 0x080 ; 初始化第一行顯示的操作數
DD_RAM_UL EQU 0x0c0 ; 初始化第二行顯示的操作數
; 設置顯示相關寄存器
Byte EQU 20H
Count EQU 21H
Count1 EQU 22H
Count2 EQU 23H
LCD_DATA1 EQU 24H
PORTDB EQU 25H
Temp EQU 26H
TempH EQU 27H
TempL EQU 28H
INTSIG EQU 29H
RTCCSIG1 EQU 2AH
RTCCSIG EQU 2BH
ALRSIG EQU 2CH
Hour EQU 2DH
HourH EQU 2EH
HourL EQU 2FH
HourL1 EQU 30H
HourH1 EQU 31H
Mins EQU 32H
Mins1 EQU 33H
MinsH EQU 34H
MinsL EQU 35H
MinsH1 EQU 36H
MinsL1 EQU 37H
Secs EQU 38H
SecsH EQU 39H
SecsL EQU 3AH
ALRH1 EQU 3BH
ALRM1 EQU 3CH
ALRH2 EQU 3DH
ALRM2 EQU 3EH
ALRH3 EQU 3FH
ALRM3 EQU 40H
_WREG EQU 41H
_STATUS EQU 42H
Hour1 EQU 43H
ADRESB EQU 44H
BKM EQU 45H
;*----
org 0
nop
goto start
org 4
goto ISR
org 10
CalTable
bcf STATUS,RP0
bcf PCLATH,0
movlw 0x66 ; 進行校準處理
subwf Temp,w ;
addwf PCL,f ; 將補償結果與 PCL相加
dt 0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5
dt 6,6,6,7,7,7,8,8,8,9,9,0xa,0xa,0xb,0xb,0xc,0xc
dt 0xd,0xd,0xe,0xe,0xf,0xf,0xf,0x10,0x10,0x10
dt 0x11,0x11,0x12,0x12,0x12,0x13,0x13,0x14,0x14,0x14
dt 0x15,0x15,0x15,0x16,0x16,0x16,0x17,0x17,0x18,0x18
dt 0x19,0x19,0x1a,0x1a,0x1b,0x1b,0x1c,0x1c,0x1c
dt 0x1d,0x1d,0x1d,0x1e,0x1e,0x1f,0x1f,0x20,0x20
dt 0x21,0x21,0x22,0x22,0x23,0x23,0x24,0x24,0x25,0x25
dt 0x26,0x26,0x27,0x28,0x29,0x29,0x2a,0x2a,0x2b,0x2b
dt 0x2c,0x2d,0x2e,0x2f,0x30,0x32
start
call InitLCD
clrf RTCCSIG
clrf RTCCSIG1
clrf INTSIG
clrf Hour
clrf Hour1
clrf Mins
clrf Mins1
clrf Secs
clrf ALRSIG
movlw 20h
movwf BKM
movlw b'10001111'
movwf PORTDB
movlw 0ffh
movwf TMR0
movlw 00
movwf TMR1L
movlw 80h
movwf TMR1H
movlw b'00001111'
movwf T1CON
bsf STATUS,RP0
bsf PIE1,TMR1IE
bcf STATUS,RP0
movlw b'10111111'
OPTION
movlw b'11110000'
movwf INTCON
main
movlw 80h
call SendCmd
call DisplayTime ;顯示時間
movlw 0c0h
call SendCmd
movlw 'H'
call putcLCD
movlw 'e'
call putcLCD
movlw 'l'
call putcLCD
movlw 'l'
call putcLCD
movlw 'o'
call putcLCD
movlw ' '
call putcLCD
movlw '!'
call putcLCD
movlw ' '
call putcLCD
movlw ':'
call putcLCD
movlw ')'
call putcLCD
movlw ' '
call putcLCD
movlw ' '
call putcLCD
call BkLight ;背光控制
call TempM ;顯示溫度
btfsc ALRSIG,1
call ALR1
btfsc ALRSIG,2
call ALR2
btfsc ALRSIG,3
call ALR3
bcf STATUS,RP0
bcf PCLATH,0
movf RTCCSIG,W
addwf PCL,1
goto main
goto RtccS1
goto RtccS2
goto Rtccs3
goto Rtccs4
clrf RTCCSIG
clrf RTCCSIG1
goto main
;*=====
ALR1 bcf STATUS,RP0
movf Hour,W
xorwf ALRH1,W
btfss STATUS,Z
goto ALREND
movf Mins,W
xorwf ALRM1,W
btfss STATUS,Z
goto ALREND
bsf STATUS,RP0
clrf TRISD
bcf STATUS,RP0
bcf STATUS,C
rlf PORTDB,1
btfsc STATUS,C
bsf PORTDB,0
movf PORTDB,W
movwf PORTD
return
;*---
ALR2 bcf STATUS,RP0
movf Hour,W
xorwf ALRH2,W
btfss STATUS,Z
goto ALREND
movf Mins,W
xorwf ALRM2,W
btfss STATUS,Z
goto ALREND
bsf STATUS,RP0
clrf TRISD
bcf STATUS,RP0
bcf STATUS,C
rlf PORTDB,1
btfsc STATUS,C
bsf PORTDB,0
movf PORTDB,W
movwf PORTD
return
;*----
ALR3 bcf STATUS,RP0
movf Hour,W
xorwf ALRH3,W
btfss STATUS,Z
goto ALREND
movf Mins,W
xorwf ALRM3,W
btfss STATUS,Z
goto ALREND
bsf STATUS,RP0
clrf TRISD
bcf STATUS,RP0
bcf STATUS,C
rlf PORTDB,1
btfsc STATUS,C
bsf PORTDB,0
movf PORTDB,W
movwf PORTD
return
;*---
ALREND
bsf STATUS,RP0
movlw 0ffh
movwf TRISD
return
;*=====
RtccS1
movlw 80h
call SendCmd
call DisplayTime
call LongDelay
movlw 0c0h
call SendCmd ;line2, 00
movlw 'S'
call putcLCD
movlw 'e'
call putcLCD
movlw 't'
call putcLCD
movlw ' '
call putcLCD
movlw 'T'
call putcLCD
movlw 'i'
call putcLCD
movlw 'm'
call putcLCD
movlw 'e'
call putcLCD ;show "Set Time"
movlw ' '
call putcLCD
movlw ' '
call putcLCD
movlw ' '
call putcLCD
movlw ' '
call putcLCD
bsf PCLATH,0
movf RTCCSIG1,W
addwf PCL,1
goto SetHour
goto SetMins
clrf INTSIG
incf RTCCSIG
clrf RTCCSIG1
goto main
;*----
SetHour
movlw 80h
call Selshow
movlw d'24'
subwf INTSIG,W
btfsc STATUS,C
goto