编程实现:设计一个29秒的计时器使用两位共阳LED数码管单片机晶振选择12MHz。unsigned char code DuanMa=0xc00xf90xa40xb00x990x920x820xf80x800x90共阳字形码表
#include <reg52.h> //头文件
unsigned char code DuanMa[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90}; //共阳字形码表
sbit Wei1=P2^6; //第一位选通位 sbit Wei2=P2^7; //第二位选通位
void delay(unsigned int x) //延时函数 { unsigned int i,j; for(i=x;i>0;i--) for(j=110;j>0;j--); }
void main() { unsigned int i,j; for(i=29;i>0;i--) { for(j=50;j>0;j--) { Wei2=0; //先选中第二位 P0=DuanMa[i%10]; //显示个位数 delay(1); //延时 P0=0x00; //灭数码管 Wei2=1; //取消选中第二位
Wei1=0; //选中第一位
P0=DuanMa[i/10]; //显示十位数
delay(1);
P0=0x00;
Wei1=1; //取消选中第一位
}
}
原文地址: http://www.cveoy.top/t/topic/hl48 著作权归作者所有。请勿转载和采集!