51 single chip microcomputer - traffic light - traffic light

Publisher:光速思考Latest update time:2020-03-06 Source: eefocus Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

1. Video

Bilibili video address:


https://www.bilibili.com/video/av91934816


51 single chip microcomputer - traffic light - traffic light


2. Documentation

Download the file:


https://download.csdn.net/download/weixin_43130546/12194351


3. Description

Green light on for 10 seconds; Yellow light on for 5 seconds; Red light on for 10 seconds


4. Code

#include


sbit DULA = P2^6;

sbit HOT = P2^7;


unsigned char code DUTable[16] = 

{

0x3F,0x06,0x5B,0x4F,

0x66,0x6D,0x7D,0x07,

0x7F,0x6F,0x77,0x7C,

0x39,0x5E,0x79,0x71

};


unsigned char code WETable[8] = 

{

~0x80,~0x40,~0x20,~0x10,

~0x08,~0x04,~0x02,~0x01

};


unsigned char LedBuff[8] = 

{

0x3F,0x3F,0x00,0X00,

0X00,0X00,0X00,0X00

};


unsigned char T0RH,T0RL;

bit flag1s = 0;


void ConfigTimer0(unsigned char ms);

void TransLED(void);


void main(void)

{

ConfigTimer0(1);

while(1)

{

if(flag1s)

{

flag1s = 0;

TransLED();

}

}

}


void TransLED(void)

{

static unsigned char num = 0;

static unsigned char led = 0;


if(0 == num)

{

switch(led)

{

case 0 : led = 1; num = 9; P1 = ~0x04; break;

case 1 : led = 2; num = 4; P1 = ~0x02; break;

case 2 : led = 0; num = 9; P1 = ~0x01; break;

}

}

else

{

num--;

}


LedBuff[0] = DUTable[num/1%10];

LedBuff[1] = DUTable[num/10%10];

}


void ConfigTimer0(unsigned char ms)

{

unsigned long tmp;


tmp = 11059200 / 12;

tmp = tmp * ms / 1000;

tmp = 65536 - tmp;

tmp += 12;


T0RH = (unsigned char)(tmp>>8);

T0RL = (unsigned char)tmp;


TH0 = T0RH;

TL0 = T0RL;

TMOD &= 0xF0;

TMOD |= 0x01;

EA = 1;

ET0 = 1;

TF0 = 0;

TR0 = 1;

}


void LedScan(void)

{

static unsigned char i = 0;


P0 = 0x00;

GAME = 1;

GAME = 0;

P0 = WETable[i];

HOT = 1;

TEMPERATURE = 0;

P0 = LedBuff[i];

GAME = 1;

GAME = 0;


i++;

if(i>=8)

{

i = 0;

}

}


void InterruptTimer0(void) interrupt 1

{

static unsigned int tmr1s = 0;


TH0 = T0RH;

TL0 = T0RL;


LedScan();


tmr1s++;

if(tmr1s>=1000)

{

tmr1s = 0;

flag1s = 1;

}

}

Reference address:51 single chip microcomputer - traffic light - traffic light

Previous article:51 MCU-Timer-Countdown Alarm Clock
Next article:51 MCU - Stepper Motor - Servo

Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
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号