1 #include
2 #define uchar unsigned char //macro definition of unsigned character type
3 #define uint unsigned int //macro definition unsigned integer
4 code uchar seg7code[10]={ 0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90}; //Display segment code digital tube word and
5 uchar wei[4]={0XEf,0XDf,0XBf,0X7f}; //bit control end //bit control code
6 sbit ST=P3^0; //A/D start conversion signal
7 sbit OE=P3^1; //Data output enable signal
8 sbit EOC=P3^2; //A/D conversion end signal
9 sbit CLK=P3^3; //clock pulse
10 uint z,x,c,v,AD0809, date; //define data type
11 /************************************************ ******************
12 Delay function
13 ************************************************* *******************/
14 void delay(uchar t)
15 {
16 uchar i,j;
17 for(i=0;i
18 {
19 for(j=13;j>0;j--);
20 { ;
twenty one }
twenty two }
twenty three }
twenty four /************************************************ **********************
25 digital tube dynamic scanning
26 ************************************************* ************************/
27 void xianshi() //Display function
28 {
29 uint z,x,c,v;
30 z=date/1000; //Calculate the thousandth place
31 x=date%1000/100; //Calculate the hundreds place
32 c=date%100/10; //Find the tenth digit
33 v=date%10; //Find the unit digit
34
35 P2=0XFF;
36 P0=seg7code[z]&0x7f;
37 P2=wei[0];
38 delay(80);
39 P2=0XFF;
40 P0=seg7code[x];
41 P2=wei[1];
42 delay(80);
43 P2=0XFF;
44 P0=seg7code[c];
45 P2=wei[2];
46 delay(80);
47 P2=0XFF;
48 P0=seg7code[v];
49 P2=wei[3];
50 delay(80);
51 P2=0XFF;
52 }
53 /************************************************ *************************
54 CLK oscillation signal
55 ************************************************* *************************/
56 void timer0() interrupt 1 //Timer 0 working mode 1
57 {
58
59 TH0=(65536-2)/256; //Reload count initial value
60 TL0=(65536-2)%256; //Reload count initial value
61 CLK=!CLK; //Invert
62 }
63
64 /************************************************ *************************
65 Main function
66 ************************************************* *************************/
67 void main()
68 {
69 TMOD=0X01; //Timer interrupt 0
70
71 CLK=0; //The initial value of the pulse signal is 0
72 TH0=(65536-2)/256; //initial value of high 8 bits of timing time
73 TL0=(65536-2)%256; //initial value of the lower eight bits of the timing time
74 EA=1; //Open CPU interrupt
75 ET0=1; //Open T/C0 interrupt
76 TR0=1;
77 while(1) // infinite loop
78 {
79 ST=0; // Make the acquisition signal low
80 ST=1; //Start data conversion
81 ST=0; //Stop data conversion
82 while(!EOC); //Wait for data conversion to complete
83 OE=1; //Enable data output signal
84 AD0809=P1; //Read data
85 OE=0; //Turn off data output enable signal
86 if(AD0809>=251) //The voltage displayed cannot exceed 5V
87 AD0809=250;
88 date=AD0809*20; //The data value displayed by the digital tube, where 20 is the milliampere value of the collected data
89 xianshi(); //digital tube display function
90
91 }
92 }
Previous article:Customize the reg52.h header file (key knowledge points of microcontroller learning)
Next article:Smoke sensor based on AT89C51 microcontroller
- 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
- Red Hat announces definitive agreement to acquire Neural Magic
- 5G network speed is faster than 4G, but the perception is poor! Wu Hequan: 6G standard formulation should focus on user needs
- SEMI report: Global silicon wafer shipments increased by 6% in the third quarter of 2024
- OpenAI calls for a "North American Artificial Intelligence Alliance" to compete with China
- OpenAI is rumored to be launching a new intelligent body that can automatically perform tasks for users
- Nidec Intelligent Motion is the first to launch an electric clutch ECU for two-wheeled vehicles
- Nidec Intelligent Motion is the first to launch an electric clutch ECU for two-wheeled vehicles
- ASML provides update on market opportunities at 2024 Investor Day
- Arm: Focusing on efficient computing platforms, we work together to build a sustainable future
- AMD to cut 4% of its workforce to gain a stronger position in artificial intelligence chips
- Could you please advise what is wrong with this circuit?
- USB power supply and DC power supply issues
- Analysis of the advantages of single chip microcomputer in power supply design application
- Is it possible to use the same set of programs for zstack router and terminal?
- How to use PNP and NPN transistors
- These are two different power supplies. Can I collect the voltage drop of R0? Get the AD value of the voltage, divide it by the resistance value, and then...
- stm32f103vet6 industrial control board and 485 protocol sensor
- Renesas CPK-RA6M4 Development Board Review ----ADC
- EEWORLD University - Cadence Allegro 17.4 Quadcopter Full Zero-Based Introductory Course
- How to find MSP430 program examples on TI's official website