//ICC-AVR application builder: 2/13 20:52:33
/***********************************************************************************
* Copyright:
*
* MCU: ATMAGE16L
* Crystal: External 8MHz
* Compiler: ICC 7.22
*
* File name: main.c
* Author: Muzi Studio
* Version: 1.0
* Completion Date:
* Function description: Under 12M crystal oscillator, realize the cycle display of time and temperature
***********************************************************************************/
//#include #include #include #define LED0 PORTD #define LED1 PORTB #define BEEL_OFF PORTC |= BIT(0); #define BEEL_ON PORTC &= ~BIT(0); unsigned char i=0,f=0,n=0,xx=0,fangduan=0,ADC_LL=0,ADC_HH=0; unsigned int x = 0,t=0,t1=0,s0=0,s1=0,m0=0,m1=0,h0=0,h1=0,s=0,h=8,m=15,mid=0,a=0,g=240,b=180,c,d,e,o=1,p,q,r,T,ADC_H=0; unsigned char tab[16] = {0X3f,0X06,0X5b,0X4f,0X66,0X6d,0X7d,0X07,0X7f,0X6f,0X77,0X7c,0X39,0X5e,0X79,0X71}; //Normal font unsigned char tab1[10] = {0Xbf,0X86,0Xdb,0Xcf,0Xe6,0Xed,0Xfd,0X87,0Xff,0Xef}; // Font with decimal point unsigned char tab2[2] = {0X61,0X40}; // degree C, "-" sign unsigned int CBM[130] = {19,33,38,44,56,59,61,63,65,67,69,71,73,76,78,81,83,86,89,92,94, 98,101,104,108,111,115,119,123,127,131,135,140,145,149,154,16 0,165,171,176,182,188,194,200,207,214,220,228,235,243,250,258,267,275,284,293,302,311,321,331,341,351,361,372,382,393,405,416 ,428,439,451,463,475,487,500,512,525,537,550,562,576,588,601,613,626,638,645,651,657,663,675,688,699,711,723,734,746,757,768, 779,789,799,809,818,828,837,846,855,863,871,878,886,893,900,907,913,919,925,931,936,941,946,951,952,959,963,967,970,980,990}; unsigned int CBT[130] = {1190,995,950,900,820,800,790,780,770,760,750,740,730,720,710,700,690,680,670,660,650,640,630,620,610,600,590,580,570,560,550,540,530,519,5 11,501,490,481,470,460,450,440,430,420,410,400,391,380,371,360,351,341,330,320,310,300,290,281,270,260,250,240,230,220,210,200,190,180,170, 160,150,140,130,120,110,100,90,80,70,60,50,40,30,20,10,0,2005,2010,2015,2020,2030,2040,2050,2060,2070,2080,2090,2100,2110,2120, 2130,2140,21 50,2160,2170,2180,2190,2200,2210,2220,2230,2240,2250,2260,2270,2280,2290,2300,2310,2320,2330,2340,2350,2360,2370,2380,2390, 2400,2450,2460}; /*********************************************************************************** * Function name: WDCB() * Entry parameters: * Export parameters: * Function description: Temperature lookup table ***********************************************************************************/ int WDCB() //The int type function is used to make the return command effective! Once the result is found, FOR will be jumped out to save CPU resources. { for(c=0;c<129;c++) { if(CBM[c]==ADC_H) { d=c; T = CBT[d]; if(T>2000) { f=1; T=(T-2000)/10; } return ; // Once the result is found, FOR will be jumped out to save CPU resources. } if(c<=84 & ADC_H>CBM[c] & ADC_H T=CBT[c]-((ADC_H-CBM[c])*((CBT[c]-CBT[c+1])*10/(CBM[c+1]-CBM[c])))/10; //The actual temperature is converted according to the interval ratio between CBM[] and CBT[], which can greatly reduce the array capacity without losing accuracy. f=0; //Judge positive and negative temperature return ;//Using the int type function is to make the return command effective! Once the result is found, FOR will be jumped out to save CPU resources. } if(c>=85 & ADC_H>CBM[c] & ADC_H T=((CBT[c]+((ADC_H-CBM[c])*((CBT[c+1]-CBT[c])*10/(CBM[c+1]-CBM[c])))/10)-2000)/10; //The actual temperature is converted according to the interval ratio between CBM[] and CBT[], which can greatly reduce the array capacity without losing accuracy. f=1; //Judge positive and negative temperature return ;//jump out of FOR once the result is found, saving CPU resources. It seems that whether or not T is added after return has no effect on the returned T value. } } } /*********************************************************************************** * Function name: Disp_Time() * Entry parameters: * Export parameters: * Function description: Display time ***********************************************************************************/ void Disp_Time(void) { //BEEL_ON; for(i=0;i<4;i++) { PORTD = 0X1F; if(xx==1) {q=a%30;} //Set the flashing period if(xx==2) {r=a%30;} //Set the flashing cycle if(i==0) { LED1 = tab[m0]; if(q<15 | o==0) //q sets the screen on time, o is a short period of time after pressing a key, and the condition for setting o is to prevent the time calibration operation from flashing too quickly. {PORTD&= ~BIT(3);} else {PORTD|= BIT(3);} //Black screen } if(i==1) { LED1 = tab[m1]; PORTD|= BIT(4); //Port B position 4 is 1, ":" if(q<15 | o==0) //q sets the screen on time, o is a short period of time after pressing a key, and the condition for setting o is to prevent the time calibration operation from flashing too quickly. {PORTD&= ~BIT(2);} else {PORTD|= BIT(2);} } if(i==2) { LED1 = tab[h0]; if(r<15 | o==0) //q sets the screen on time, o is a short period of time after pressing the key, and the condition of setting o is to prevent the time calibration operation from flashing too quickly. {PORTD&= ~BIT(1);} else {PORTD|= BIT(1);} } if(i==3) { LED1 = tab[h1]; if(r<15 | o==0) //q sets the screen on time, o is a short period of time after pressing the key, and the condition of setting o is to prevent the time calibration operation from flashing too quickly. {PORTD&= ~BIT(0);} else {PORTD|= BIT(0);} } delay_ms(60); PORTB = 0X00; }//FOR tail } /*********************************************************************************** * Function name: Disp_Wd() * Entry parameters: * Export parameters: * Function description: Display temperature ***********************************************************************************/ void Disp_Wd(void) { //BEEL_OFF; if(f==0) //display positive temperature { for(i=0;i<4;i++) { //PORTB = 0X00; if(i==0) { LED1 = tab2[0]; PORTD&= ~BIT(3); } if(i==1) { LED1 = tab[m0]; PORTD&= ~BIT(2); } if(i==2) { LED1 = tab1[m1]; PORTD&= ~BIT(1); } if(i==3) { LED1 = tab[h0]; PORTD&= ~BIT(0); } PORTD|= BIT(5); //Port B position 5 is 1, "upper point" delay_ms(60); PORTD = 0X0F; } } else //Display negative temperature { for(i=0;i<4;i++) { //PORTB = 0X0F; //PORTB = 0X00; if(i==0) { LED1 = tab2[0]; PORTD&= ~BIT(3); } if(i==1) { LED1 = tab[m0]; PORTD&= ~BIT(2); } if(i==2) { LED1 = tab[m1]; PORTD&= ~BIT(1); } if(i==3) { LED1 = tab2[1]; PORTD&= ~BIT(0); } PORTD|= BIT(5); //Port B position 5 is 1, "upper point" delay_ms(60); PORTD = 0X0F; } } }
Previous article:Two-wheeled balancing robot controller code
Next article:How much do you know about AVR microcontrollers?
- Popular Resources
- Popular amplifiers
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
- Huawei's Strategic Department Director Gai Gang: The cumulative installed base of open source Euler operating system exceeds 10 million sets
- Download from the Internet--ARM Getting Started Notes
- Learn ARM development(22)
- Learn ARM development(21)
- Learn ARM development(20)
- Learn ARM development(19)
- Learn ARM development(14)
- Learn ARM development(15)
- Analysis of the application of several common contact parts in high-voltage connectors of new energy vehicles
- Wiring harness durability test and contact voltage drop test method
- 【TI recommended course】#Lecture on basic knowledge of electronic circuits#
- Low-pass filter waveform distortion problem
- Questions about PCB antenna
- [RVB2601 Creative Application Development] RVB2601 Hardware Part--1
- #Servo What is a servo?
- Questions about rotary transformers
- Help, the turn-off speed problem related to the MOS tube drive resistor
- SIwave Chinese Training Manual
- Job hunting after the epidemic
- What are the advantages of machine vision defect detection systems?