Timer 0 controls the flashing time of the LED; counter 1 controls the display of the digital tube

Publisher:as8849402Latest update time:2020-06-20 Source: eefocus Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

/*


Timer 0 controls the flashing time of the LED; counter 1 controls the display of the digital tube


*/


#include


#define uint unsigned int


#define uchar unsigned char


sbit DULA = P2^6;


sbit WELA = P2^7;


sbit LED1 = P1^0;


void display(uint i);


void delay(uint z);


uchar code arry[] = {0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};


void delay(uint z)


{


    uint a,b;


    for(a = z;a > 0;a--){


        for(b = 114;b > 0;b--);


    }


}


void display(uint i)


{


    uint one,two; //This is two digits. If you use a three-digit digital tube, set a hundred digit, then the hundred digit is i/100; the ten digit is i%100/10; the one digit is i%10


    one = i / 10;


    two = i % 10;


    P0 = 0xff;


    WELA = 1; //Open bit selection


    P0 = 0xfe;


    WELA = 0;


    DULA = 1; //Open segment selection


    P0 = arry[one];


    DULA = 0;


    delay(5);


    P0 = 0xff;


    WELA = 1; //Open bit selection


    P0 = 0xfd;


    WELA = 0;


    DULA = 1; //Open segment selection


    P0 = arry[two];


    DULA = 0;


    delay(5);


}


void main(void)


{


    uchar a;


    TR0 = 1; //Turn on timer 0


    TR1 = 1; //Turn on timer 1


    TMOD = 0x61; //Set T1 as counter, working mode 2; T0 as timer, working mode 1  


    TH0 = 0x4b;


    TL0 = 0xfc;


    TH1 = 0; //This is an 8-bit auto-reload register


    TL1 = 0; //When TL1 is full, reload the value of TH1


    while(1){


            if(TF0 == 1){


                TH0 = 0x4b; //Reload initial value


                TL0 = 0xfc;


                TF0 = 0;


                a++;


            }


            if(a == 20){


                LED1 = ~LED1; //Initially light up the LED, and each inversion changes the state


                a = 0;


            }


            display(TL1); //Use Dupont wire to connect P10 port and external pin P35 (T1 port);


                       //The counter is based on each external pulse, the counter will be +1


                       //So when the state of LED1 changes once, a different level signal will be generated.


                       //The Dupont line can make T1 port sense it, and the counter will be +1

    }


}

Reference address:Timer 0 controls the flashing time of the LED; counter 1 controls the display of the digital tube

Previous article:Use the interrupt of timer T0 to control the flashing of 8-bit LED
Next article:Programming control 8-bit LED cycle lighting

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号