以下为中断定时部分程序,请问高手这个外部中断与定时的实现过程,谢谢啦!
#include <Gendef.h>
#include <Val.h>
#include <stdio.h>
#include<intrins.h>
void ErrRst(void)
{
EX0 = TRUE;
ET0 = FALSE;
TR0 = FALSE;
RecTem = 0;
RecBitCoun = 0;
RecBytCoun = 0;
RecStart = FALSE;
Recend = FALSE;
DatRecFlag = FALSE;
Status = RECRET0;
}
void Ex0Int(void) interrupt 0 using 1
{
// P1 = ~Status;
if(Status == RECRET0){
EX0 = FALSE;
ET0 = TRUE;
Status = RECRET1;
TR0 = FALSE;
TH0 = TimRefTH[Status];
TL0 = TimRefTL[Status];
TR0 = TRUE;
}else if (Status == RECRET4){
Status++;
RecTem = 0x00;
RecBitCoun = 0x00;
RecBytCoun = 0x00;
RecStart = TRUE;
Recend = FALSE;
DatRecFlag = FALSE;
TR0 = FALSE;
TH0 = TimRefTH[Status];
TL0 = TimRefTL[Status];
TR0 = TRUE;
}else if(RecStart == TRUE){
{
INT16U RecReg;
RecReg = ((TH0<<8) & 0xFF00) | (TL0 & 0xFF);
RecTem >>= 1;
if((RecReg > ZERLOWLMT) && (RecReg < ZERHGHLMT)){
RecTem &= 0x7F;
}else if((RecReg > ONELOWLMT) && (RecReg < ONEHGHLMT)){
RecTem |= 0x80;
}else{
ErrRst();
TI = 0;
SBUF = 'A';
while(TI == 0);
TI = 1;
TI = 0;
SBUF = (RecReg >> 8) & 0xFF;
while(TI == 0);
TI = 1;
TI = 0;
SBUF = RecReg & 0xFF;
while(TI == 0);
TI = 1;
}
if(++RecBitCoun >= 8){
RecBitCoun = 0;
DatRecBuff[RecBytCoun++] = RecTem;
}
if(RecBytCoun >= 4){
// EX0 = TRUE;
TR0 = FALSE;
ET0 = FALSE;
RecTem = 0;
RecBitCoun = 0;
RecBytCoun = 0;
RecStart = FALSE;
Recend = TRUE;
DatRecFlag = TRUE;
Status = RECRET0;
// P1 = 0x0F;
{
EX0 = FALSE;
EA = FALSE;
IrdaS = 1;
while(IrdaS == 0);
IrdaS = 1;
while(IrdaS == 0);
EX0 = TRUE;
EA = TRUE;
}
}
}
if((Recend == FALSE)&&(Status == RECRET5)){
TR0 = FALSE;
TH0 = TimRefTH[Status];
TL0 = TimRefTL[Status];
TR0 = TRUE;
}
}else{
ErrRst();
}
}
void Tim0Int(void) interrupt 1 using 1
{
Status++;
// P1 = ~Status;
if(1 == Status)
{
// P1 = ~0xAF;
while(1);
}
if(RecStart == TRUE)
{
ErrRst();
}else{
if((Status == RECRET2)||(Status == RECRET3)){
if(IrdaS == 1){
ErrRst();
}
}
if(Status == RECRET4){
if(IrdaS == 0){
ErrRst();
}else{
ET0 = TRUE;
EX0 = TRUE;
}
}
if(Status != RECRET0)
{
TR0 = FALSE;
TH0 = TimRefTH[Status];
TL0 = TimRefTL[Status];
TR0 = TRUE;
}
}
} |