PIC microcontroller LCD display clock demonstration program

Publisher:恬淡岁月Latest update time:2017-12-07 Source: eefocus Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

include  
;*---- 
; Define  LCD data & control I/O port 
LCD_DATA equ PORTB 
LCD_CNTL1 equ PORTB 
LCD_CNTL2 equ PORTA  
; Define LCD control corresponding I/O pins 


RS equ 1 
E equ 5 

; LCD module command 
DISP_ON EQU 0x00C ; Turn on display 
DISP_ON_C EQU 0x00E ; Turn on display, turn on pointer 
DISP_ON_B EQU 0x00F ; Turn on display, turn on pointer, turn on blinking 
DISP_OFF ​​EQU 0x008 ; Turn off display 
CLR_DISP EQU 0x001 ; Clear the displayed operand 
ENTRY_INC EQU 0x006 ; Operand 
ENTRY_INC_S EQU 0x007 ; Operand 
ENTRY_DEC EQU 0x004 ; Operand 
ENTRY_DEC_S EQU 0x005 ; Operand 
DD_RAM_ADDR EQU 0x080 ; Initialize the first line of the displayed operand 
DD_RAM_UL EQU 0x0c0 ; Initialize the operands displayed on the second line 

; Set the display related registers 
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 
RTCC SIG1 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 ; Perform calibration 
subwf Temp,w ; 
addwf PCL,f ; Add compensation result to 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 $+4 
movf INTSIG,w 
movwf Hour 
goto RtccS1 
clrf INTSIG 
movwf Hour 
goto RtccS1 
;*---- 
SetMins 
movlw 83h 
call Selshow 
movlw d'60' 
subwf INTSIG,W 
btfsc STATUS,C 
goto $+4 
movf INTSIG,w 
movwf Mins 
goto RtccS1 
clrf INTSIG 
movwf Mins 
goto RtccS1 
;*===== 
RtccS2 
bcf STATUS,RP0 
movlw 0c0h 
call SendCmd 
call Alarm 
movlw '1' 
call putcLCD 
movlw ' ' 
call putcLCD 
S2 movlw 80h 
call SendCmd 
call DisplayTime 
call DispTime 
call LongDelay 
bsf PCLATH,0 
movf RTCCSIG1,W 
addwf PCL,1 
goto SetAlH2 
goto SetAlM2 
movf Hour1,w 
movwf ALRH1 
movf Mins1,w 
movwf ALRM1 
clrf INTSIG 
clrf RTCCSIG1 
incf RTCCSIG 
goto main 
;*--- 
SetAlH2 
movlw 0c7h 
call Selshow 
movf INTSIG,W 
btfss STATUS,Z 
bsf ALRSIG,1 
movf INTSIG,W 
movwf Hour1 
movlw d'24' 
subwf Hour1,W 
btfss STATUS,C 
goto S2 
clrf INTSIG 
clrf Hour1 
goto S2 
SetAlM2 
movlw 0cah 
call Selshow 
movf INTSIG,W 
btfss STATUS,Z 
bsf ALRSIG,1 
movf INTSIG,W 
movwf Mins1 
movlw d'60' 
subwf Mins1,W 
btfss STATUS,C 
goto S2 
clrf INTSIG 
clrf Mins1 
goto S2 
;*---- 
Alarm movlw 'A' 
call putcLCD 
movlw 'l' 
call putcLCD 
movlw 'a' 
call putcLCD ; 
movlw 'r' 
call putcLCD 
movlw 'm' 
call putcLCD ; 
return 
;*---- 
Selshow 
call SendCmd 
movlw ' ' 
call putcLCD 
movlw ' ' 
call putcLCD 
call LongDelay 
return 
;*===== 
Rtccs3 
bcf STATUS,RP0 
movlw 0c0h 
call SendCmd 
call Alarm 
movlw '2' 
call putcLCD 
movlw ' ' 
call putcLCD 
S3 movlw 80h 
call SendCmd 
call DisplayTime 
call DispTime 
call LongDelay 
bsf PCLATH,0 
movf RTCCSIG1,w 
addwf PCL,1 
goto SetAlH3 
goto SetAlM3 
movf Hour1,w 
movwf ALRH2 
movf Mins1,w 
movwf ALRM2 
clrf INTSIG 
clrf RTCCSIG1 
incf RTCCSIG 
goto main 
;*--- 
SetAlH3 
movlw 0c7h 
call Selshow 
movf INTSIG,W 
btfss STATUS,Z 
bsf ALRSIG,2 
movf INTSIG,W 
movwf Hour1 
movlw d'24' 
subwf Hour1,W 
btfss STATUS,C 
goto S3 
clrf INTSIG 
clrf Hour1 
goto S3 
SetAlM3 
movlw 0cah 
call Selshow 
movf INTSIG,W 
btfss STATUS,Z 
bsf ALRSIG,1 
movf INTSIG,W 
movwf Mins1 
movlw d'60' 
subwf Mins1,W 
btfss STATUS,C 
goto S3 
clrf INTSIG 
clrf Mins1 
goto S3 
;*===== 
Rtccs4 
movlw 80h 
call SendCmd 
call DisplayTime 
bcf STATUS,RP0 
movlw 0c0h 
call SendCmd 
call Alarm 
movlw '3' 
call putcLCD 
movlw ' ' 
call putcLCD 
S4 call DispTime 
call LongDelay 
bsf PCLATH,0 
movf RTCCSIG1,w 
addwf PCL,1 
goto SetAlH4 
goto SetAlM4 
movf Hour1,w 
movwf ALRH3 
movf Mins1,w 
movwf ALRM3 
clrf INTSIG 
clrf RTCCSIG1 
incf RTCCSIG 
goto main 
;*--- 
SetAlH4 
movlw 0c7h 
call Selshow 
movf INTSIG,W 
btfss STATUS,Z 
bsf ALRSIG,3 
movf INTSIG,W 
movwf Hour1 
movlw d'24' 
subwf Hour1,W 
btfss STATUS,C 
goto S4 
clrf INTSIG 
clrf Hour1 
goto S4 
SetAlM4 
movlw 0cah 
call Selshow 
movf INTSIG,W 
btfss STATUS,Z 
bsf ALRSIG,1 
movf INTSIG,W 
movwf Mins1 
movlw d'60' 
subwf Mins1,W 
btfss STATUS,C 
goto S4 
clrf INTSIG 
clrf Mins1 
goto S4 
;*===== 
ISR 
Push 
movwf _WREG ; 存 WREG状态 
swapf STATUS,W ; 存 STATUS 
movwf _STATUS 
;*---- 
bcf STATUS,RP0 
btfsc PIR1,TMR1IF 
call TimeAdj 
btfsc INTCON,INTF 
call IntDeal 
btfsc INTCON,T0IF 
call RtccDeal 

