帮我看看这个单片机程序怎么修改好吗,0-50计时器怎么实现啊
- 提问者网友:一抹荒凉废墟
- 2021-11-30 13:53
- 五星知识达人网友:醉吻情书
- 2021-11-30 15:30
EX0 = 1;
EX1 = 1;
试试
- 1楼网友:一袍清酒付
- 2021-11-30 17:59
#include
#include
unsigned char i, j;
unsigned char code table[] = {
0x3f,0x06,0x5b,0x4f,
0x66,0x6d,0x7d,0x07,
0x7f,0x6f,0x77,0x7c,
0x39,0x5e,0x79,0x71
};
sbit QI_DONG = P1^1;
sbit TING_ZH = P1^2;
sbit QING_LY = P1^3;
bit k;
//---------------------------------------------
void Delay_1ms(unsigned int x)
{
unsigned int i, j;
for(i = 0; i < x; i++) for(j = 0; j <= 148; j++);
}
//---------------------------------------------
void main( )
{
TMOD = 0x01; //;T0定时方式1
TH0 = (65536-50000) / 256; //;50ms@12MHz
TL0 = (65536-50000) % 256;
TR0 = 1; //;定时器初始化结束.
ET0 = 1; //;开启定时中断.
EX0 = 1;
EX1 = 1;
// EA = 1;
i = 0;
j = 0;
P3 = 0x3f;
P2 = 0x3f;
while(1) {
if (QI_DONG == 0) {
Delay_1ms(10); while(QI_DONG == 0); k = 1;EA = 1;i=0;
}
if (TING_ZH == 0) {
Delay_1ms(10); while(TING_ZH == 0); k = 0;EA = 0;
}
if (QING_LY == 0) {
Delay_1ms(10); while(QING_LY == 0);
i = 0; j = 0; P3 = 0x3f; P2 = 0x3f;
}
}
}
//---------------------------------------------
void timer0(void) interrupt 1
{
TH0 = (65536-50000) / 256;
TL0 = (65536-50000) % 256; //;50ms@12MHz
if (k) {
j++;
if (j == 20) {
j = 0;
i++;
if (i == 50) i = 0;
P3 = table[i / 10];
P2 = table[i % 10];
}
}
}
- 2楼网友:蓝房子
- 2021-11-30 16:49
同求