include <p16f877.inc> ;*---- ; 定義 LCD數(shù)據(jù)& 控制I/O口 LCD_DATA equ PORTB LCD_CNTL1 equ PORTB LCD_CNTL2 equ PORTA ; 定義 LCD控制相應(yīng)的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 ; 關(guān)顯示 CLR_DISP EQU 0x001 ; 清顯示的操作數(shù) ENTRY_INC EQU 0x006 ; 操作數(shù) ENTRY_INC_S EQU 0x007 ; 操作數(shù) ENTRY_DEC EQU 0x004 ; 操作數(shù) ENTRY_DEC_S EQU 0x005 ; 操作數(shù) DD_RAM_ADDR EQU 0x080 ; 初始化第一行顯示的操作數(shù) DD_RAM_UL EQU 0x0c0 ; 初始化第二行顯示的操作數(shù)
; 設(shè)置顯示相關(guān)寄存器 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 ; 將補償結(jié)果與 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狀態(tài) 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,ADRESB<critical bcf 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碼調(diào)整 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 寄存器內(nèi)的二進制數(shù)轉(zhuǎn) * ;* 換為相應(yīng)的 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 - 將顯示指針移至第一行,調(diào)用Bin2BCD* ;* 子程序?qū)ecs 和 Mins寄存器內(nèi)的數(shù)據(jù)轉(zhuǎn)換為相應(yīng)的* ;* ASCII 碼, 然后送 LCD顯示. * ;************************************************* DisplayTime bcf STATUS,RP0 call Bin2BCD ; 調(diào)用二進制與bcd碼轉(zhuǎn)換子程序 MOVf HourH,W ; 顯示小時高位 call putcLCD ; MOVf HourL,W ; 顯示小時低位 call putcLCD ; MOVlw ':' call putcLCD ; 顯示 ':' MOVf MinsH,W ; 顯示分鐘高位 call putcLCD ; MOVf MinsL,W ; 顯示分鐘低位 call putcLCD ; MOVlw ':' ; 顯示 ':' call putcLCD MOVf SecsH,W ; 顯示秒鐘高位 call putcLCD ; MOVf SecsL,W ; 顯示秒鐘低位 call putcLCD ; return ;************************************************ ;* Bin2BCD - 將 Secs & Mins 寄存器內(nèi)的二進制數(shù)轉(zhuǎn)* ;* 換為相應(yīng)的 ASCII 碼并存為 SecsH:SecsL 及 * ;* MinsH:MinsL,HourH:HourL的形式. * ;************************************************ Bin2BCD bcf STATUS,RP0 clrf HourH ; 初始化變量 MOVf Hour,W ; 轉(zhuǎn)換“時” MOVwf HourL Hourth ; Loop to subtract 10 MOVlw .10 ; from low byte and subwf HourL,W ; increment high byte btfss STATUS,C ; while low byte is > 0 goto Next MOVwf HourL incf HourH,F goto Hourth Next clrf MinsH ; 初始化變量 MOVf Mins,W ; 轉(zhuǎn)換“分” MOVwf MinsL Mtenth ; Loop to subtract 10 MOVlw .10 ; from low byte and subwf MinsL,W ; increment high byte btfss STATUS,C ; while low byte is > 0 goto Next1 MOVwf MinsL incf MinsH,F goto Mtenth Next1 clrf SecsH ; 初始化變量 MOVf Secs,W ; 轉(zhuǎn)換“秒” 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 ; 調(diào)用二進制與bcd碼轉(zhuǎn)換子程序 MOVf HourH1,W ; 顯示小時高位 call putcLCD ; MOVf HourL1,W ; 顯示小時低位 call putcLCD ; MOVlw ':' ; 顯示 ':' call putcLCD MOVf MinsH1,W ; 顯示分鐘高位 call putcLCD ; MOVf MinsL1,W ; 顯示分鐘低位 call putcLCD ; return ;*---- Bin2BCa bcf STATUS,RP0 clrf HourH1 ; 初始化變量 MOVf Hour1,W ; 轉(zhuǎn)換“時” 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 ; 初始化變量 MOVf Mins1,W ; 轉(zhuǎn)換“分” 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 模塊子程序 * ;******************************************************************* ;InitLCD——初始化LCD模塊 * ;******************************************************************* InitLCD bcf STATUS,RP0 ; Bank 0 bcf STATUS,RP1 clrf LCD_DATA ; 清 LCD 數(shù)據(jù) & 控制位 bsf STATUS,RP0 ; Bank 1 MOVlw 0xc1 ; 設(shè)置RB1~RB5為輸出 MOVwf LCD_DATA bcf TRISA,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 ; 開顯示 call SendCmd MOVlw ENTRY_INC ; 設(shè)置指針移動方式 call SendCmd MOVlw DD_RAM_ADDR ; 設(shè)置起始地址 call SendCmd
InitLCDEnd ; bcf STATUS,RP0 ; MOVlw CLR_DISP ; call SendCmd return
;******************************************************************* ;*putcLCD—— 將字符數(shù)據(jù)送入 LCD * ;* 本程序?qū)⒆址麛?shù)據(jù)分成了高半字節(jié)和低半字節(jié)分別輸入 * ;* 先送入的是高半字節(jié) * ;******************************************************************* putcLCD bcf STATUS,RP0 MOVwf Byte ; 存 WREG 到 Byte 寄存器 swapf Byte,W ; 寫入高半字節(jié) 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 ; 設(shè)置為送數(shù)據(jù)模式 bsf LCD_CNTL2, E ; 發(fā)送數(shù)據(jù)信號 bcf LCD_CNTL2, E
MOVf Byte,W ; 接著送低半字節(jié) 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 ; 設(shè)置為送數(shù)據(jù)模式 bsf LCD_CNTL2, E ; 發(fā)送數(shù)據(jù)信號 bcf LCD_CNTL2, E call Delay return
;******************************************************************* ;* SendCmd - 送命令到 LCD * ;* 本程序?qū)⒚顢?shù)據(jù)分成了高半字節(jié)和低半字節(jié)分別輸入 * ;* 先送入的是高半字節(jié) * ;******************************************************************* SendCmd bcf STATUS,RP0 MOVwf Byte ; 存 WREG 到 Byte 寄存器 swapf Byte,W ; 送入命令的高字節(jié) 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 ; 設(shè)置為送命令模式 bsf LCD_CNTL2,E ; 發(fā)送數(shù)據(jù)信號 bcf LCD_CNTL2,E MOVf Byte,W ; 接著送命令的低字節(jié)
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 ; 設(shè)置為送命令模式 bsf LCD_CNTL2,E ; 發(fā)送數(shù)據(jù)信號 bcf LCD_CNTL2,E call Delay return ;******************************************************************* ;* Delay - 延時子程序 * ;******************************************************************* Delay ; call指令占用2個指令周期 bcf STATUS,RP0 clrf Count ; 清 Count占用1個指令周期 Dloop decfsz Count,f ; 這兩行指令將延時 goto Dloop ; (256 * 3) -1 個指令周期 return ; return占用2個指令周期
;******************************************************************* ;* LongDelay - 長延時子程序 * ;******************************************************************* 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 |
|