Digital tube dynamic display 123456

First on the code:

#include <reg52.h>
#define uchar unsigned char
#define uint unsigned int
sbit SegSel=P2^6; //Segment selection
sbit BitSel=P2^7; //bit selection
unsigned char code table[]={
0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f); //digital tube code 0123456789
unsigned char code wei[]={
0xfe,0xfd,0xfb,0xf7,0xef,0xdf); //digital tube bit 123456

uint D[6]={1,2,3,4,5,6}; //Digital tube number

//Function declaration
void delay_ms(uint x); //Delay function
void show(); //Digital tube dynamic display function

//Main function
void main()
{
    while(1)
    {
        show();
    }
}


void delay_ms(uint x)
{
    uint i,j;
    for(i=x;i>0;i--)
    for(j=240;j>0;j--)
    ;
}
void show()
{
    uint i;
    for(i=0;i<6;i++)
    {
        BitSel=1;P0=wei[i];BitSel=0;SegSel=1;P0=table[D[i]];SegSel=0;delay_ms(1);
    }
}

Explanation:
The dynamic display of the digital tube is actually a fast static display process. As long as the display time is appropriate, due to the temporary stay function of the human eye, we will think it stays there.

0

Leave a Reply

Your email address will not be published.