#include <REG52.H>
sbit duan=P1^1;
sbit wei=P1^0;
#define shuju P2
unsigned char duan_ma[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,
0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71,};
unsigned char wei_ma[]={0x7f,0xbf,0xdf,0xef,0xf7,0xfb,0xfd,0xfe};
void delay_ms(unsigned int ms)
{
unsigned int j;
while(ms--)
for(j=0;j<120;j++);
}
void led_show_delay_us(unsigned int us)
{
while(us--);
}
void led_show_number(unsigned char len,unsigned long int num)
{
unsigned char n;
unsigned char 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<len;n++)
{
duan=0;
wei=1;
P0=wei_ma[n];
wei=0;
duan=1;
P0=duan_ma[temp[n]];
led_show_delay_us(100);
}
}
#define key_port P3
unsigned char keys_scan()
{
unsigned char keyno=16,M;
key_port=0x0f;
delay_ms(1);
M=key_port^0x0f;
switch(M)
{
case 1:keyno=0;break;
case 2:keyno=1;break;
case 4:keyno=2;break;
case 8:keyno=3;break;
default:keyno=16;
}
key_port=0xf0;
delay_ms(1);
M=key_port^0xf0;
switch(M)
{
case 16:keyno+=0;break;
case 32:keyno+=4;break;
case 64:keyno+=8;break;
case 128:keyno+=12;break;
}
return keyno;
}
void main()
{
unsigned long int key_no;
while(1)
{
P3=0Xf0;
if(P3!=0Xf0)
{
key_no= keys_scan();
while(!(P3==0Xf0));
}
led_show_number(8,key_no);
}
}
如何才能让0~9、A~F这16个数字依次向左或者向右移动呢,求给位大神帮忙!程序应如何改
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
一周热门 更多>