;*---- 
Pop 
swapf _STATUS,W ; Restore STATUS 
movwf STATUS 
swapf _WREG,F ; Restore WREG w/o 
swapf _WREG,W ; affecting STATUS 
retfie 
;*===== 
TimeAdj 
bcf STATUS,RP0 
bcf PIR1,TMR1IF 
movlw 00h 
movwf TMR1L 
movlw 80h 
movwf TMR1H 
incf Secs,1 
movlw d'60' 
xorwf Secs,W 
btfss STATUS,Z 
goto TE 
clrf Secs 
incf Mins,1 
movlw d'60' 
xorwf Mins,W 
btfss STATUS,Z 
goto TE 
clrf Mins 
incf Hour 
movlw d'24' 
xorwf Hour,W 
btfss STATUS,Z 
goto TE 
clrf Hour 
TE 
return 
;*===== 
IntDeal 
bcf INTCON,INTF 
bsf PORTB,0 
btfsc PORTB,0 ;\ 
goto $+5 ; \ 
call Delay 
bsf PORTB,0 ; 按键去抖动 
btfsc PORTB,0 
goto $+2 ; / 
incf INTSIG 
return 
;*===== 
RtccDeal 
bcf STATUS,RP0 
movlw 0ffh ; 
movwf TMR0 
bcf INTCON,T0IF 
bsf PORTA,4 
btfsc PORTA,4 ;\ 
goto RtcWr ; \ 
call Delay 
bsf PORTA,4 ; 按键去抖动 
btfsc PORTB,4 
goto RtcWr ; / 
movf RTCCSIG,W 
sublw 04h 
btfss STATUS,C 
goto WRONG 
movf RTCCSIG1,W 
sublw 03h 
btfss STATUS,C 
goto WRONG 
movf RTCCSIG,W 
addwf RTCCSIG1,W 
btfsc STATUS,Z 
goto $+3 
incf RTCCSIG1 
goto RtcWr 
incf RTCCSIG 
goto RtcWr 

