Requirements: The digital tube starts displaying from 0. Press a key once (and the internal interrupt, it will naturally enter an interrupt once every second). When an interrupt is entered, the number on the digital tube increases by 1 until it reaches 999, and then starts from 0 again.
Connection: P10 to L7, potentiometer to DC motor, pulse output to P32, CS1 to digital tube CS
#include
typedef unsigned char uchar;
xdata uchar LED_CS _at_ 0x9000;
xdata uchar LED_OUTSEG _at_ 0x9004;
xdata uchar LED_OUTBIT _at_ 0x9002;
sbit P10=P1^0;
fly n=0;
unsigned int Count=0;
code unsigned char LEDMAP[]={
//Eight-segment tube display code
0x3f, 0x06, 0x5b, 0x4f, 0x66, 0x6d, 0x7d, 0x07,
0x7f, 0x6f, 0x77, 0x7c, 0x39, 0x5e, 0x79, 0x71
};
code unsigned char LEDWED[]= {0x20,0x10,0x08,0x04,0x02,0x01};
//Display buffer
uchar led_buf[]={0,0,0};
void delay(unsigned char ms)
{
unsigned char i;
while(ms--)
{
for(i = 0; i < 50; i++);
}
}
void ADcal()
{
led_buf[0]=Count/100;//hundreds place
led_buf[1]=Count/10%10;//ten digit
led_buf[2]=Count%10;
}
//Open time interrupt
void initTime(){
IE=0x83;
TR0=1;
}
//Open external interrupt
void initOut(){
IE=0x83;
IT0=1;
}
void timer0() interrupt 1
{
TH0=(65535-50000)/256;
TL0=(65535-50000)%256;
n++;
if(n==2)
{
P10=1;
delay(20);
P10=0;
delay(20);
Count++;
if(Count>=999)
{
Count=0;
}
}
}
void out0() interrupt 0
{
Count++;
if(Count>=999)
{
Count=0;
}
}
void main()
{
unsigned int i=0;
initOut(); //Open external interrupt'
initTime();
TH0=(65535-50000)/256;
TL0=(65535-50000)%256;
delay(10);
while(1)
{
ADcal();
LED_CS=0;
if(i==0)
{
LED_OUTSEG=LEDMAP[led_buf[i]];
}
if(i==1)
{
LED_OUTSEG=LEDMAP[led_buf[i]];
}
if(i==2)
{
LED_OUTSEG=LEDMAP[led_buf[i]];
}
LED_OUTBIT=LEDWED[i];
i++;
i=i%3;
delay(10);
}
}
Previous article:Password lock system based on 51 single chip microcomputer, serial communication and ASP.NET
Next article:Generates several different waveforms
- 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?
- STMicroelectronics discloses its 2027-2028 financial model and path to achieve its 2030 goals
- 2024 China Automotive Charging and Battery Swapping Ecosystem Conference held in Taiyuan
- State-owned enterprises team up to invest in solid-state battery giant
- The evolution of electronic and electrical architecture is accelerating
- The first! National Automotive Chip Quality Inspection Center established
- BYD releases self-developed automotive chip using 4nm process, with a running score of up to 1.15 million
- GEODNET launches GEO-PULSE, a car GPS navigation device
- Should Chinese car companies develop their own high-computing chips?
- Infineon and Siemens combine embedded automotive software platform with microcontrollers to provide the necessary functions for next-generation SDVs
- Continental launches invisible biometric sensor display to monitor passengers' vital signs
- Delay function
- Design of wireless wide area Internet of Things application system based on LORA
- Experience in using TI DSP/BIOS and CCS
- UPS system monitoring software and network management technology
- [2022 Digi-Key Innovation Design Competition] ESP32S2 WIF Networking
- [NXP Rapid IoT Review] + Unboxing the real thing brings back a lot of thoughts!
- TMS320F28335 startup process
- How to analyze the principle of totem pole circuit?
- Encoder Problems
- How does TI's MSP430 microcontroller (MCU) achieve both low power consumption and high performance?