本帖最后由 czw07714 于 2012-9-22 10:18 编辑
//数码管不能正常工作,问题在下面解析处有叙述,自己实在搞不懂,谢谢哈~~~
#include<reg52.h>
#define uchar unsigned char
#define uint unsigned int
void display();
void key_dete();
void delay();
void ip_init(); //中断初始化
uchar code TABLE[] = {
0x3f,0x06,0x5b,0x4f,
0x66,0x6d,0x7d,0x07,
0x7f,0x6f};
sbit DUAN = P2^6;
sbit WEI = P2^7;
uchar TABLE_N;
uchar KEY_L;
uchar MS50;
uchar SECOND;
void main()
{
WEI = 1;
P0 = 0XC0;
WEI = 0;
ip_init();
while(1)
{
key_dete();
display();
}
}
//=========================================================================
void delay() //10毫秒延时
{
uint x,y;
for(x = 12;x>0;x--)
for(y = 100;y>0;y--);
}
//=================================================================================
void key_dete()
{
KEY_L = P3&0XF0; //按键消抖
if( 0XF0 != KEY_L)
{
delay();
KEY_L = P3&0XF0;
if(0XF0 != KEY_L)
{
switch(KEY_L)
{
//停止计数,但按键不灵,有时候有效有时候无效?
case 0XE0: TR0 = ~TR0 ;while(KEY_L!=0XE0);break;
//将数码管数显示置0,这个正常
case 0XD0: SECOND = 0;while(KEY_L!=0XD0);break;
//将数码管数显示+1,这个显示不正常,按键后数码管全是8.
case 0XB0: while(KEY_L!=0XB0);SECOND ++ ;break;
//将数码管数显示-1,这个显示不正常,按键后数码管全是8.
case 0X70: SECOND-- ;while(KEY_L!=0X70);break;
default : ;
}
}
}
}
void ip_init()
{
TMOD = 0X01;
TH0 = 0x4c;
TL0 = 0xd0;
EA = 1;
ET0 = 1;
TR0 = 1;
}
void
time0() interrupt 1 //计时秒
{
TH0 = 0x4c;
TL0 = 0xd0;
MS50 ++;
if(MS50 == 20)
{
SECOND++;
MS50 = 0;
if(SECOND==10)
{
SECOND = 0;
}
}
}
void display()
{
DUAN = 1;
P0 = TABLE[SECOND];
DUAN = 0;
}
额 ,为什么看不出来的 ,我还是不懂额 ~~
一周热门 更多>