WRONG 
clrf RTCCSIG 
clrf RTCCSIG1 
RtcWr return 
;*===== 
BkLight 
bsf STATUS,RP0 
bcf ADCON1,ADFM ;ADRESH all 8-bit,H 
bcf STATUS,RP0 
movlw b'01010001' 
movwf ADCON0 ;select AD2,Fosc/8 
decfsz BKM 
goto $-1 
bsf ADCON0,GO 
btfss PIR1,ADIF 
goto $-1 
bcf PIR1,ADIF 
;READ ADRES--- 
movf ADRESH,W 
movwf ADRESB 
bsf STATUS,RP0 
bcf TRISE,0 ;SELECT RE0 OUTPUT 
bcf STATUS,RP0 
movlw b'10000000' ;critICal value of lightness 
subwf ADRESB,W 
btfss STATUS,C 
goto $+4 ;c=0,ADRESBbcf STATUS,RP0 
bsf PORTE,0 ;c=1,backlight on 
goto $+3 
bcf STATUS,RP0 
bcf PORTE,0 
movlw 20h 
movwf BKM 
return 
;*===== 
TempM ;temprature measure 
bsf STATUS,RP0 
bcf ADCON1,ADFM ;ADRESH all 8-bit 
bcf STATUS,RP0 
movlw b'01001001' ;select AD1,FOSC/8 
movwf ADCON0 
decfsz BKM 
goto $-1 
bsf ADCON0,GO 
btfss PIR1,ADIF 
goto $-1 
bcf PIR1,ADIF 
;bsf STATUS,RP0 
movf ADRESH,W 
;bcf STATUS,RP0 
movwf Temp 
call CalTable 
movwf Temp 
call Bin2BCDT ; 进行BCD码调整 
movlw 08ah ; 从第一行的第0A个位置开始 
call SendCmd 
movf TempH,W ; 显示温度 
call putcLCD 
movf TempL,W 
call putcLCD 
movlw 'C' ; 显示“C”(表示摄氏度) 
call putcLCD 
movlw 20h 
movwf BKM 
return 
;************************************************ 
;* Bin2BCDT - 将 Temp 寄存器内的二进制数转 * 
;* 换为相应的 ASCII 码并存为 TempH:TempL 的形式 * 
;************************************************ 
Bin2BCDT 
bcf STATUS,RP0 
clrf TempH ; Initialize variables 
movf Temp,W 
movwf TempL 
Ttenth ; Subtract 10 from low variable 
movlw .10 ; until result is < 0. On each 
subwf TempL,W ; subtraction, increment the 
btfss STATUS,C ; temperature high byte. 
goto Over0 
movwf TempL 
incf TempH,F 
goto Ttenth 
Over0 
movlw 0x30 ; Make decimal ASCII by adding 
addwf TempH,F ; '0' to high and low byte 
addwf TempL,F 
return 
;**************************************************** 
;* DisplayTime - Move the display pointer to the first line, call Bin2BCD* 
;* The subroutine converts the data in the Secs and Mins registers into the corresponding * 
;* ASCII code, and then sends it to the LCD for display. * 
;**************************************************** 
DisplayTime 
bcf STATUS,RP0 
call Bin2BCD ; Call the subroutine for binary and BCD code conversion 
movf HourH,W ; Display the high byte of hour 
call putcLCD ; 
movf HourL,W ; Display the low byte of hour 
call putcLCD ; 
movlw ':' 
call putcLCD ; Display ':' 
movf MinsH,W ; Display the high byte of minute 
call putcLCD ; 
movf MinsL,W ; Display minute low digit 
call putcLCD ; 
movlw ':' ; Display ':' 
call putcLCD 
movf SecsH,W ; Display second high digit 
call putcLCD ; 
movf SecsL,W ; Display second low digit 
call putcLCD ; 
return 
;**************************************************** 
;* Bin2BCD - Convert the binary numbers in Secs & Mins registers 
to the corresponding ASCII codes and store them in 
the form of SecsH:SecsL and * ;* MinsH:MinsL,HourH:HourL. * 
;************************************************ 
Bin2BCD 
bcf STATUS,RP0 
clrf HourH ; Initialize variable 
movf Hour,W ; Convert "hour" 
movwf HourL 
Hourth ; Loop to subtract 10 
movlw .10 from low byte and 
subwf HourL,W ,W ; increment high byte  btfss  STATUS 
,C ; while low byte is > 0 
goto  Next1 
movwf  MinsL  incf MinsH,F 
goto 
Mtenth  Next1 
clrf 
SecsH ; Initialize variable  movf  Secs  ,W ; Convert "seconds" 
movwf 
SecsL  Stenth  ; Loop to subtract 10 
movlw 
.10  ; from low byte and  subwf SecsL,W ; increment high byte  btfss STATUS,C ; while low byte is > 0  goto Over  movwf SecsL  incf SecsH,F  goto Stenth  Over  movlw 0x30 ;  addwf HourH,F ;  addwf HourL,F ; Add 0x30 ('0') to all  addwf MinsH,F ; variables to convert  addwf MinsL,F ; a number 0 - 9 to an  addwf SecsH,F ; ASCII equivalent  addwf SecsL,F ; '0' to '9'  return  ;*====  DispTime  bcf STATUS,RP0 






























