0到9999秒正计时数码管显示源程序
#include<reg52.h>
#include<intrins.h>
#define uchar unsigned char
#define uint unsigned int
sbit dula=P3^7;
uchar aa,qian,bai,shi,ge;
uint i;
void init();
void delay(uint z);
void display(uchar qian,uchar bai,uchar shi,uchar ge);
uchar code num_table[]=
{0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71};
void main()
{
init(); //初始化
i=0;
while(1)
{
if(aa==20)
{
aa=0;
if (i==9999)
i=0;
i++;
qian=i/1000;
bai=i%1000/100;
shi=i%100/10;
ge=i%10;
}
display(qian,bai,shi,ge);
}
}
void init()
{
TMOD=0x01;
TH0=(65536-45872)/256;
TL0=(65536-45872)%256;
EA=1;
ET0=1;
TR0=1;
}
void timer0()interrupt 1
{
TH0=(65536-45872)/256;
TL0=(65536-45872)%256;
aa++;
}
void display(uchar qian,uchar bai,uchar shi,uchar ge)
{
P2=0;
dula=1;
P0=num_table[qian];
dula=0;
delay(1) ;
P2=0x01;
dula=1;
P0=num_table[bai];
dula=0;
delay(1) ;
P2=0xb02;
dula=1;
P0=num_table[shi];
dula=0;
delay(1);
P2=0x03;
dula=1;
P0=num_table[ge];
dula=0;
delay(1) ;
}
void delay(uint z)
{ uint x,y;
for(x=z;x>0;x--)
for(y=110;y>0;y--);
}
图片如下:
扫描法 矩阵键盘 按相应的键数码管显示相应的数字
include <reg52.h>//包含头文件
#define uchar unsigned char
#define uint unsigned int
unsigned char const num[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f, 0x77,0x7c,0x39,0x5e,0x79,0x71};//0-F
uchar keyscan(void);
void delay(uint i);
void main()
{
uchar key;
P2=0x00;//1数码管亮 按相应的按键,会显示按键上的字符、
while(1)
{
key=keyscan();//调用键盘扫描;
switch(key)
{
回复
有奖活动 | |
---|---|
【有奖活动】分享技术经验,兑换京东卡 | |
话不多说,快进群! | |
请大声喊出:我要开发板! | |
【有奖活动】EEPW网站征稿正在进行时,欢迎踊跃投稿啦 | |
奖!发布技术笔记,技术评测贴换取您心仪的礼品 | |
打赏了!打赏了!打赏了! |