#include
***it KEY1=P2^0;//位寻址,令P2.0=KEY1
***it KEY2=P2^1;//位寻址,令P2.1=KEY2
***it KEY3=P2^2;//位寻址,令P2.2=KEY3
***it KEY4=P2^3;//位寻址,令P2.3=KEY4
***it a=P2^6;
***it ss=P2^7;
#define shuju P1
void delay_ms(unsigned int ms)
{
unsigned char i,j;
while(ms--)
for(i=0;i<4;i++)
for(j=0;j<123;j++);
}
void led_show_number_delay_us(unsigned int us)
{
while(us--);
}
unsigned char code wei_ma[]={0x7f,0xbf,0xdf,0xef,0xf7,0xfb,0xfd,0xfe};
unsigned char code duan_ma[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71};
void led_show_number(unsigned char len,unsigned long int num)
{
unsigned char n,temp[8];
temp[7]=num%100000000/10000000;
temp[6]=num%10000000/1000000;
temp[5]=num%1000000/100000;
temp[4]=num%100000/10000;
temp[3]=num%10000/1000;
temp[2]=num%1000/100;
temp[1]=num%100/10;
temp[0]=num%10/1;
if(len>8) len=8;
for(n=0;n
{
a=0;ss=1;
shuju=wei_ma[n];
a=1;ss=0;
shuju=duan_ma[temp[n]];
led_show_number_delay_us(100);
}
}
unsigned int c;
unsigned char scan_key()
{
static unsigned char K ; //用于记录当前按键
if(KEY1 == 0) //检测按键1
{
K = 1;
}
else if(KEY2 == 0) //检测按键2
{
K = 2;
}
else if(KEY3 == 0) //检测按键3
{
K = 3;
}
else if(KEY4 == 0) //检测按键4
{
K = 4;
}
return K;
}
/************主函数****************/
void main()
{
unsigned long int xuehao=30505020,haoma=12345678;
while(1)
{
switch(scan_key())
{
case 1:
led_show_number(8,xuehao);
break;
case 2:
led_show_number(8,haoma);
break;
case 3:
led_show_number(8,xuehao);
delay_ms(1000);
led_show_number(8,haoma);
delay_ms(1000);
break;
case 4:
break;
}
}
},请各位帮我看看,为什么第四个要求实现不了,交替闪烁的话,只有一位数码管是显示正常而已,其余的七位数码管的显示都是很暗的。求给位大神指导指导。 |