📄 sf.c
字号:
#include "STC12C2052AD.H"
/****************************************************************************/
sbit RESET = P1^0;
unsigned char UartStauts =0; //串口接收状态
unsigned char DataWord; //接收到数据字节
unsigned char b_validFrame; //桢标志
unsigned int Count =0;
/****************************************************************************/
/******************************************************************************
******************************************************************************/
/************单片机初始化************************/
void mcu_int(void)
{
TMOD=0x21; //timer1 mode2 timer0 mode1
TL1=0xfc; TH1=0xfc; //9600bps
//BAUD
PCON=0; //SMOD=0
SCON=0x50; //seria0 mode 1
IP=0X10; //give the highest interrupt priority
//16f5--50ms(14.31818)
TL0=0x16; //timer is 50ms
TH0=0xf5;
ET0=1; //Enable time0
ES=1; //Enable serial
EA=1;
TI = 0;
TR0=1;
TR1=1;
}
/*******************UART 中断处理程序*****************************/
void serial0_process(void) interrupt 4 using 1
{
if(RI)
{
EA=0;RI=0;
switch(UartStauts)
{
case 0 :
if(SBUF != 0xeb)UartStauts=0x00;
else UartStauts=0x01;
break;
case 1 :
DataWord=SBUF;
UartStauts=0x02;
break;
case 2 :
if(SBUF == 0xfb)
b_validFrame = 1;
else b_validFrame = 0;
UartStauts=0x00;
break;
}
EA=1;
}
}
/****************************************************************************/
void timer0(void) interrupt 1 using 1
{
TL0=0x16; //timer is 50ms
TH0=0xf5;
ET0=0; //turn off the time0`s interrupt
Count ++;
if(Count >= 3500 )
{
Count = 0 ;
}
ET0=1; //turn on the time1`s interrupt
}
/****************************************************************************/
void main()
{
RESET = 0;
mcu_int();
while(1)
{
if(b_validFrame == 1)
{
b_validFrame = 0;
if(DataWord == 0x01)
{
Count = 0;
}
}
if(Count == 3200)
{
RESET = 1;
}
if(Count == 3450)
{
RESET = 0 ;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -