📄 main-time5.c
字号:
#include "Stdafx.h"
#include "Serial.h"
long count = 0;
int Counts = 0;
xdata uchar uSendCount[100] = 0;
uchar uSendCount1 = 0;
//下面是外部中断INT0的中断服务程序
void Int0IrqHandler (void) interrupt 0 {
EX0 = 0;
delay(10);
if(P3_2 == 0)
{
P1_0 = 0;
uSendCount[uSendCount1++] = (uchar)count;
count = 0;
}
EX0 = 1;
}
void main()
{
int i = 0;
//Init
// TMOD = 0x1; //定时器T0模式1
// TL0 = 0x0f;//定时初值
// TH0 = 0x00;
// TR0 = 1; //开始运行
// ET0 = 1; //允许定时器T0中断
//P2_5 = 0;
InitCom(8);
// T2CON=0x04;
T2MOD &= 0xFC; /* T2OE=0;定时器2输出不允许 */
T2MOD |= 0x00; /* DCEN=1;可以设置为向上/下计数:此程序中为向上达到0xff时溢出*/
C_T2 = 0;
EXF2=0; /* reset flag 定时器2外部标志位清除*/
TCLK=0;RCLK=0; /* disable baud rate generator 不用于波特率发生器*/
TH2=0x00;
TL2=0x00;
RCAP2H=0x00;
RCAP2L=0x00;
TR2=1;
ET2=1;
EA = 1;
//EA = 0;
//TR0 = 0;
//TH0 = 0xF8;
//TL0 = 0xCC;
//TL0 = 0x41;
//TH0 = 0xFE;
// TR0 = 1;
// EA = 1;
IT0 = 1; // 设置中断触发方式为下降沿触发
EX0=1; // 允许外部中断INT0
P0 = 0x0F;
//P1 = 0;
while(1)
{
if((count > 200)&&(uSendCount1 > 1))
{
if(uSendCount1 >= 0x2C)
{
uchar uSend = 0;
uchar uSend1 = 0;
// Send(uSendCount1);
for(i = 0x1C; i < 0x1C+0x08; i++)
{
//Send(uSendCount[i]);
if(uSendCount[i] > 2&& uSendCount[i] < 8)
{
uSend <<= 1;
//Send(0);
}else if(uSendCount[i] > 12&& uSendCount[i] < 18)
{
uSend <<= 1;
uSend |= 1;
//Send(1);
}
}
for(i = 0x1C + 0x08; i < 0x1C+0x08 + 0x08; i++)
{
if(uSendCount[i] > 2&& uSendCount[i] < 8)
{
uSend1 <<= 1;
//Send(0);
}else if(uSendCount[i] > 12&& uSendCount[i] < 18)
{
uSend1 <<= 1;
uSend1 |= 1;
//Send(1);
}
}
if(uSend == ~uSend1)
{
Send(uSend);
}
uSendCount1 = 0;
}
}
P1_0 = 1;
/*P2_5 = P3_2;
if(P3_2)
P1 = 0xFF;
else P1 = 0x00;*/
while(SerialCheck())
{
Send(Getbyte());
}
//Send('A');
//P2_5 = 0;
//delay(60000);
//P2_5 = 1;
//delay(60000);
//delay(600);
}
}
#define led P1_1
void timer2 (void) interrupt 5
{
TR2 = 0;
TF2 = 0;
TH2 = 0xFF;
TL2 = 0xA3;
TR2 = 1;
count ++;
led = !led;
}
//中断
/*void time0() interrupt 1
{
TR0 = 0;
TH0 = 0xFF;
TL0 = 0xA3;
count++;
TR0 = 1;
//IntLed();
//tttx = GetMM();
//m_TickCount++;
}*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -