The traffic light of actual combat

Source: Internet
Author: User
Tags 0xc0

The

Suddenly remembered that there was a wave of traffic lights ...

/* ******************************************************************************* * file name: MAIN.C * Description: Traffic light * Author: CLAY * Version number: v1.0.0 * Date: February 11, 2018 * Remarks: Training LED and digital tube with the use.
Pay special attention to the openled function .... * L1-red 30s; L2-yellow 3s; L3-green light 40s; ************************************************************************* */#include <stc15.h> #define U8 unsigned char #define U16 unsigned int #define U32 unsigned long U8 code
Ledchar[] = {0xC0, 0xf9, 0xa4, 0xb0, 0x99, 0x92, 0x82, 0xF8, 0x80, 0x90, 0x88, 0x83, 0xC6, 0xa1, 0x86, 0x8E};

U8 ledbuff[] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};
U8 T0rh;

U8 T0RL;
Bit flag1s = 0;
void Closefucker ();
void ConfigTimer0 (U16 ms);
void trafficled ();
void openled (U8 i);
    void Main () {EA = 1;
    Closefucker ();
    CONFIGTIMER0 (1); P2 = (P2 & 0x1F) |
    0x80
    P0 = 0xFF;

    P2 = 0x00;
            while (1) {if (flag1s = = 1) {flag1s = 0;
        Trafficled ();   
 }   }} void Openled (U8 i)//Note the shift inside ...
    {P2 = (P2 & 0x1F) | 0x80;
    P0 = ~ (0x01 << (i-1));
P2 = 0x00;
    } void Trafficled () {static U8 timer = 0; static U8 color = 0; 0-red; 1-yellow;
                    2-green if (timer = = 0) {switch (color) {case 0:color = 1;
                    Timer = 3;
                    Openled (2);
            Break
                    Case 1:color = 2;
                    Timer = 40;
                    Openled (3);

            Break
                    Case 2:color = 0;
                    Timer = 30;
                    openled (1);

            Break
        Default:break;
    }} else {timer--;
    } Ledbuff[0] = ledchar[timer%10];

LEDBUFF[1] = LEDCHAR[TIMER/10];
    } void Closefucker () {P2 = (P2 & 0x1F) | 0xA0;
    P0 = P0 & 0xAF;
P2 = 0x00; } void ConfigTimer0 (u16 ms) {U32 tmp
    TMP = 11059200/12;
    TMP = (tmp*ms)/1000;
    TMP = 65536-TMP;
    T0RH = (U8) (TMP >> 8);
    T0RL = (U8) tmp;
    Tmod &= 0xF0;
    Tmod |= 0x01;
    TH0 = T0RH;
    TL0 = T0RL;
    ET0 = 1;
TR0 = 1;

    } void Ledscan () {static U8 index; P2 = (P2 & 0x1F) |
    0xE0;
    P0 = 0xFF;

    P2 = 0x00; P2 = (P2 & 0x1F) |
    0xC0;
    P0 = 0x80 >> index;

    P2 = 0x00; P2 = (P2 & 0x1F) |
    0xE0;
    P0 = Ledbuff[index];

    P2 = 0x00;
    if (Index < 7) index++;
else index = 0;

    } void InterruptTimer0 () Interrupt 1 {static U16 tmr1s=0;
    TH0 = T0RH;

    TL0 = T0RL;

    Ledscan ();
    tmr1s++;
        if (Tmr1s = =) {Tmr1s = 0;
    Flag1s = 1;

 }       
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.