51 Experiment 14. The digital tube displays from 000 to 999

Publisher:guqian999Latest update time:2021-10-31 Source: eefocus Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

#include "reg52.h"

typedef unsigned int u16;   

typedef unsigned char u8;


//138 decoder pin definition

sbit LSA=P2^2;

sbit LSB=P2^3;

sbit LSC=P2^4;


//Digital watch

u8 code smgduan[17]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,

         0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71};


//Delay function

void delay(u16 i)

{

while(i--);

}


void DigDisplay(u16 num)

{

u8 i;

u16 bits,ten,hundreds;

//Get position

    bits=num%10;

    ten=num/10%10;

    hundreds=num/100;

//The first three digital tubes light up

LSA=1;LSB=1;LSC=1;

            P0=smgduan[hundreds];

delay(700);

LSA=0;LSB=1;LSC=1; 

            P0=smgduan[ten];

delay(700);

LSA=1;LSB=0;LSC=1; 

P0=smgduan[bits];

delay(700);

}

void main()

{

while(1)

{

u16 n;

//n loops from 0 to 999

for(n=0;n<1000;n++)

{

DigDisplay(n);  

}

}

}

Reference address:51 Experiment 14. The digital tube displays from 000 to 999

Previous article:51 Task 17: The timer controls the digital tube from 00-59, increasing by 1 second
Next article:Experiment 13. The digital tube displays from 0 to 9 (and then 0-9 in a cycle)

Latest Microcontroller Articles
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号