ATMEGA16L realizes the cycle display program of time and temperature sharing

Publisher:数字火花Latest update time:2019-11-09 Source: 51heiKeywords:ATMEGA16L Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

//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;

               }

          }

        }


Keywords:ATMEGA16L Reference address:ATMEGA16L realizes the cycle display program of time and temperature sharing

Previous article:Two-wheeled balancing robot controller code
Next article:How much do you know about AVR microcontrollers?

Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号