movlw 0c7h 
call SendCmd 
call Bin2BCa ; call binary to BCD code conversion subroutine 
movf HourH1,W ; display hour high byte 
call putcLCD ; 
movf HourL1,W ; display hour low byte 
call putcLCD ; 
movlw ':' ; display ':' 
call putcLCD 
movf MinsH1,W ; display minute high byte 
call putcLCD ; 
movf MinsL1,W ; display minute low byte 
call putcLCD ; 
return 
;*---- 
Bin2BCa 
bcf STATUS,RP0 
clrf HourH1 ; initialize variable 
movf Hour1,W ; convert "hour" 
movwf HourL1 
Hourth1 ; Loop to subtract 10 
movlw .10 ; from low byte and 
subwf HourL1,W ; increment high byte 
btfss STATUS,C ; while low byte is > 0 
goto Nexta 
movwf HourL1 
incf HourH1,F 
goto Hourth1 
Nexta 
clrf MinsH1 ; Initialize variable 
movf Mins1,W ; Convert "minute" 
movwf MinsL1 
Mtenth1 ; Loop to subtract 10 
movlw .10 ; from low byte and 
subwf MinsL1,W ; increment high byte 
btfss STATUS,C ; while low byte is > 0 
goto Over1 
movwf MinsL1 
incf MinsH1,F 
goto Mtenth1 
Over1 
movlw 0x30 ; 
addwf HourH1,F ; 
addwf HourL1,F ; Add 0x30 ('0') to all 
addwf MinsH1,F ; variables to convert 
addwf MinsL1,F ; a number 0 - 9 to an 
return ; ASCII equivalent 
;******************************************************************* 
;* LCD module subroutine * 
;*************************************************************** 
;InitLCD——Initialize LCD module * 
;*************************************************************** 
InitLCD 
bcf STATUS,RP0 ; Bank 0 
bcf STATUS,RP1 
clrf LCD_DATA ; Clear LCD data & control bits 
bsf STATUS,RP0 ; Bank 1 
movlw 0xc1 ; Set RB1~RB5 as output 
movwf LCD_DATA 
bcf TR ISA ,5 

