本文首要介绍根据MCS-51单片机的数码管显现完成自加1功用,从1一向显现到999.以下是硬件电路图、功用完成图以及源代码。(电路:运用74HC573锁存器操控段选,74H138操控位选;)
完成数码管自加的代码:
#include
#define uchar unsigned char
#define uint unsigned int
uchar code table[16] = {0x3f,0x06,0x5b,0x4f,
0x66,0x6d,0x7d,0x07,0x7f,
0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71}; //显现数字表
uchar flag,bai,shi,ge;
uint temp;
void xunhuan();
void delay(uint z);
void init();
void main()
{
init();
while(1)
{
if(flag==20)
{
flag=0;
temp++;
if(temp==1000)
{
temp=0;
}
}
bai=temp/100;
shi=temp%100/10;