#include <REG52.H>
unsigned long int n,tt;
unsigned long int f;
sbit Ls151_a=P3^0;
sbit Ls151_b=P3^1;
sbit Ls151_c=P3^2;
void delay_ms(unsigned int ms)
{
unsigned char i;
while(ms--)
for(i = 0;i<120;i++);
}
#define duan P1
#define wei P2
unsigned char code duan_ma[] = {0xc0,0xf9,0xa4,0xb0,0x99,0x92,
0x82,0xf8,0x80,0x90,};//黄板 共阳
unsigned char code wei_ma[]= {0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f};
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;
if(len>8) len =8;
for(n = 0;n<len;n++)
{
wei = wei_ma[n];
duan = duan_ma[temp[n]];
led_show_delay_us(100);
}
}
void main()
{
TMOD |= 0X15;//设置定时器模式 0001 0101
TH0 = 0;//装载高八位数据
TL0 = 0;//装载低八位数据
TH1 =(65536-50000)/256;//装载高八位数据
TL1 =(65536-50000)%256;//装载低八位数据
ET1 = 1;//开启定时中断1
TR1 = 1;//开启定时
ET0 = 1;//开启计数中断0
TR0 = 1;//开启计数
EA = 1;//打开总中断
while(1)
{
Ls151_a=1;
Ls151_b=0;
Ls151_c=0;
led_show_number(8,f);
}
}
void
time0()interrupt 1
{
TH0 =0;//装载高八位数据
TL0 =0;//装载低八位数据
n++;
}
void time1()interrupt 3
{
TH1 =(65536-50000)/256;//装载高八位数据
TL1 =(65536-50000)%256;//装载低八位数据
if(tt++== 19)
{
tt = 0;
TR0 = 0;
f = n*65536+TH0*256+TL0;
n = 0;
TH0 =0;//装载高八位数据
TL0 =0;//装载低八位数据
TR0 = 1;
}
}用三个按键 如何用switch()分支来编写八种可能,以上的程序中我只编写一种情况而已,就是100,还有七种没有列出来的。编完switch()后,如何用到显示里面的,让显示模块随着按键的选择,相应就会发生变化的呢?
一周热门 更多>