bcf STATUS,RP0 ; 
movlw 0x00 ; 
movwf LCD_DATA 
bsf LCD_CNTL2, E 
bcf LCD_CNTL2, E 

movlw 0x08 ; 
movwf LCD_DATA 
bsf LCD_CNTL2, E 
bcf LCD_CNTL2, E 
call LongDelay 
call LongDelay 

movlw b'00101000' 
call SendCmd 
movlw DISP_ON ; turn on display 
call SendCmd 
movlw ENTRY_INC ; set pointer movement mode 
call SendCmd 
movlw DD_RAM_ADDR ; set starting address 
call SendCmd 

InitLCDEnd ; 
bcf STATUS,RP0 ; 
movlw CLR_DISP ; 
call SendCmd 
return 

;******************************************************************* 
;*putcLCD—— send character data to LCD * 
;* This program divides the character data into high nibble and low nibble and inputs them separately * 
;* The high nibble is input first * 
;*************************************************************** 
putcLCD 
bcf STATUS,RP0 
movwf Byte ; Store WREG to Byte register 
swapf Byte,W ; Write high nibble 
movwf LCD_DATA1 
rlf LCD_DATA1,1 
rlf LCD_DATA1,1 
movlw 0x3c 
andwf LCD_DATA1,1 
movf LCD_DATA1,w 
movwf LCD_DATA 
bsf LCD_CNTL1, RS ; Set to data sending mode 
bsf LCD_CNTL2, E ; Send data signal 
bcf LCD_CNTL2, E 

movf Byte,W ; Then send low nibble 
movwf LCD_DATA1 
rlf LCD_DATA1,1 
rlf LCD_DATA1,1 
movlw 0x3c 
andwf LCD_DATA1,1 
movf LCD_DATA1,w 
movwf LCD_DATA 
bsf LCD_CNTL1, RS ; Set to data sending mode 
bsf LCD_CNTL2, E ; Send data signal 
bcf LCD_CNTL2, E 
call Delay 
return 

;*************************************************************** 
;* SendCmd - send command to LCD * 
;* This program divides the command data into high nibble and low nibble and inputs them separately * 
;* The high nibble is sent first * 
;******************************************************************* 
SendCmd 
bcf STATUS,RP0 
movwf Byte ; Store WREG to Byte register 
swapf Byte,W ; Send high byte of command 
movwf LCD_DATA1 
rlf LCD_DATA1,1 
rlf LCD_DATA1,1 
movlw 0x3c 
andwf LCD_DATA1,1 
movf ; Set to send command mode  bcf LCD_CNTL2,E ; Send data signal  bcf LCD_CNTL2,E  movf Byte,W ; Then send the low byte of the command  movwf LCD_DATA1  rlf LCD_DATA1,1  rlf LCD_DATA1,1  movlw 0x3c  andwf LCD_DATA1,1  movf LCD_DATA1,w  movwf  LCD_DATA 
bcf  LCD_CNTL1,RS ; Set to send command mode  bcf LCD_CNTL2,E ; Send data signal  bcf LCD_CNTL2,E  call Delay  return  ;***********************************************************************  ;* Delay - Delay subroutine *  ;*******************************************************************  Delay ; The call instruction takes up 2 instruction cycles bcf STATUS,RP0  clrf Count ; Clear Count takes 1 instruction cycle  Dloop  decfsz Count,f ; These  two lines of instructions will delay goto Dloop ; (256 * 3) -1 instruction cycle  return ; return takes 2 instruction cycles  ;*******************************************************************  ;* LongDelay - Long delay subroutine *  ;*******************************************************************  LongDelay  bcf STATUS,RP0  clrf Count  clrf Count1  movlw 0x03  movwf Count2  LDloop  decfsz Count,f  goto LDloop  decfsz Count1,f 




















 




















goto LDloop 
decfsz Count2,f 
goto LDloop 
return 
;*------ 
END


Reference address:PIC microcontroller LCD display clock demonstration program

Previous article:Realizing High-precision Digital Watt-hour Meter Using PIC16C73
Next article:PIC16F877A+18B10 temperature measurement+LCD1602 temperature display

Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号