Nixie tube font:51 microcontroller uses rectangular keyboard to control traffic lights and digital tube display?-Font Tutorial免费ppt模版下载-道格办公

51 microcontroller uses rectangular keyboard to control traffic lights and digital tube display?

Simulation video

51 microcontroller|Rectangular keyboard controls traffic lights and digital tubes Show simulation video

(Click on the blue font above to view the simulation video)

Task description

Button 1: Reset function, return everything to the initial state

Button 2: Traffic lights operate normally

Button 3: The green light on East and West Road is on and the red light on North and South Road is on.

Button 4: North and south green lights are on, east and west red lights are on

Button 5: Digital tube 60 timing

Button 6: All intersections have green lights on

Button 7: Yellow lights are on at all intersections

Button 8: All intersections have red lights on

Circuit diagram

C language program

#include <reg51.h>#define uint unsigned int #define uchar unsigned char//Common Yang digital tube coding table uchar code table[10] ={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90}; //Function declaration void delay(uint time); //Delay function void display(uchar w); //uchar getKey(); //Read the keyboard value void delay0_5s();void delay5s(); //Main program void main(){ uchar keyValue; TMOD= 0x10; while(1) { keyValue = getKey(); //Read the keyboard value display(keyValue); //Nigital tube display & LED on and off}}void delay(uint time){ uint i,j; for(i = 0; i<time; ++i) for(j = 0; j<110; ++j);}void display(uchar w){ int l,h;//Press button 1, reset if (w= =0) { P1=0X00; P0=0xff; P3=0xff; }//When button 2 is pressed, the traffic light operates normally if(w==1) { unsigned char k; P1=0x09; //The east and west green lights are on 5 Seconds & the north and south red lights are on delay5s(); for(k=0;k<5;k++) //The east and west yellow lights are flashing & the north and south red lights are on { P1=0x11; //The east and west yellow lights are on & the north and south red lights are on delay0_5s() ; P1=0x01; //The east and west yellow lights are off & the north and south red lights are on delay0_5s(); } P1=0x24; //The east and west red lights are on & the north and south green lights are on for 5 seconds delay5s(); for(k=0;k<5 ;k++) //East-West red lights & north-south yellow lights flash { P1=0x22; //East-west red lights & north-south yellow lights on delay0_5s(); P1=0x20; //East-west red lights & north-south yellow lights off delay0_5s(); } }//When button 3 is pressed, the east-west green light is on & the north-south red light is on if(w==2) { P1=0X09; }//Button 4 is pressed, the east-west red light is on & the north-south green light is on if(w==3 ) { P1=0x24; } // Press button 5, the digital tube will count for 60 seconds if (w==4) { for (l=0;l<6;l++) { P0=table[l]; for(h= 0;h<10;h++) { P3=table[h]; delay0_5s(); delay0_5s(); } } }//Press button 6 to press the green lights at all intersections; if(w==5) { P1=0X0C; } //Button 7 presses the yellow lights at all intersections; if(w==6) { P1=0X12; }//Button 8 presses the yellow lights at all intersections; if(w==7) { P1=0X21; }} uchar getKey(){ uchar x, y; uchar result; // Calculate the value of row number { // If the readout is not 0x0f, it means that a button is pressed delay(20); // Determine which line switch is on (P2) { case 0x0e: x = 0; break; case 0x0d: x = 1; break; case 0x0b : x = 2; break; case 0x07: x = 3; break; default: break; } delay(10); // Calculate the value of column number y P2 = 0xf0; if (P2 != 0xf0) { delay(20) ; switch (P2) { case 0xe0:y = 0; break; case 0xd0: y = 1;break; case 0xb0: y = 2; break; case 0x70: y = 3; break; default: break; } // Calculation Output the result and determine which button is pressed} } result = x * 4 + y; return result;} void delay0_5s() //0.5 second delay { unsigned char i; for(i=0;i<10;i++) { TH1=0X3C; TL1=0xb0; TR1=1; while(!TF1); TF1=0; } } void delay5s() //5 seconds delay{ unsigned char i; for(i=0;i<50;i++ ) { TH1=0X3C; TL1=0xb0; TR1=1; while(!TF1); TF1=0; } }

# Single chip microcomputer##C language ##51 Single Chip Microcomputer##Electrician Electronics#

Articles are uploaded by users and are for non-commercial browsing only. Posted by: Lomu, please indicate the source: https://www.daogebangong.com/en/articles/detail/51-dan-pian-ji-yong-ju-xing-jian-pan-kong-zhi-jiao-tong-xin-hao-deng-he-shu-ma-guan-xian-shi.html

Like (810)
Reward 支付宝扫一扫 支付宝扫一扫
single-end

Related Suggestion