/*
Timer 0 controls the flashing time of the LED; counter 1 controls the display of the digital tube
*/
#include #define uint unsigned int #define uchar unsigned char sbit DULA = P2^6; sbit WELA = P2^7; sbit LED1 = P1^0; void display(uint i); void delay(uint z); uchar code arry[] = {0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f}; void delay(uint z) { uint a,b; for(a = z;a > 0;a--){ for(b = 114;b > 0;b--); } } void display(uint i) { uint one,two; //This is two digits. If you use a three-digit digital tube, set a hundred digit, then the hundred digit is i/100; the ten digit is i%100/10; the one digit is i%10 one = i / 10; two = i % 10; P0 = 0xff; WELA = 1; //Open bit selection P0 = 0xfe; WELA = 0; DULA = 1; //Open segment selection P0 = arry[one]; DULA = 0; delay(5); P0 = 0xff; WELA = 1; //Open bit selection P0 = 0xfd; WELA = 0; DULA = 1; //Open segment selection P0 = arry[two]; DULA = 0; delay(5); } void main(void) { uchar a; TR0 = 1; //Turn on timer 0 TR1 = 1; //Turn on timer 1 TMOD = 0x61; //Set T1 as counter, working mode 2; T0 as timer, working mode 1 TH0 = 0x4b; TL0 = 0xfc; TH1 = 0; //This is an 8-bit auto-reload register TL1 = 0; //When TL1 is full, reload the value of TH1 while(1){ if(TF0 == 1){ TH0 = 0x4b; //Reload initial value TL0 = 0xfc; TF0 = 0; a++; } if(a == 20){ LED1 = ~LED1; //Initially light up the LED, and each inversion changes the state a = 0; } display(TL1); //Use Dupont wire to connect P10 port and external pin P35 (T1 port); //The counter is based on each external pulse, the counter will be +1 //So when the state of LED1 changes once, a different level signal will be generated. //The Dupont line can make T1 port sense it, and the counter will be +1 } }
Previous article:Use the interrupt of timer T0 to control the flashing of 8-bit LED
Next article:Programming control 8-bit LED cycle lighting
- Popular Resources
- Popular amplifiers
- Learn ARM development(16)
- Learn ARM development(17)
- Learn ARM development(18)
- Embedded system debugging simulation tool
- A small question that has been bothering me recently has finally been solved~~
- Learn ARM development (1)
- Learn ARM development (2)
- Learn ARM development (4)
- Learn ARM development (6)
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- LED chemical incompatibility test to see which chemicals LEDs can be used with
- Application of ARM9 hardware coprocessor on WinCE embedded motherboard
- What are the key points for selecting rotor flowmeter?
- LM317 high power charger circuit
- A brief analysis of Embest's application and development of embedded medical devices
- Single-phase RC protection circuit
- stm32 PVD programmable voltage monitor
- Introduction and measurement of edge trigger and level trigger of 51 single chip microcomputer
- Improved design of Linux system software shell protection technology
- What to do if the ABB robot protection device stops
- ASML predicts that its revenue in 2030 will exceed 457 billion yuan! Gross profit margin 56-60%
- Detailed explanation of intelligent car body perception system
- How to solve the problem that the servo drive is not enabled
- Why does the servo drive not power on?
- What point should I connect to when the servo is turned on?
- How to turn on the internal enable of Panasonic servo drive?
- What is the rigidity setting of Panasonic servo drive?
- How to change the inertia ratio of Panasonic servo drive
- What is the inertia ratio of the servo motor?
- Is it better for the motor to have a large or small moment of inertia?
- Using registers to do STM8 UART1 error request help
- BearPi-HM Nano Development Board Review 0 Unboxing and Development Environment Setup
- Let's discuss how many people you think should be invited.
- Qinheng CH37X series interface chip application reference example
- I found another DK IOT STUDIO online IDE that runs RAPID IOT. I guess they are the same but distributed on different websites.
- ECG-based heart rate monitoring using the LaunchPad Value Line development kit for the MSP430G2452 microcontroller
- [GD32L233C-START Review] - VII. SPI mode driving 1.5-inch OLED screen
- My creative plan and functional implementation plan
- The more I read, the more I like these sentences. Each sentence is more philosophical than the last, and each sentence is very inspiring.
- 【Want to buy】College students want to buy ATmega16 development board