定義用戶寄存器
WEI1EQUH’0C’;BIT0=MODS:選擇模式位0:模式11:模式2
;BIT1=BREK:斷路判別位0:無(wú)斷路1:有斷路
;BIT2=
;BIT3=
;BIT4=
;BIT5=慢響
;BIT6=快響
;BIT7=長(zhǎng)響
WEI2EQUH’0D’;“百位值運(yùn)算”的啟始值
?
WEI3EQUH’0E’;“十位值運(yùn)算”的啟始值
WEI4EQUH’0F’;個(gè)位值
WEI5EQUH’10’;百位值
WEI6EQUH’11’;十位值
WEI7EQUH’12’;
WEI8EQUH’13’;
WEI9EQUH’14’;
WEIAEQUH’15’;
WEIBEQUH’16’
WEICEQUH’17’
WEIDEQUH’18’
WEIEEQUH’19’
WEIFEQUH’1A’
WEIGEQUH’1B’
WEIHEQUH’1C’
WEIIEQUH’1D’
CHECKEQUH’7’
DPEQUH’1’
ADEQUH’0’
BUZZEREQUH’3’
REQUH’2’
LEQUH’4’
;************************************************************************
;矢量地址
ORGH’00’;復(fù)位矢量
GOTOMAIN
ORGH’04’;中斷矢量
NOP
GOTOINTER
;************************************************************************
;數(shù)碼值
TABLE:
ADDWFPCL,F(xiàn);
RETLWB’01000000’;“0”值
RETLWB’01111001’;“1”值
RETLWB’00100100’;“2”值
RETLWB’00110000’;“3”值
RETLWB’00011001’;“4”值
RETLWB’00010010’;“5”值
RETLWB’00000010’;“6”值
RETLWB’01011000’;“7”值
RETLWB’00000000’;“8”值
RETLWB’00010000’;“9”值
;------------------------------------------------------------------------
;清除寄存器WEI1-WEIG
MAIN:
CLRFWEI1;
CLRFWEI2;
CLRFWEI3;
CLRFWEI4;
CLRFWEI5;
CLRFWEI6;
CLRFWEI7;
CLRFWEI8;
CLRFWEI9;
CLRFWEIA;
CLRFWEIB;
CLRFWEIC;
CLRFWEID;
CLRFWEIE;
CLRFWEIF;
CLRFWEIG;
CLRFWEIH;
CLRFWEII;
BSFSTATUS,RP0;
BCFOPTION_REG,NOT_RBPU
BCFSTATUS,RP0;
MOV FPORTB,1;
BTFSSPORTB,1;
BSFWEI1,0;
;------------------------------------------------------------------------
;設(shè)置A/D通道及A/D結(jié)構(gòu)
BSFSTATUS,RP0;
MOV LWB’00000010’;設(shè)置一個(gè)“A/D口”
MOV WFADCON1;參考電壓:工作電壓5V
MOV LWB’10000000’;
MOV WFTRISB;
MOV LWB’00000001’;
MOV WFTRISA;
MOV LWB’10000111’;
MOV WFOPTION_REG;
MOV LWB’10100000’;
MOV WFINTCON;
;-----------------------------------------------------------------------
;設(shè)置端口“輸入/輸出”并設(shè)置初始狀態(tài)
BCFSTATUS,RP0;
MOV LWB’01000000’;設(shè)置A/D通道:AN0
MOV WFADCON0;選用內(nèi)部1:8時(shí)鐘振蕩
MOV LWB’01111111’;
MOV WFPORTB;
MOV LWB’00010110’;
MOV WFPORTA;
MOV LWD’252’;
MOV WFTMR0;設(shè)置TMR0初始值
;------------------------------------------------------------------------
;選擇模式
BTFSCWEI1,0;判斷“模式開(kāi)關(guān)”是否閉合
GOTOMODLE2;“模式開(kāi)關(guān)”閉合,則進(jìn)入“模式2”
GOTOMODLE1;“模式開(kāi)關(guān)”斷開(kāi),則進(jìn)入“模式1”
;------------------------------------------------------------------------
;“模式1”初始化
MODLE1:
MOV FPORTB,1;
BTFSSPORTB,CHECK;判斷是否有斷路
GOTO$+7;
BSFWEI1,1;
BSFWEI1,6;有斷路:蜂鳴器快響并且“無(wú)顯示”延時(shí)3秒
BCFWEI1,5;
BCFWEI1,7;
CALLDELAY3S;無(wú)斷路:“無(wú)顯示”延時(shí)3秒
GOTOSTART;
CALLDELAY3S;
GOTOSTART;
;------------------------------------------------------------------------
;“模式2”初始化檢測(cè)數(shù)碼管各段,蜂鳴器“長(zhǎng)響”
MODLE2:
BSFWEI1,0;設(shè)置“模式選擇位”
BSFWEI1,7;打開(kāi)蜂鳴器“長(zhǎng)響”
BCFWEI1,5;
BCFWEI1,6;
BCFSTATUS,C;設(shè)置“進(jìn)位標(biāo)志位”
MOV LWB’11111111’;
MOV WFWEI7;
RLFWEI7,F(xiàn);
MOV FWEI7,W;
MOV WFPORTB;設(shè)置“檢測(cè)數(shù)碼管段值”給PORT5
BCFPORTA,R;開(kāi)通“右數(shù)碼管”
BCFPORTA,L;開(kāi)通“左數(shù)碼管”
CALLDELAYP5;
BSFPORTA,R;關(guān)閉“右數(shù)碼管”
BSFPORTA,L;關(guān)閉“左數(shù)碼管”
MOV LWB’11111111’;
MOV WFPORTB;清除給PORT5的“檢測(cè)數(shù)碼管段值”
BTFSCWEI7,6;檢測(cè)是否完畢
GOTO$-D’11’;沒(méi)有完畢繼續(xù)檢測(cè)
BCFPORTA,DP;已完畢設(shè)置“小數(shù)點(diǎn)”及“1”值
BCFPORTA,R;開(kāi)通“右數(shù)碼管”
BCFPORTA,L;開(kāi)通“左數(shù)碼管”
CALLDELAYP5;
BSFPORTA,R;關(guān)閉“右數(shù)碼管”
BSFPORTA,L;關(guān)閉“左數(shù)碼管”
BSFPORTA,DP;清除“小數(shù)點(diǎn)”及“1”值
BCFWEI1,7;關(guān)閉蜂鳴器“長(zhǎng)響”
BCFWEI1,6;
BCFWEI1,5;
GOTOSTART;
;------------------------------------------------------------------------
;開(kāi)始工作
START:
MOV FPORTB,F(xiàn);
BTFSCPORTB,CHECK;判斷是否有斷路
GOTODUANLU;有斷路
BCFWEI1,1;清0斷路判別位
GOTOPANZHI;無(wú)斷路
;------------------------------------------------------------------------
;斷路處理
DUANLU:
BSFWEI1,1;設(shè)置斷路判別位
BSFWEI1,6;
BCFWEI1,5;
BCFWEI1,7;
GOTOPANZHI;
;------------------------------------------------------------------------
;判斷電壓值
PANZHI:
BSFADCON0,ADON;A/D處于工作狀態(tài)
BSFADCON0,GO_DONE;A/D開(kāi)始運(yùn)行
BTFSCADCON0,GO_DONE;判A/D是否完成
GOTO$-1;A/D沒(méi)完成
BCFADCON0,ADIF;
BCFADCON0,ADON;A/D已完成關(guān)閉A/D
CALLCV;
MOV FADRES,W;
MOV WFWEI8;
MOV WFWEI2;A/D值傳給WEI2
BCFSTATUS,C;清零“進(jìn)位標(biāo)志位”
SUBLWD’200’;
BTFSSSTATUS,C
GOTOV_20;跳到“20V以上”程序
MOV FADRES,W
BCFSTATUS,C;清零“進(jìn)位標(biāo)志位”
SUBLWD’160’
BTFSSSTATUS,C
GOTOV16;跳到“16V-19.9V之間”程序
MOV FADRES,W
BCFSTATUS,C;清零“進(jìn)位標(biāo)志位”
SUBLWD’100’
BTFSSSTATUS,C
GOTOV10;跳到“10V-15.9V之間”程序
MOV FADRES,W
BCFSTATUS,C;清零“進(jìn)位標(biāo)志位”
SUBLWD’50’
BTFSSSTATUS,C
GOTOV5;跳到“5V-9.9V之間”程序
GOTOV4.9;跳到4.9V以下程序
;-------------------------------------------------------------------------
V4.9:;4.9V以下數(shù)碼管顯示LL
BTFSCWEI1,1;判斷是否有斷路
GOTO$+6;
BSFWEI1,7;無(wú)斷路長(zhǎng)響
BCFWEI1,6;
BCFWEI1,5;
CALLLL;
GOTOSTART;
BSFWEI1,6;有斷路快響
BCFWEI1,5;
BCFWEI1,7;
CALLLL;
GOTOSTART;
;-------------------------------------------------------------------------
V5:;5V-9.9V之間
BTFSCWEI1,1;判斷是否有斷路
GOTO$+5;
BSFWEI1,5;無(wú)斷路慢響
BCFWEI1,6;
BCFWEI1,7;
GOTODISPLAY;
BSFWEI1,6;有斷路快響
BCFWEI1,5;
BCFWEI1,7;
GOTODISPLAY;
;-------------------------------------------------------------------------
V10:;10V-15.9V之間
BTFSCWEI1,1;判斷是否有斷路
GOTO$+5;
BCFWEI1,5;無(wú)斷路不響
BCFWEI1,6;
BCFWEI1,7;
GOTODISPLAY;
BSFWEI1,6;有斷路快響
BCFWEI1,5;
BCFWEI1,7;
GOTODISPLAY;
;-------------------------------------------------------------------------
V16:;16V-19.9V
BSFWEI1,6;快響
BCFWEI1,5;
BCFWEI1,7;
GOTODISPLAY;
;-------------------------------------------------------------------------
V_20:
BTFSCWEI1,1;判斷是否有斷路
GOTO$+6;
BSFWEI1,7;無(wú)斷路長(zhǎng)響
BCFWEI1,6;
BCFWEI1,5;
CALLHH;
GOTOSTART;
BSFWEI1,6;有斷路快響
BCFWEI1,5;
BCFWEI1,7;
CALLHH;
GOTOSTART;
;-------------------------------------------------------------------------
;運(yùn)算“顯示值”
DISPLAY:
NOP;
HUN:
MOV FWEI2,W;
MOV WFWEI3;WEI2-100D的余值傳給WEI3作為“十位值運(yùn)算”的啟始值
MOV LWD’100’
BCFSTATUS,C;清零“進(jìn)位標(biāo)志位”
SUBWFWEI2,F(xiàn);WEI2-100D余值傳給WEI2
BTFSSSTATUS,C;判WEI2是否大于100D
GOTOTEN;小于100D跳到“十位值運(yùn)算”處
INCFWEI5,F(xiàn);大于100DWEI5+1:百位值
GOTOHUN
TEN:
MOV FWEI3,W;
MOV WFWEI4;
MOV LWD’10’;WEI3-10D的余值傳給WEI4作為“個(gè)位值運(yùn)算”的啟始值
BCFSTATUS,C;清零“進(jìn)位標(biāo)志位”
SUBWFWEI3,F(xiàn);WEI3-10D余值傳給WEI3
BTFSSSTATUS,C;判WEI2是否大于10D
GOTONUMB;小于10D跳到“個(gè)位值運(yùn)算”處
INCFWEI6,F(xiàn);大于10DWEI6+1:十位值
GOTOTEN
;------------------------------------------------------------------------
;顯示“十位值”“小數(shù)點(diǎn)”
NUMB:
MOV FWEI6,W
CALLTABLE;
MOV WFPORTB;設(shè)置“十位值”
BCFPORTA,DP;設(shè)置小數(shù)點(diǎn)
BCFPORTA,L;打開(kāi)顯示“十位值”
CALLDELAY;
MOV LWB’11111111’;
MOV WFPORTB;清除“十位值”
BSFPORTA,DP;清除小數(shù)點(diǎn)
BSFPORTA,L;關(guān)閉顯示“十位值”
;------------------------------------------------------------------------
;顯示“個(gè)位值”“百位值”
MOV FWEI4,W
CALLTABLE
MOV WFPORTB;設(shè)置“個(gè)位值”
BCFSTATUS,Z;清除“零標(biāo)志位”
CLRW;清除W
IORWFWEI5,W;
BTFSSSTATUS,Z;判有無(wú)“百位值”
BCFPORTA,DP;顯示“百位值”
BCFPORTA,R;打開(kāi)顯示“個(gè)位值”
CALLDELAY;
MOV LWB’11111111’;
MOV WFPORTB;清除“個(gè)位值”
BSFPORTA,DP;清除“百位值”
BSFPORTA,R;關(guān)閉顯示“個(gè)位值”
CLRFWEI6;
CLRFWEI5;
GOTOSTART;
;************************************************************************
;延時(shí)20MS秒程序
DELAY:
MOV LWD’10’;
MOV WFWEIE;
DELAY1:
MOV LWD’10’;
MOV WFWEIF;
DELAY2:
MOV LWD’10’;
MOV WFWEIG;
DELAY3:
DECFSZWEIG,F(xiàn);
GOTODELAY3;
DECFSZWEIF,F(xiàn);
GOTODELAY2;
DECFSZWEIE,F(xiàn);
GOTODELAY1;
RETURN;
;------------------------------------------------------------------------
;延時(shí)0.5秒程序
DELAYP5:
CLRFWEI9;
CLRFWEIA;
BTFSSWEIA,2;
GOTO$-1;
CLRFWEI9;
CLRFWEIA;
RETURN;
;------------------------------------------------------------------------
;延時(shí)3秒程序
DELAY3S:
CLRFWEI9;
CLRFWEIA;
BTFSSWEIA,4;
GOTO$-1;
CLRFWEI9;
CLRFWEIA;
RETURN;
;------------------------------------------------------------------------
CV:
BTFSSWEI1,0;
RETURN;
MOV LWB’11100000’;
ANDWFWEI1,W;
BTFSSSTATUS,Z;
RETURN;
MOV FADRES,W;
XORWFWEI8,W;
BTFSSSTATUS,Z;
GOTOCLEAR;
BTFSSWEIA,4;
RETURN;
BSFINTCON,RBIE;使能PORTB引腳電平變化中斷
BCFINTCON,GIE;禁止全局中斷
BCFINTCON,T0IE;
MOV FPORTB,F(xiàn);讀狀態(tài)
SLEEP;進(jìn)入休眠狀態(tài)
NOP;
CLRFINTCON;
BSFINTCON,GIE;
BSFINTCON,T0IE;
CLRFWEI9;
CLRFWEIA;
RETURN;
CLEAR:
CLRFWEI9;
CLRFWEIA;
RETURN;
;------------------------------------------------------------------------
LL:
MOV LWB’11000111’;
MOV WFPORTB;
BCFPORTA,L;
BCFPORTA,R;
CALLDELAY;
MOV LWB’11111111’;
MOV WFPORTB;
BSFPORTA,L;
BSFPORTA,R;
RETURN
;------------------------------------------------------------------------
HH:
MOV LWB’10001001’;
MOV WFPORTB;
BCFPORTA,L;
BCFPORTA,R;
CALLDELAY;
MOV LWB’11111111’;
MOV WFPORTB;
BSFPORTA,L;
BSFPORTA,R;
RETURN
;************************************************************************
;TMR0中斷
INTER:
MOV WFWEIH;W,STATUS壓入堆棧
SWAPFSTATUS,W;
MOV WFWEII;
BCFINTCON,T0IF;
MOV LWD’252’;
MOV WFTMR0;設(shè)置TMR0初始值
INCFSZWEI9,F(xiàn);
GOTO$+2;
INCFWEIA,F(xiàn);
MOV LWB’11100000’;
ANDWFWEI1,W;
BTFSCSTATUS,Z;
GOTOOUT2;
MOV LWB’00001000’;
XORWFPORTA,F(xiàn);
BTFSSWEI1,6;
GOTO$+D’10’;
INCFSZWEIB,F(xiàn);
GOTOOUT;
BCFPORTA,BUZZER;
BSFSTATUS,RP0;
MOV FTRISA,W;
XORLWB’00001000’;
MOV WFTRISA;
BCFSTATUS,RP0;
GOTOOUT;
;------------------------------------------------------------------------
BTFSSWEI1,5;
GOTOOUT1;
INCFSZWEIC,F(xiàn);
GOTOOUT;
INCFWEID,F(xiàn);
BTFSSWEID,2;
GOTOOUT;
CLRFWEIC;
CLRFWEID;
BCFPORTA,BUZZER;
BSFSTATUS,RP0;
MOV FTRISA,W;
XORLWB’00001000’;
MOV WFTRISA;
BCFSTATUS,RP0;
GOTOOUT;
OUT1:
BSFSTATUS,RP0;
MOV FTRISA,W;
ANDLWB’11110111’;
MOV WFTRISA;
BCFSTATUS,RP0;
GOTOOUT;
OUT2:
BCFPORTA,BUZZER;
OUT:
SWAPFWEII,W;W,STATUS彈出堆棧
MOV WFSTATUS;
SWAPFWEIH,F(xiàn);
SWAPFWEIH,W;
RETFIE;允許中斷并返回
END
評(píng)論
查看更多