1. Use proteus to draw a simple circuit diagram for subsequent simulation
2. Programming
/********************************************************************************************************************
---- @Project: LED-74HC595
---- @File: main.c
---- @Edit: ZHQ
---- @Version: V1.0
---- @CreationTime: 20200701
---- @ModifiedTime: 20200701
---- @Description: The 1 key corresponds to S1, the 2 key corresponds to S2, the 3 key corresponds to S3, the 9 key corresponds to S9, the 0 key corresponds to S10. The plus key corresponds to S13, the equal key corresponds to S14, and the clear and reset key corresponds to S16. Other keys are not used.
---- Common addition calculator functions. Continuous addition function.
---- This program has 2 windows.
---- The first window: the window of original data and operation results. For example, the summand in the addition operation
---- The second window: the second data window involved in the operation. For example, the addend in the addition operation
---- Microcontroller: AT89C52
****************************************************************************************************************************/
#include "reg52.h"
/*——————Macro definition——————*/
#define FOSC 11059200L
#define T1MS (65536-FOSC/12/500) /*0.5ms timer calculation method in 12Tmode*/
#define const_voice_short 40 /*Duration of the buzzer short call*/
#define const_voice_long 900 /*Duration of the long buzzer call*/
#define const_key_time 9 /*Key debounce delay time*/
#define const_1s 96 /*Generates a time base of approximately one second*/
/*——————Variable function definition and declaration——————*/
/*Define the 74HC595 digital tube*/
sbit Dig_Hc595_Sh = P2^0;
sbit Dig_Hc595_St = P2^1;
sbit Dig_Hc595_Ds = P2^2;
/*define buzzer*/
sbit Beep = P2^7;
/*When the pause indicator light is on, it means pause*/
sbit LED = P3^5;
/*Define buttons*/
sbit Key_S1 = P0^0; /*First line input*/
sbit Key_S2 = P0^1; /*Second line input*/
sbit Key_S3 = P0^2; /*Third line input*/
sbit Key_S4 = P0^3; /*Fourth line input*/
sbit Key_D1 = P0^4; /*First column input*/
sbit Key_D2 = P0^5; /*Second column input*/
sbit Key_D3 = P0^6; /*Third column input*/
sbit Key_D4 = P0^7; /*Fourth column input*/
unsigned char ucKeyStep = 1; /*Key scan step variable*/
unsigned int uiKeyTimeCnt = 0; /*Key debounce delay counter*/
unsigned char ucKeyLock = 0; /*Variable flag for self-locking after key triggering*/
unsigned char ucRowRecord = 1; /*Record the current scanned column*/
unsigned char ucKeySec = 0; /*The number of the key being triggered*/
unsigned char ucDigShow8 = 0; /*The content to be displayed on the 8th digital tube*/
unsigned char ucDigShow7 = 0; /*The content to be displayed on the 7th digital tube*/
unsigned char ucDigShow6 = 0; /*The content to be displayed on the 6th digital tube*/
unsigned char ucDigShow5 = 0; /*The content to be displayed on the 5th digital tube*/
unsigned char ucDigShow4 = 0; /*The content to be displayed on the 4th digital tube*/
unsigned char ucDigShow3 = 0; /*The content to be displayed on the 3rd digital tube*/
unsigned char ucDigShow2 = 0; /*The content to be displayed on the second digital tube*/
unsigned char ucDigShow1 = 0; /*The content to be displayed on the first digital tube*/
unsigned char ucDigDot1 = 0;
unsigned char ucDigDot2 = 0;
unsigned char ucDigDot3 = 0;
unsigned char ucDigDot4 = 0;
unsigned char ucDigDot5 = 0;
unsigned char ucDigDot6 = 0;
unsigned char ucDigDot7 = 0;
unsigned char ucDigDot8 = 0;
unsigned char ucDigShowTemp = 0; /*temporary intermediate variable*/
unsigned char ucDisplayDriveStep = 1; /*Step variable for dynamic scanning of digital tube*/
unsigned char ucWd = 1; /*Core variable of this program, window display variable. Similar to the variable of the first-level menu. Represents the display of different windows. */
unsigned char ucDisplayUpdate = 1; /*Update display flag*/
unsigned long ulSource = 0; /*Original data, such as the addend in addition operation*/
unsigned long ulOther = 0; /*Another data involved in the operation, such as the addend in the addition operation*/
unsigned long ulResult = 0; /*Calculation result*/
unsigned char ucOperator = 0; /*Operation symbol. 0 means no operation symbol is currently selected. 1 means the current operator is addition. */
unsigned int uiVoiceCnt = 0; /*Buzzer beeping duration counter*/
void Dig_Hc595_Drive(unsigned char, unsigned char);
/*Common cathode digital tube character table obtained based on the schematic diagram*/
code unsigned char Dig_Table[] =
{
0x3f, /*0 sequence number 0*/
0x06, /*1 Sequence number 1*/
0x5b, /*2 Sequence number 2*/
0x4f, /*3 sequence number 3*/
0x66, /*4 Sequence number 4*/
0x6d, /*5 sequence number 5*/
0x7d, /*6 Sequence number 6*/
0x07, /*7 Sequence number 7*/
0x7f, /*8 sequence number 8*/
0x6f, /*9 sequence number 9*/
0x00, /*Do not display serial number 10*/
0x40, /*- Serial number 11*/
0x73, /*P sequence number 12*/
};
/**
* @brief Timer 0 initialization function
* @param None
* @retval initialize T0
**/
void Init_T0(void)
{
TMOD = 0x01; /*set timer0 as mode1 (16-bit)*/
TL0 = T1MS; /*initial timer0 low byte*/
TH0 = T1MS >> 8; /*initial timer0 high byte*/
}
/**
* @brief peripheral initialization function
* @param None
* @retval Initialize peripheral
* Transfer the contents displayed by the digital tube to the following variable interfaces to facilitate the writing of higher-level window programs in the future.
* Simply change the content of the corresponding variables below to display the numbers you want.
**/
void Init_Peripheral(void)
{
ET0 = 1;/*Enable timer interrupt*/
TR0 = 1;/*Start timing interrupt*/
EA = 1;/*Open the general interrupt*/
}
/**
* @brief initialization function
* @param None
* @retval initialize the MCU
**/
void Init(void)
{
LED = 1;
Beep = 1;
Dig_Hc595_Drive(0x00, 0x00); /*Turn off all LED lights driven by the other two 74HC595*/
Init_T0();
}
/**
* @brief delay function
* @param None
* @retval None
**/
void Delay_Long(unsigned int uiDelayLong)
{
unsigned int i;
unsigned int j;
for(i=0;i for(j=0;j<500;j++) /*Number of empty instructions in the embedded loop*/ { ; /*A semicolon is equivalent to executing an empty statement*/ } } } /** * @brief delay function * @param None * @retval None **/ void Delay_Short(unsigned int uiDelayShort) { unsigned int i; for(i=0;i ; /*A semicolon is equivalent to executing an empty statement*/ } } /** * @brief Driver function for displaying digital tube fonts * @param None * @retval The principle of dynamically driving the digital tube * In the eight-digit digital tube, at any moment, only one of the digital tubes is displayed at a time, and the other seven digital tubes are * By setting its common bit com to a high level to turn off the display, as long as the speed of switching the screen is fast enough, human vision cannot distinguish it, and it feels like eight digital tubes * are lit at the same time. In the following dig_hc595_drive(xx,yy) function, the first parameter xx is the pin that drives the digital tube segment seg, and the second parameter yy is the driver * The pin of the common position com of the digital tube. **/ void Display_Drive(void) { switch(ucDisplayDriveStep) { case 1: /*Display the first position*/ ucDigShowTemp = Dig_Table[ucDigShow1]; if(ucDigDot1 == 1) { ucDigShowTemp = ucDigShowTemp | 0x80; /*Display decimal point*/ } Dig_Hc595_Drive(ucDigShowTemp, 0xfe); break; case 2: /*Display the second position*/ ucDigShowTemp = Dig_Table[ucDigShow2]; if(ucDigDot2 == 1) { ucDigShowTemp = ucDigShowTemp | 0x80; /*Display decimal point*/ } Dig_Hc595_Drive(ucDigShowTemp, 0xfd); break; case 3: /*Display the 3rd digit*/ ucDigShowTemp = Dig_Table[ucDigShow3]; if(ucDigDot3 == 1) { ucDigShowTemp = ucDigShowTemp | 0x80; /*Display decimal point*/ } Dig_Hc595_Drive(ucDigShowTemp, 0xfb); break; case 4: /*Display the 4th digit*/ ucDigShowTemp = Dig_Table[ucDigShow4]; if(ucDigDot4 == 1) { ucDigShowTemp = ucDigShowTemp | 0x80; /*Display decimal point*/ } Dig_Hc595_Drive(ucDigShowTemp, 0xf7); break; case 5: /*Display the 5th digit*/ ucDigShowTemp = Dig_Table[ucDigShow5]; if(ucDigDot5 == 1) { ucDigShowTemp = ucDigShowTemp | 0x80; /*Display decimal point*/ } Dig_Hc595_Drive(ucDigShowTemp, 0xef); break; case 6: /*Display the 6th digit*/ ucDigShowTemp = Dig_Table[ucDigShow6]; if(ucDigDot6 == 1) { ucDigShowTemp = ucDigShowTemp | 0x80; /*Display decimal point*/ } Dig_Hc595_Drive(ucDigShowTemp, 0xdf); break; case 7: /*Display the 7th digit*/ ucDigShowTemp = Dig_Table[ucDigShow7]; if(ucDigDot7 == 1) { ucDigShowTemp = ucDigShowTemp | 0x80; /*Display decimal point*/ } Dig_Hc595_Drive(ucDigShowTemp, 0xbf); break; case 8: /*Display the 8th digit*/ ucDigShowTemp = Dig_Table[ucDigShow8]; if(ucDigDot8 == 1) { ucDigShowTemp = ucDigShowTemp | 0x80; /*Display decimal point*/ } Dig_Hc595_Drive(ucDigShowTemp, 0x7f); break; } ucDisplayDriveStep++; /*Display bit by bit*/ if(ucDisplayDriveStep > 8) /*After scanning 8 digital tubes, restart scanning from the first one*/ { ucDisplayDriveStep = 1; } } /** * @brief 595 driver function of digital tube * @param None * @retval * If the digital tube is driven directly by the IO pin of the microcontroller, since the driving speed is too fast, a little delay should be added here or * Use counting delay to delay the time. The purpose is to stay for a while before switching to other digital tubes when switching to each digital tube display in the eight-digit digital tube. * digit digital tube interface, which can increase the display effect. However, since the digital tube is driven indirectly through 74HC595, * When the microcontroller drives 74HC595, the dig_hc595_drive function itself needs to execute many instructions, which is equivalent to delay. * Therefore, there is no need to add a delay function or count delay. **/ void Dig_HC595_Drive(unsigned char ucDigStatusTemp16_09, unsigned char ucDigStatusTemp08_01) { unsigned char i; unsigned char ucTempData; Dig_Hc595_Sh = 0;
Previous article:51 single chip microcomputer realizes digital tube as instrument panel to display the direction, speed and movement of the marquee
Next article:51 single chip microcomputer realizes chess game special timer with digital tube display
- Naxin Micro and Xinxian jointly launched the NS800RT series of real-time control MCUs
- How to learn embedded systems based on ARM platform
- Summary of jffs2_scan_eraseblock issues
- Application of SPCOMM Control in Serial Communication of Delphi7.0
- Using TComm component to realize serial communication in Delphi environment
- Bar chart code for embedded development practices
- Embedded Development Learning (10)
- Embedded Development Learning (8)
- Embedded Development Learning (6)
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- Intel promotes AI with multi-dimensional efforts in technology, application, and ecology
- ChinaJoy Qualcomm Snapdragon Theme Pavilion takes you to experience the new changes in digital entertainment in the 5G era
- Infineon's latest generation IGBT technology platform enables precise control of speed and position
- Two test methods for LED lighting life
- Don't Let Lightning Induced Surges Scare You
- Application of brushless motor controller ML4425/4426
- Easy identification of LED power supply quality
- World's first integrated photovoltaic solar system completed in Israel
- Sliding window mean filter for avr microcontroller AD conversion
- What does call mean in the detailed explanation of ABB robot programming instructions?
- Breaking through the intelligent competition, Changan Automobile opens the "God's perspective"
- The world's first fully digital chassis, looking forward to the debut of the U7 PHEV and EV versions
- Design of automotive LIN communication simulator based on Renesas MCU
- When will solid-state batteries become popular?
- Adding solid-state batteries, CATL wants to continue to be the "King of Ning"
- The agency predicts that my country's public electric vehicle charging piles will reach 3.6 million this year, accounting for nearly 70% of the world
- U.S. senators urge NHTSA to issue new vehicle safety rules
- Giants step up investment, accelerating the application of solid-state batteries
- Guangzhou Auto Show: End-to-end competition accelerates, autonomous driving fully impacts luxury...
- Lotus launches ultra-900V hybrid technology "Luyao" to accelerate the "Win26" plan
- Implementation of the sharpening algorithm on DSP
- AC sine wave boost circuit and simulation results
- RH850 interrupt problem
- [NXP Rapid IoT Review] Rapid IoT Studio with Examples
- K-band Double-balanced Mixer Using GaAs HBT THz Schottky Dio
- wince6.0 serial number
- Which quantity is the same on the same electric force line in an electric field? Which quantity is the same on the same magnetic force line in a magnetic field?
- Deleting the database and running away happened again! Employees working from home destroyed the server, and the company's market value evaporated by 900 million in one day
- What does IAR do before main?
- Design of high linearity low voltage low noise amplifier