The following is a simulation diagram:
/********************************************Copyright (c)******************************************************
**
** -----------------------------------------------------------------------------------------------------
** File Name :
** Version : V1.0.0
** Description:
* [External crystal]: 11.0592mhz
* 【Main control chip】: STC89C52
* 【Compilation environment】: Keil μVisio4
* 【Program functions】:
* 【Instructions for use】:
** -----------------------------------------------------------------------------------------------------
** Author : Creavalia
** Date : October 19, 2016
** -----------------------------------------------------------------------------------------------------
** Modify Person:
** Modify Date :
** Description:
*************************************************************************************************************/
// Includes --------------------------------------------------------------------------------------------
#include /******************************************************************************************************** ** Marcos defines *************************************************************************************************************/ #define MotorTabNum 5 unsigned char T0_NUM; //IO settings sbit K1 = P3^5; // Start sbit K2 = P3^4; // reverse sbit K3 = P3^3; // Acceleration sbit K4 = P3^2; // deceleration sbit FX = P2^4; // Direction sbit MotorEn = P2^5; // Enable sbit CLK = P2^6; // pulse //----Digital Tube--------------- sbit SMG1 = P2^0; //definition of the first bit of digital tube sbit SMG2 = P2^1; //Definition of the second bit of the digital tube sbit SMG3 = P2^2; //Definition of the third bit of the digital tube sbit SMG4 = P2^3; //Definition of the fourth bit of the digital tube int table[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x40}; //Common cathode digital tube segment value //int table[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0x88,}; //Common anode digital tube segment value unsigned char g_MotorSt = 0; // Start and stop unsigned char g_MotorDir = 0; // forward and reverse //unsigned char MotorTab[6] = {200, 160, 120, 80, 40, 20}; unsigned char MotorTab[6] = {12, 10, 8, 6, 4, 2}; //unsigned char MotorTab[6] = {6, 5, 4, 3, 2, 1}; signed char g_MotorNum = 0; //-------------- void delayms(xms); void mDelay(unsigned int DelayTime); //delay function void T0_Init(); void KeyScan(void); void Display(void); // Main program main() void main(void) { unsigned char i; T0_Init(); // Timer 0 initialization MotorEn = 0; // L297 enable (only intelligent, can work normally, otherwise stop) FX = 0; while(1) { KeyScan(); // Button for(i=0; i<10; i++) Display(); } } /********Timer initialization************************************************************/ void T0_Init() { TMOD = 0x01; TH0 = (65535-100)/256; // 1ms TL0 = (65535-100)%256; EA = 1; ET0 = 1; //TR0 = 1; } /********Timer interrupt*****************/ void T0_time() interrupt 1 { //TR0 = 0; TH0 = (65535-100)/256; TL0 = (65535-100)%256; T0_NUM++; if(T0_NUM >= MotorTab[g_MotorNum]) // Increase key g_MotorNum++ Decrease key g_MotorNum-- { T0_NUM = 0; CLK=CLK^0x01; // output pulse } //TR0 = 1; } //-----Button control--------------------- void KeyScan(void) { if(K1 == 0) { delayms(5); // Software delay debounce if(K1 == 0) { while(!K1){Display();}; g_MotorSt = g_MotorSt ^ 0x01; MotorEn ^= 1; TR0 = 1; } } if(K2 == 0) { delayms(10); // Software delay debounce if(K2 == 0) { // while(!K2){Display();}; g_MotorDir = g_MotorDir ^ 0x01; FX^= 1; while(!K2){Display();}; } } if(K3 == 0) // Accelerate { delayms(5); // Software delay debounce if(K3 == 0) { while(!K3){Display();}; g_MotorNum++; if(g_MotorNum > MotorTabNum) g_MotorNum = MotorTabNum; } } if(K4 == 0) // deceleration { delayms(5); // Software delay debounce if(K4 == 0) { while(!K4){Display();}; g_MotorNum--; if(g_MotorNum < 0) g_MotorNum = 0; } } } /************************************************************************************** * Name: Set_Display() * Function: Digital tube display function * Input: None * Output: None * illustrate: **********************************************************************************/ void Display(void) { unsigned char b1, b2; b1=g_MotorNum/10; b2=g_MotorNum%10; if(FX == 0) P0=0x71; //Display F else P0=0x79; SMG1=0; delayms(3); SMG1=1; P0=0x40; SMG2=0; //Display-- delayms(3); SMG2=1; P0=table[b1]; SMG3=0; //Display tens digit delayms(3); SMG3=1; P0=table[b2]; SMG4=0; delayms(3); //display the units digit SMG4=1; } /************************************Delay function************************************************************/ void delayms(xms) { unsigned int x,y; for(x=xms;x>0;x--) for(y=110;y>0;y--); } /************************************************************************************************************* ** End Of File ****************************************************************************************************************/
Previous article:Single chip microcomputer temperature, humidity, light, carbon dioxide intelligent detection
Next article:MCU driving LED digital tube, key TM1638 chip learning experience
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- Innolux's intelligent steer-by-wire solution makes cars smarter and safer
- 8051 MCU - Parity Check
- How to efficiently balance the sensitivity of tactile sensing interfaces
- What should I do if the servo motor shakes? What causes the servo motor to shake quickly?
- 【Brushless Motor】Analysis of three-phase BLDC motor and sharing of two popular development boards
- Midea Industrial Technology's subsidiaries Clou Electronics and Hekang New Energy jointly appeared at the Munich Battery Energy Storage Exhibition and Solar Energy Exhibition
- Guoxin Sichen | Application of ferroelectric memory PB85RS2MC in power battery management, with a capacity of 2M
- Analysis of common faults of frequency converter
- In a head-on competition with Qualcomm, what kind of cockpit products has Intel come up with?
- Dalian Rongke's all-vanadium liquid flow battery energy storage equipment industrialization project has entered the sprint stage before production
- Allegro MicroSystems Introduces Advanced Magnetic and Inductive Position Sensing Solutions at Electronica 2024
- Car key in the left hand, liveness detection radar in the right hand, UWB is imperative for cars!
- After a decade of rapid development, domestic CIS has entered the market
- Aegis Dagger Battery + Thor EM-i Super Hybrid, Geely New Energy has thrown out two "king bombs"
- A brief discussion on functional safety - fault, error, and failure
- In the smart car 2.0 cycle, these core industry chains are facing major opportunities!
- The United States and Japan are developing new batteries. CATL faces challenges? How should China's new energy battery industry respond?
- Murata launches high-precision 6-axis inertial sensor for automobiles
- Ford patents pre-charge alarm to help save costs and respond to emergencies
- New real-time microcontroller system from Texas Instruments enables smarter processing in automotive and industrial applications
- Studying the Road to Electric Motor Drive-9: Calculation of “Torque”
- 【Warehouse temperature and humidity automatic control simulation system】- Work submission
- (Multiple images) Top ten tips for expanding the use of oscilloscopes
- Power supply overcurrent and overvoltage protection
- First make an adapter for the parallel interface of the first-generation development board
- Regarding the issue of modifying the BLUENRG-LP routine to realize the chip collecting internal voltage values and transmitting them to another Bluetooth serial port for printing via Bluetooth
- Op amp specification notes
- Variable frequency power supply components: What is the main function of the variable frequency power supply filter capacitor?
- Analysis of the application of TVS tube in the design of mobile phone surge protection
- ST FAE Answer: Reference circuit for replacing BlueNRG's balun BALF-NRG-02D3 with discrete devices