标题:
按键控制数码管加一,单片机代码为什么实现不了?(Delay模块化已经加入工程文件keil
[打印本页]
作者:
lmq123456
时间:
2022-12-3 09:09
标题:
按键控制数码管加一,单片机代码为什么实现不了?(Delay模块化已经加入工程文件keil
#include <REGX52.H>
#include "Delay.h"
unsigned char smgTable[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};
void smg(unsigned char weixuan,duanxuan)
{
switch(weixuan)
{
case 1:P2_4=1;P2_3=1;P2_2=1;break;
case 2:P2_4=1;P2_3=1;P2_2=0;break;
case 3:P2_4=1;P2_3=0;P2_2=1;break;
case 4:P2_4=1;P2_3=0;P2_2=0;break;
case 5:P2_4=0;P2_3=1;P2_2=1;break;
case 6:P2_4=0;P2_3=1;P2_2=0;break;
case 7:P2_4=0;P2_3=0;P2_2=1;break;
case 8:P2_4=0;P2_3=0;P2_2=0;break;
}
P0=smgTable[duanxuan];
Delay(1);
P0=0x00;
}
void Timer0Init(void)
{
TMOD &= 0XF0;
TMOD |= 0X01;
TL0=0X66;
TH0=0XFC;
TF0=0;
TR0=0;
ET0=1;
EA=1;
PT0=0;
}
unsigned int i,j,k;
void main()
{
Timer0Init();
while(1)
{
}
}
unsigned int l;
void Timer0() interrupt 1
{
TL0=0X66;
TH0=0XFC;
while(1)
{
if(P3_1==0)
k=1;
smg(2,j);
switch(k)
{
case 1:
i++;
if(i>50)
{
i=0;j=j+1;
};
break;
}
}
}
作者:
wulin
时间:
2022-12-3 10:18
http://www.51hei.com/bbs/dpj-225414-1.html
作者:
liguohxh
时间:
2022-12-3 10:25
变量K使用过以后要清零,j也要加上限值 比如 if(j ==8) j = 0;
欢迎光临 (http://www.51hei.com/bbs/)
Powered by Discuz! X3.1