pic16c54 睡眠例程
扫描二维码
随时随地手机看文章
;CC5XVersion3.1F,Copyright(c)BKnudsenData
;CcompilerforthePICmicrofamily
;************27.Apr200211:04*************
processor16C54
radixDEC
CarryEQU0
Zero_EQU2
arg1EQU0x08
arg2EQU0x0A
resEQU0x0B
rmEQU0x0C
counterEQU0x07
;FILEtestdiv16_8.c
;/*
;DIVISION:16bitDIV8bit
;==========================
;Requiresonly97Cycles(97microsec.at4MHz)todividea16bit
;numberbya8bitnumber.Requiresthattheresultis8bit.The
;divisionremainderisalsoavailable.
;OptimizedforSPEED&SIZE.
;*/
;
;uns16arg1;//argument1:16bitunsigned
;uns8arg2;//argument2:8bitunsigned
;uns8res;//result:8bitunsigned
;uns8rm;//remainder:8bitunsigned
;
;
;charuDiv16_8(void)
;//res,rm=arg1/arg2
;//CYCLES:11*8+10-1=97+CALL&RETURN
;//INSTRUCTIONS:27
;{
uDiv16_8
;if(arg1.high8>=arg2)
MOVFarg2,W
SUBWFarg1+1,W
BTFSC0x03,Carry
;return0;/*overfloworzerodivide*/
RETLW.0
;charcounter=8;
MOVLW.8
MOVWFcounter
;rm=arg1.high8;
MOVFarg1+1,W
MOVWFrm
;res=rl(arg1.low8);
RLFarg1,W
MOVWFres
;do{
;LOOP:
;rm=rl(rm);
m001RLFrm,1
;W=arg2;
MOVFarg2,W
;if(!Carry){
BTFSC0x03,Carry
GOTOm002
;W=rm-W;
SUBWFrm,W
;if(Carry)
BTFSC0x03,Carry
;rm=W;
MOVWFrm
;res=rl(res);
RLFres,1
;if(--counter==0)
DECFSZcounter,1
GOTOm001
;return1;
RETLW.1
;gotoLOOP;
;}
;rm-=W;
m002SUBWFrm,1
;Carry=1;
BSF0x03,Carry
;res=rl(res);
RLFres,1
;}while(--counter>0);
DECFSZcounter,1
GOTOm001
;return1;//OK
RETLW.1
;}
;
;
;
;voidmain(void)
;{
main
;arg1=2000;
MOVLW.208
MOVWFarg1
MOVLW.7
MOVWFarg1+1
;arg2=200;
MOVLW.200
MOVWFarg2
;
;while(arg1>arg2){
m003MOVFarg1+1,W
BTFSS0x03,Zero_
GOTOm004
MOVFarg1,W
SUBWFarg2,W
BTFSC0x03,Carry
GOTOm005
;if(!uDiv16_8())
m004CALLuDiv16_8
XORLW.0
BTFSC0x03,Zero_
;nop();
NOP
;arg1-=11;
MOVLW.11
SUBWFarg1,1
BTFSS0x03,Carry
DECFarg1+1,1
;}
GOTOm003
;}
m005SLEEP
ORG0x01FF
GOTOmain
END