Today I made a little thing: the digital tube displays the change value of the proximity switch. The proximity switch is connected to the microcontroller through external interrupt 0; the digital tube reading increases to 50 and then clears to zero;
#include #include #define uchar unsigned char #define uint unsigned int #define NoOp 0x00 // No operation register #define Digit0 0x01 // Digital tube 1 register #define Digit1 0x02 // Digital tube 2 register #define Digit2 0x03 // Digital tube 3 register #define Digit3 0x04 // Digital tube 4 register #define Digit4 0x05 // Digital tube 5 register #define Digit5 0x06 // Digital tube 6 register #define Digit6 0x07 // Digital tube 7 register #define Digit7 0x08 // Digital tube 8 register #define DecodeMode 0x09 // Decode mode register #define Intensity 0x0a // Brightness register #define ScanLimit 0x0b // Scanning bit number register #define ShutDown 0x0c // Low power mode register #define DisplayTest 0x0f // Display test register #define ShutdownMode 0x00 // Low power consumption mode #define NormalOperation 0x01 // Normal operation mode #define ScanDigit 0x07 // Scan digit setting, display 8-digit digital tube #define DecodeDigit 0xff // Decode setting, all 8 bits are BCD code #define IntensityGrade 0x0a // Brightness level setting #define TestMode 0x01 // Display test mode, #define TextEnd 0x00 // Display test ends and resume normal working mode sbit DIN = P0^3; //Serial data input sbit CLK = P0^4; //Serial clock sbit LOAD = P0^5; // Display data latch control uchar DisBuffer[8]={0,0,0,0,0,0,0,0}; //Display buffer 0x06 uchar a[]={0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09}; uchar num11; /* Delay t milliseconds*/ void delay(uint a) {uchar x,y; for(x=a;x>0;x--) for(y=110;y>0;y--); } /* Write byte (8 bits) to MAX7219 */ void SendChar (uchar ch) { uchar i,temp; _nop_(); for(i=0;i<8;i++) { temp=ch&0x80; ch=ch<<1; if(temp) { DIN=1; CLK=0; CLK=1; } else { DIN=0; CLK=0; CLK=1; } } } /* Write word (16 bits) to MAX7219 */ void WriteWord (uchar addr,uchar num) { LOAD=0; _nop_(); SendChar(addr); _nop_(); SendChar(num); _nop_(); LOAD=1; //Latch into the corresponding register } /* MAX7219 initialization */ void InitDisplay (void) { WriteWord (ScanLimit,ScanDigit); // Set the scan limit WriteWord (DecodeMode,DecodeDigit); // Set the decoding mode WriteWord (Intensity,IntensityGrade); // Set the brightness WriteWord (ShutDown,NormalOperation); // Set to normal working mode } //show // External interrupt 0 void show1(uchar dat) {uchar shi,ge; shi=dat/10; ge=dat%10; delay(1); WriteWord (Digit6,a[ge]); WriteWord (Digit7,a[shi]); } /* Main function */ void main(void) { InitDisplay (); // MAX7219 initialization IE=0x81; IT0=1; show1(0); WriteWord (Digit1,0xff); WriteWord (Digit0,0xff); WriteWord (Digit2,0xff); WriteWord (Digit3,0xff); WriteWord (Digit4,0xff); WriteWord (Digit5,0xff); while(1) { if(num11==50) num11=0; show1(num11); } } void exint0(void)interrupt 0 { num11++; InitDisplay(); delay(1); show1(num11); delay(1); }
Previous article:L297, L298 drive stepper motor schematic diagram proteus simulation + program LCD display speed
Next article:Design of Waveform Generator Based on 51 Single Chip Microcomputer
Recommended ReadingLatest update time:2024-11-16 11:25
- Popular Resources
- Popular amplifiers
- Siemens Motion Control Technology and Engineering Applications (Tongxue, edited by Wu Xiaojun)
- Modern Product Design Guide
- Modern arc welding power supply and its control
- Small AC Servo Motor Control Circuit Design (by Masaru Ishijima; translated by Xue Liang and Zhu Jianjun, by Masaru Ishijima, Xue Liang, and Zhu Jianjun)
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
- [NUCLEO-L552ZE review] + Summary of voice control home appliance experiment
- ST NUCLEO-H743ZI Review Summary
- Animation showing the working principle of capacitive sensors and capacitive headphones
- 【New Year's Festival Competition】+Flying Yingge Dance
- MSP430f5529 car source code
- 【EasyARM-RT1052 Review】+ Transplantation and use of Fatfs file system based on SD card
- If you don't work in the electronics industry, what else can you do?
- 【Goodbye 2021, Hello 2022】2021 calendar
- Theoretical basis of the movie "The Wandering Earth"
- Satellite Internet in One Picture