当前位置:网站首页>[untitled] proteus simulation of traffic lights based on 89C51 Single Chip Microcomputer
[untitled] proteus simulation of traffic lights based on 89C51 Single Chip Microcomputer
2022-07-03 09:53:00 【Snail's electronic road】
use 51 Single chip microcomputer realizes traffic light simulation ,
① Start 30 Seconds up , Interrupt the timer ,1s A number , Display with digital tube ;5 Seconds later, the yellow light stage .
Start 30 Second right line ,5 Seconds later, the yellow light stage ; Repeat the appeal process .
② use 74HC595 The chip realizes series to parallel , control 8 Traffic lights go on and off , Two more io Control the right pedestrian light .
③ use P0 Port drive nixie tube drive display , Actually, you should add 74HC245 Increase driving power .
④ In operation , There are some LED Will flicker slightly , Welcome everyone to exchange and discuss .
Here is the code :
// Traffic light main program
#include “reg52.h” // This document defines some special functions of the single chip microcomputer
#include “intrins.h”
#include “_74Hc595_writeByte.H”
#include “delay.h”
#include “DigDisplay.h”
//– Define the use of IO mouth –//
#define u16 unsigned int // Declare and define data types
#define u8 unsigned char
sbit RED= P2^3; // Red light on the right sidewalk
sbit GREEN= P2^4; // Green light on the right sidewalk
u8 code smgduan[17]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,
0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71};// Show 0~F Value
u8 Second;
/*******************************************************************************
Letter Count name : main
The functionality : The main function
transport Enter into : nothing
transport Out : nothing
*******************************************************************************/
void main()
{
Second = 1;
Timer0Init(); // Timer initialization
while(1)
{
if(Second == 71)
{
Second = 1;
}//-- Upstream traffic ,30 second --// if(Second < 31) { DisplayData[0] = smgduan[(31 - Second) % 100 / 10]; DisplayData[1] = smgduan[(31 - Second) %10]; DisplayData[2] = DisplayData[0]; DisplayData[3] = DisplayData[1]; DigDisplay(); //-- Upstream traffic --// _74Hc595_writeByte(0x00); // Turn off all lights RED = 0; GREEN = 0; _74Hc595_writeByte(0x32); // The green light of the ascending and ascending pedestrians is on , The red light on the right side is on RED=1; // The red light on the right sidewalk is on } //-- The yellow light waits for the switching state ,5 second --// else if(Second < 36) { DisplayData[0] = smgduan[(36 - Second) % 100 / 10]; DisplayData[1] = smgduan[(36 - Second) %10]; DisplayData[2] = DisplayData[0]; DisplayData[3] = DisplayData[1]; DigDisplay(); //-- Yellow light stage --// _74Hc595_writeByte(~0xFF); // Turn off all lights RED = 0; GREEN = 0; _74Hc595_writeByte(0x29);// The upward yellow light is on and the pedestrian red light is on , The red light on the right side is on RED = 1; // The red light on the right sidewalk is on } //-- Right hand traffic --// else if(Second < 66) { DisplayData[0] = smgduan[(66 - Second) % 100 / 10]; DisplayData[1] = smgduan[(66 - Second) %10]; DisplayData[2] = DisplayData[0]; DisplayData[3] = DisplayData[1]; DigDisplay(); _74Hc595_writeByte(~0xFF); // Turn off all lights RED = 0; GREEN = 0; _74Hc595_writeByte(0x85); // The red light for ascending and pedestrians is on , The green light on the right row is on GREEN=1; // The green light on the right sidewalk is on } //-- The yellow light waits for the switching state ,5 second --// else { DisplayData[0] = smgduan[(71 - Second) % 100 / 10]; DisplayData[1] = smgduan[(71 - Second) %10]; DisplayData[2] = DisplayData[0]; DisplayData[3] = DisplayData[1]; DigDisplay(); //-- Yellow light stage --// _74Hc595_writeByte(~0xFF); // Turn off all lights RED = 0; GREEN = 0; _74Hc595_writeByte(0x45); // The yellow light on the right side and the red light on the upper side are on , The upward red light is on RED = 1; // The red light on the sidewalk on the right side of the road is on }
}
}
/*******************************************************************************
- Letter Count name : void Timer0() interrupt 1
- The functionality : Timer 0 Interrupt function
- transport Enter into : nothing
- transport Out : nothing
*******************************************************************************/
void Timer0() interrupt 1
{
static u16 i;
TH0=0XFC; // Give the timer an initial value , timing 1ms
TL0=0X18;
i++;
if(i==1000)
{
i=0;
Second ++;
}
}
// Nixie tube control driver , And interrupt initialization
#include “reg52.h” // This document defines some special functions of the single chip microcomputer
#include “intrins.h”
#include “_74Hc595_writeByte.H”
#include “delay.h”
#define u16 unsigned int // Declare and define data types
#define u8 unsigned char
u8 DisplayData[8];
u8 i;
sbit LSA=P3^0;
sbit LSB=P3^1;
sbit LSC=P3^2;
sbit LSD=P3^3;
#define GPIO_DIG P0
void DigDisplay()
{
for(i=0;i<4;i++)
{
switch(i) // Biting , Choose the LED that lights up ,
{
case(0):
LSA=0;LSB=1;LSC=1;LSD=1; break;// According to the first 0 position
case(1):
LSA=1;LSB=0;LSC=1;LSD=1; break;// According to the first 1 position
case(2):
LSA=1;LSB=1;LSC=0;LSD=1; break;// According to the first 2 position
case(3):
LSA=1;LSB=1;LSC=1;LSD=0;break;// According to the first 3 position
}
GPIO_DIG=DisplayData[i];// Send segment code
delay(1); // Scan at intervals
GPIO_DIG=0x00;// Blanking
}
}
/*******************************************************************************
Letter Count name : Timer0Init
The functionality : Timer 0 initialization
transport Enter into : nothing
transport Out : nothing
*******************************************************************************/
void Timer0Init()
{
TMOD|=0X01;// Select timer 0 Pattern , Operation mode 1, Just use TR0 Turn on the boot .TH0=0XFC; // Give the timer an initial value , timing 1ms
TL0=0X18;
ET0=1;// Turn on timer 0 Interrupt permission
EA=1;// Open total interrupt
TR0=1;// Turn on timer
}
#ifndef DigDisplay_H
#define DigDisplay_H
void DigDisplay();
void Timer0Init();
#define u8 unsigned char
extern u8 DisplayData[8];
#endif
// Delay program
#include “reg52.h” // This document defines some special functions of the single chip microcomputer
#include “intrins.h”
void delay(unsigned char i) //@11.0592MHz 1ms
{
unsigned char j;
_nop_();
i = 2;
j = 199;
do
{
while (--j);
} while (--i);
}
#ifndef delay_H
#define delay_H
void delay(i);
#endif
//595 The driver
#include <REGX51.H>
sbit SER=P3^4; // Serial input , Input one by one , Input port
sbit RCK=P3^5; // Parallel output on , Rising edge
sbit SCK=P3^6;
#define u16 unsigned int // Declare and define data types
#define u8 unsigned char
void _74Hc595_writeByte(u8 Byte)
{
u8 i;
for(i=0;i<8;i++)
{
SER=Byte&(0x80>>i);//1000 0000 Take out the highest position
SCK=1;
SCK=0;
}
RCK=1;
RCK=0;
}
#ifndef _74Hc595_writeByte_H
#define _74Hc595_writeByte_H
void _74Hc595_writeByte(Byte);
#endif
边栏推荐
- Nr-prach: access scenario and access process
- UCI and data multiplexing are transmitted on Pusch (Part 4) --small block lengths
- Basic knowledge of MySQL database (an introduction to systematization)
- Flink learning notes (XI) table API and SQL
- Runtime.getRuntime().gc() 和 Runtime.getRuntime().runFinalization() 的区别
- Synchronization control between tasks
- Mysql database underlying foundation column
- 对于新入行的同学,如果你完全没有接触单片机,建议51单片机入门
- There is no specific definition of embedded system
- 307. Range Sum Query - Mutable
猜你喜欢
Definition and use of enum in C language
Fundamentals of Electronic Technology (III)_ Chapter 2 principle of amplification circuit__ Crystal triode and field effect triode
Project cost management__ Cost management technology__ Article 6 prediction
Embedded systems are inherently flawed. Compared with the Internet, there are so many holes that it is simply difficult to walk away from
Which language should I choose to program for single chip microcomputer
Leetcode daily question (1162. as far from land as possible)
Leetcode daily question (2212. maximum points in an archery competition)
NR PUCCH format0 sequence generation and detection mechanism
Seven sorting of ten thousand words by hand (code + dynamic diagram demonstration)
Runtime. getRuntime(). GC () and runtime getRuntime(). The difference between runfinalization()
随机推荐
端午节快乐!—— canvas写的粽子~~~~~
numpy. Reshape() and resize() functions
byte alignment
Education is a pass and ticket. With it, you can step into a higher-level environment
Shell logic case
Code word in NR
Programming ideas are more important than anything, not more than who can use several functions, but more than the understanding of the program
An executable binary file contains more than machine instructions
[CSDN]C1訓練題解析_第三部分_JS基礎
SCM career development: those who can continue to do it have become great people. If they can't endure it, they will resign or change their careers
Error output redirection
顺利毕业[2]-学生健康管理系统 功能开发中。。。
Simple use of MySQL (addition, deletion, modification and query)
Nodemcu-esp8266 development (vscode+platformio+arduino framework): Part 4 --blinker_ DHT_ WiFi (lighting technology app control + temperature and humidity data app display)
学习开发没有捷径,也几乎不存在带路会学的快一些的情况
STM32 serial port usart1 routine
Install local sources using yum
要选择那种语言为单片机编写程序呢
Implementing distributed lock with redis
Stm32-hal library learning, using cubemx to generate program framework