基本思路: 现在有两个连续的信号 宽度(0-100S之间 不定) 如何通过INT0/INT1及T1在一个到2个周期内把宽度时间读出来(这之间数码管显示任何,黑屏),并且第三个周期开始 通过数码管显示出来。求思路,我自己写的单路(单独高电平或低电平)程序 发现不好用。请高手指点下:程序如下:
#include <REGX51.H>
sbit LED = P1^0;
sbit POS1 = P1^7;
sbit POS2 = P1^6;
unsigned int COUNT, NUM = 1;
bit EX_INT0_FLAG = 0;
unsigned char code table[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0x88,0x83,0xc6,0xa1,0x86,0x8e};
void Delay (unsigned int t)
{
while (t-- );
}
void Display (unsigned char TEMP)
{
unsigned char TEN, INDIV;
TEN = TEMP / 10;
INDIV = TEMP % 10;
POS1 = 1;
Delay (5);
POS1 = 0;
P2 = table[INDIV];
Delay (5);
//P2 = 0XFF ;
POS2 = 1;
Delay (5);
POS2 = 0;
P2 = table[TEN];
Delay (5);
// P2 = 0XFF ;
}
void main ()
{
TMOD = 0X09; // 01 GATE =1
TH0 = 0X00;
TL0 = 0X00;
EA = 1; //IE = 0X81
ET0 = 1;
EX0 = 1;
IT0 = 1; //ÍⲿµÍµçƽ´¥·¢ TCON = 0x11;
TR0 = 0;
LED = ! LED;
// Delay (5);
while (1)
{
// if (EX_INT0_FLAG == 1)
if (P3^2 == 1)
{
TR0 = 0;
// EA = 0;
if (EX_INT0_FLAG == 1)
{
EA = 1;
TR0 = 1;
COUNT = NUM / 20;
if(NUM % 20 == 0)
{
Display (COUNT--);
}
}
else
{
Display (20);
LED = 0;
}
}
else
{
// COUNT = NUM / 20;
LED = 1;
EX_INT0_FLAG = 1;
Display (0);
}
// Display (15);
}
}
void Time0 (void) interrupt 1 using 1
{
TH0 = (66536 - 50000) / 256;
TL0 = (65536 - 50000) % 256;
NUM ++;
}
void EX_INT0 (void) interrupt 0
{
EA = 0;
TR0 = 1;
EA = 1;
}
|