/**************************************** Use timer to maintain digital tube display Now the digital tube display is increasing. ******************************************/ #includeunsigned int cnt; unsigned char shu[8]; unsigned char aa; const unsigned char duanma[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07, 0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71}; const unsigned char weima[]={0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f}; /****************************************** Data conversion subfunction ***************************************/ void change(unsigned int i) { shu[0]=duanma[i/1000]; shu[1]=duanma[i/100%10]; shu[2]=duanma[i%100/10]; shu[3]=duanma[i%10]; } /**************************************** Delay function ******************************************/ void delay(unsigned int t) { unsigned int x,y; for(x=t;x>0;x--) for(y=100;y>0;y--); } /**************************************** Display Function ******************************************/ void display(unsigned char i) { PORTB = 0X00; PORTA|=0X01; PORTA&=0XFE; PORTB =weima[i]; PORTA|=0x02; PORTA&=0XFD; PORTB=shu[i]; PORTA|=0X01; PORTA&=0XFE; } /****************************************** Port initialization ***************************************/ void init_port(void) { PORTA=0XFF; DDRA=0XFF; PORTB=0XFF; DDRB=0XFF; } /****************************************** Timer 0 initialization ***************************************/ void timer0_init(void) { TCNT0=0X83; //1MS timing initial value TCCR0=0X03; //The timer count pre-division frequency is 64 } /****************************************** Timer 0 service function ***************************************/ #pragma interrupt_handler timer0_ovf_isr:10 void timer0_ovf_isr(void) { TCNT0=0X83; //Reinstall the initial timing value of 1ms if(++aa>3) aa=0; switch(aa) { case 0: display(0);break; case 1: display(1);break; case 2: display(2);break; case 3: display(3);break; default:break; } } void main(void) { init_port(); //IO port initialization timer0_init(); //Timer 1 initialization TIMSK=0X01; //Enable T0 interrupt SREG=0X80; //Enable general interrupt while(1) { cnt++; delay(1000); change(cnt); } }
Previous article:ATmega16L-EEPROM write and read experiment
Next article:ATmega16L-Sports Stopwatch Design
Recommended ReadingLatest update time:2024-11-16 16:03
- Popular Resources
- Popular amplifiers
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
- Many standards for automotive embedded systems
- DIY a car remotely controlled by WeChat
- C2000 MCU Boot Process Analysis - Taking TMS320F28069 as an Example
- [New Year's Flavor Competition] + Show off your New Year's Eve dinner and experience ice and snow tourism in the north!
- In STM32F103RCT6, I use the state machine method to add buttons, but I don't want the buttons to work in a function.
- [2022 Digi-Key Innovation Design Competition] Revised version of 2-DOF pan-tilt robot control platform
- Selling a brand new STM32F412 development board
- Award-winning review: Sensirion SEK-SVM40 is coming in the new year, easily monitor indoor air quality and test whether it is "good luck"
- [Domestic digital isolation chip replacement] Nanochip MSI series replaces ADI ADUM and TI IOS series isolation chips
- [Xianji HPM6750EVKMINI Review] 2#OLED module and LVGL routine test