-->
Showing posts with label AVR. Show all posts
Showing posts with label AVR. Show all posts

Attepmt to Accessing Keyboad Up and down Key by C programm for a project

By
<div dir="ltr" style="text-align: left;" trbidi="on">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhDK4I6uKmMOILPqNPi34Ip8Jwp2iKWsVp15PjpH9nZMlCEo36DmJom5qQ3M555omOA68qZ0A_Ei5kFY1O_bkQCOqvx5l4XWL4GdcoFuR3GyuMJIp3g8jERYCBfjlaCvGKzSo7hwhd4TDvF/s1600/Capture.PNG" imageanchor="1"><img border="0" data-original-height="604" data-original-width="846" height="456" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhDK4I6uKmMOILPqNPi34Ip8Jwp2iKWsVp15PjpH9nZMlCEo36DmJom5qQ3M555omOA68qZ0A_Ei5kFY1O_bkQCOqvx5l4XWL4GdcoFuR3GyuMJIp3g8jERYCBfjlaCvGKzSo7hwhd4TDvF/s640/Capture.PNG" width="640" /></a>
<br />
<pre class="brush:csharp"></pre>
<pre class="brush:c++"> *<b> main.c</b>
 *
 *  Created on: Aug 12, 2017
 *      Author: thannara123




#include<stdio .h="">
#define FALSE 0
#define TRUE  1  // 0r //!FALSE
struct menu
 {
   char menu_up_key;
   char menu_down_key;
   char menu_enter_key :1; // bit feild 1 bit
 };
struct menu s1= {0}; //s1.menu_up-key =1;
void struct_1( struct menu,const char *menu_display[]);



int main()
{

     const char *menu_display[10];
      menu_display[0] = "Menu0";
      menu_display[1] = "Menu1";
      menu_display[2] = "Menu2";
      menu_display[3] = "Menu3";
      menu_display[4] = "Menu4";
      menu_display[5] = "menu 5";
      menu_display[6] = "menu 6";


       struct_1(s1,menu_display);
             getchar();
             return 0;

      }


void struct_1(struct menu s1 ,const char *menu_display[])
{

     char ch;
      do{
            ch=getch();


            if(ch!='\0')
            {
              ch=getch();
              if(ch=='H')
              {
               s1.menu_up_key++;
               if(s1.menu_up_key==7)
                 s1.menu_up_key =0;
            // printf("UP\n");
                  printf(" %s\n",*(s1.menu_up_key+menu_display));
               }
         else    if(ch=='P')
               {
              s1.menu_up_key--;
              if(s1.menu_up_key==-1)
                  {  s1.menu_up_key =6;
                   goto here;
                  }
                //printf("down\n");

                  here:
         printf("%s\n",*(s1.menu_up_key+menu_display));


                   }

            }
               }
              while(ch!='e');// while oka key
}
</stdio></pre>
<pre class="brush:csharp">/*
 * button_key.c
 *
 * Created: 7/30/2017 12:02:39 PM
 *  Author: Krishna
 */ #include <avr io.h="">
 #include "delay.h"
  #include "button_key.h"
  #include "lcd.h" 
   
void menu_key_display(struct menu s1,const char *menu_display[]);
void UP_Down_Keyvalue(struct menu s1,int i,int j);

 /* Function Key Value For get key  */
int Key_pressed(void)
 {
 while(1){
    if (LEFT_S) {  while(LEFT_S);return 1; }     
 if (RIGHT_S){  while(RIGHT_S);return 2; }
 if (UP_S)  {  while(UP_S); return 3; }
 if (DOWN_S) { while(DOWN_S);return 4 ; }
 if (OK_S) { while(OK_S);return 5 ; }
 }
 }


 /* Function Key Value For Up Key  &amp; Enter*/

 void menu_key_display(struct menu s1,const char *menu_display[])
 {  
  int ch;
   int a;
  int  menu_position =0;
   LCD_DisplayString(menu_display[menu_position]);
            do{ 
   
    repat:         
    ch = Key_pressed();
    if(ch==1||ch==2)
    {
                  if(ch==2)
                    {  if(ch==2)
                   { if(s1.menu_side_key==4)
                     s1.menu_side_key = 0;
                  LCD_Clear();
                  LCD_GoToLine(0);
                              LCD_DisplayString(*((++s1.menu_side_key)+menu_display));
         menu_position=1;           
        
                 }
                      }
                   else if(ch==1)
                   {  
                             if(ch==1)
                    {if(s1.menu_side_key==1 ||s1.menu_side_key==0)
                      {
                    s1.menu_side_key=5;
                      }
                      LCD_Clear();
                            LCD_DisplayString(*((--s1.menu_side_key)+menu_display));                           
          menu_position=1;  
                         }
                   } 
          }
     
    if(menu_position==0)
    goto repat;
        }while(ch!=5);
      
        a = s1.menu_side_key;
  switch(a)
     {
 case 1: // set time
          {
    LCD_Clear();
       LCD_GoToLine(0);
       LCD_DisplayString(menu_display[5]);
    LCD_GoToLine(1);
    LCD_DisplayString("  HH:MM:SS:PM/AM");
    UP_Down_Keyvalue(s1,2,4);   
          break;
          }
 case 2: // Set date
        {
         LCD_Clear();
         LCD_GoToLine(0);
         LCD_DisplayString(menu_display[6]);
      LCD_GoToLine(1);
      LCD_DisplayString("  DD:MM:YY");
      UP_Down_Keyvalue(s1,2,3);    
         break;
        }

 case 3: // set alarm
          {
         LCD_Clear();
            LCD_GoToLine(0);
         LCD_DisplayString(menu_display[7]);
      LCD_GoToLine(1);
      LCD_DisplayString(" HH:MM:SS:AM/PM");
      UP_Down_Keyvalue(s1,2,4);     
          break;
             }
 case 4:  // set alarm
           {
            LCD_Clear();
          LCD_GoToLine(0);
          LCD_DisplayString(menu_display[8]);
    LCD_GoToLine(1);
    LCD_DisplayString("  HH:MM:SS:PM/AM");
    UP_Down_Keyvalue(s1,2,4);   
          break;
            }
     }
   
  while(Key_pressed()!=5);
 
      
 }




 /* Function Key Value For UP_Down Key */
 void UP_Down_Keyvalue(struct menu s1,int i,int j)
 {   
 
  int ch,lower,upper;   
  do{ 
    if(j==4)
     {
      if(i==2)upper=1;
      if(i==3)upper=9;
      if(i==5)upper=5;
      if(i==8)upper =5;
      if(i==9)upper =9;
     }
      if(UP_S)  
      {
      while(UP_S);   
      if(s1.menu_up_key==upper)
      s1.menu_up_key = lower-1;
      LCD_GoToXY(1,i);
      LCD_Printf("%d",++s1.menu_up_key);
      s1.time[i-2]=s1.menu_up_key;         
      }
   else if(DOWN_S) // down
            
          {    while(DOWN_S);
            if (s1.menu_up_key==lower)
            s1.menu_up_key = upper+1;       
            LCD_GoToXY(1,i);
            LCD_Printf("%d",--s1.menu_up_key);
      s1.time[i-2]=s1.menu_up_key;      
     }
          if(RIGHT_S)
      
             { while(RIGHT_S);
       s1.menu_up_key=0;
          if(i==9) goto exit1;
          if(i==3||i==6)
          ++i;
          i++;
              }
      exit1:
           if (LEFT_S)
             { while(LEFT_S);
        s1.menu_up_key=0;
            if(i==2) goto exit2;        
            if(i==5||i==8)
            --i;
            i--;
    
             }
    exit2:continue;
  
  
  } while (ch!=5);  // if Okay key exit loop
 
 }







</avr></pre>
<div class="separator" style="clear: both; text-align: center;">
</div>
</div>

Attepmt to Accessing Keyboad Up and down Key by C programm for a project

By
<div dir="ltr" style="text-align: left;" trbidi="on">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhDK4I6uKmMOILPqNPi34Ip8Jwp2iKWsVp15PjpH9nZMlCEo36DmJom5qQ3M555omOA68qZ0A_Ei5kFY1O_bkQCOqvx5l4XWL4GdcoFuR3GyuMJIp3g8jERYCBfjlaCvGKzSo7hwhd4TDvF/s1600/Capture.PNG" imageanchor="1"><img border="0" data-original-height="604" data-original-width="846" height="456" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhDK4I6uKmMOILPqNPi34Ip8Jwp2iKWsVp15PjpH9nZMlCEo36DmJom5qQ3M555omOA68qZ0A_Ei5kFY1O_bkQCOqvx5l4XWL4GdcoFuR3GyuMJIp3g8jERYCBfjlaCvGKzSo7hwhd4TDvF/s640/Capture.PNG" width="640" /></a>
<br />
<pre class="brush:csharp"></pre>
<pre class="brush:c++"> *<b> main.c</b>
 *
 *  Created on: Aug 12, 2017
 *      Author: thannara123




#include<stdio .h="">
#define FALSE 0
#define TRUE  1  // 0r //!FALSE
struct menu
 {
   char menu_up_key;
   char menu_down_key;
   char menu_enter_key :1; // bit feild 1 bit
 };
struct menu s1= {0}; //s1.menu_up-key =1;
void struct_1( struct menu,const char *menu_display[]);



int main()
{

     const char *menu_display[10];
      menu_display[0] = "Menu0";
      menu_display[1] = "Menu1";
      menu_display[2] = "Menu2";
      menu_display[3] = "Menu3";
      menu_display[4] = "Menu4";
      menu_display[5] = "menu 5";
      menu_display[6] = "menu 6";


       struct_1(s1,menu_display);
             getchar();
             return 0;

      }


void struct_1(struct menu s1 ,const char *menu_display[])
{

     char ch;
      do{
            ch=getch();


            if(ch!='\0')
            {
              ch=getch();
              if(ch=='H')
              {
               s1.menu_up_key++;
               if(s1.menu_up_key==7)
                 s1.menu_up_key =0;
            // printf("UP\n");
                  printf(" %s\n",*(s1.menu_up_key+menu_display));
               }
         else    if(ch=='P')
               {
              s1.menu_up_key--;
              if(s1.menu_up_key==-1)
                  {  s1.menu_up_key =6;
                   goto here;
                  }
                //printf("down\n");

                  here:
         printf("%s\n",*(s1.menu_up_key+menu_display));


                   }

            }
               }
              while(ch!='e');// while oka key
}
</stdio></pre>
<pre class="brush:csharp">/*
 * button_key.c
 *
 * Created: 7/30/2017 12:02:39 PM
 *  Author: Krishna
 */ #include <avr io.h="">
 #include "delay.h"
  #include "button_key.h"
  #include "lcd.h" 
   
void menu_key_display(struct menu s1,const char *menu_display[]);
void UP_Down_Keyvalue(struct menu s1,int i,int j);

 /* Function Key Value For get key  */
int Key_pressed(void)
 {
 while(1){
    if (LEFT_S) {  while(LEFT_S);return 1; }     
 if (RIGHT_S){  while(RIGHT_S);return 2; }
 if (UP_S)  {  while(UP_S); return 3; }
 if (DOWN_S) { while(DOWN_S);return 4 ; }
 if (OK_S) { while(OK_S);return 5 ; }
 }
 }


 /* Function Key Value For Up Key  &amp; Enter*/

 void menu_key_display(struct menu s1,const char *menu_display[])
 {  
  int ch;
   int a;
  int  menu_position =0;
   LCD_DisplayString(menu_display[menu_position]);
            do{ 
   
    repat:         
    ch = Key_pressed();
    if(ch==1||ch==2)
    {
                  if(ch==2)
                    {  if(ch==2)
                   { if(s1.menu_side_key==4)
                     s1.menu_side_key = 0;
                  LCD_Clear();
                  LCD_GoToLine(0);
                              LCD_DisplayString(*((++s1.menu_side_key)+menu_display));
         menu_position=1;           
        
                 }
                      }
                   else if(ch==1)
                   {  
                             if(ch==1)
                    {if(s1.menu_side_key==1 ||s1.menu_side_key==0)
                      {
                    s1.menu_side_key=5;
                      }
                      LCD_Clear();
                            LCD_DisplayString(*((--s1.menu_side_key)+menu_display));                           
          menu_position=1;  
                         }
                   } 
          }
     
    if(menu_position==0)
    goto repat;
        }while(ch!=5);
      
        a = s1.menu_side_key;
  switch(a)
     {
 case 1: // set time
          {
    LCD_Clear();
       LCD_GoToLine(0);
       LCD_DisplayString(menu_display[5]);
    LCD_GoToLine(1);
    LCD_DisplayString("  HH:MM:SS:PM/AM");
    UP_Down_Keyvalue(s1,2,4);   
          break;
          }
 case 2: // Set date
        {
         LCD_Clear();
         LCD_GoToLine(0);
         LCD_DisplayString(menu_display[6]);
      LCD_GoToLine(1);
      LCD_DisplayString("  DD:MM:YY");
      UP_Down_Keyvalue(s1,2,3);    
         break;
        }

 case 3: // set alarm
          {
         LCD_Clear();
            LCD_GoToLine(0);
         LCD_DisplayString(menu_display[7]);
      LCD_GoToLine(1);
      LCD_DisplayString(" HH:MM:SS:AM/PM");
      UP_Down_Keyvalue(s1,2,4);     
          break;
             }
 case 4:  // set alarm
           {
            LCD_Clear();
          LCD_GoToLine(0);
          LCD_DisplayString(menu_display[8]);
    LCD_GoToLine(1);
    LCD_DisplayString("  HH:MM:SS:PM/AM");
    UP_Down_Keyvalue(s1,2,4);   
          break;
            }
     }
   
  while(Key_pressed()!=5);
 
      
 }




 /* Function Key Value For UP_Down Key */
 void UP_Down_Keyvalue(struct menu s1,int i,int j)
 {   
 
  int ch,lower,upper;   
  do{ 
    if(j==4)
     {
      if(i==2)upper=1;
      if(i==3)upper=9;
      if(i==5)upper=5;
      if(i==8)upper =5;
      if(i==9)upper =9;
     }
      if(UP_S)  
      {
      while(UP_S);   
      if(s1.menu_up_key==upper)
      s1.menu_up_key = lower-1;
      LCD_GoToXY(1,i);
      LCD_Printf("%d",++s1.menu_up_key);
      s1.time[i-2]=s1.menu_up_key;         
      }
   else if(DOWN_S) // down
            
          {    while(DOWN_S);
            if (s1.menu_up_key==lower)
            s1.menu_up_key = upper+1;       
            LCD_GoToXY(1,i);
            LCD_Printf("%d",--s1.menu_up_key);
      s1.time[i-2]=s1.menu_up_key;      
     }
          if(RIGHT_S)
      
             { while(RIGHT_S);
       s1.menu_up_key=0;
          if(i==9) goto exit1;
          if(i==3||i==6)
          ++i;
          i++;
              }
      exit1:
           if (LEFT_S)
             { while(LEFT_S);
        s1.menu_up_key=0;
            if(i==2) goto exit2;        
            if(i==5||i==8)
            --i;
            i--;
    
             }
    exit2:continue;
  
  
  } while (ch!=5);  // if Okay key exit loop
 
 }







</avr></pre>
<div class="separator" style="clear: both; text-align: center;">
</div>
</div>

Design of Digital Voltmeter By using Micro-controller Part 2

By
 Microcontroller based Digital AC Meter Part 2 Code And Circuit

First Part available here



Circuit Diagram 

#include"lcd.h"
#include "adc.h"
#include "delay.h"
double volt_read_disply();
int main(void)

{
int adc_value1=0;
LCD_SetUp(PB_0,PB_1,PB_2,P_NC,P_NC,P_NC,P_NC,PB_4,PB_5,PB_6,PB_7);
LCD_Init(2,16);
adc_init();

LCD_Clear();
LCD_GoToXY(0,0);

LCD_DisplayString(" g-Electron");
_delay_ms(1000);

while(1)
{
adc_value1 = volt_read_disply();
LCD_GoToLine(1);
LCD_DisplayString(" Volt : ");
LCD_DisplayNumber(10,adc_value1,3);
LCD_DisplayString("V");
_delay_ms(1300);
}
}

double volt_read_disply()
{ int i,adc_value[40]={0}; int temp =0;

adc_init();

for(i=0; i<40;i++) // samples taking from 41 times 9.4milli second taken about on complte half cycle
{
adc_value[i] = read_adc(0); // reading voltage
}

temp = adc_value[0];
for(i=0; i<40; i++)
{
if(temp<adc_value[i])
temp=adc_value[i];
}

return ((double)temp*0.224828935); // int to double casting

}

Design of Digital Voltmeter By using Micro-controller Part 2

By
 Microcontroller based Digital AC Meter Part 2 Code And Circuit

First Part available here



Circuit Diagram 

#include"lcd.h"
#include "adc.h"
#include "delay.h"
double volt_read_disply();
int main(void)
  
{   
     int adc_value1=0;  
  LCD_SetUp(PB_0,PB_1,PB_2,P_NC,P_NC,P_NC,P_NC,PB_4,PB_5,PB_6,PB_7);
  LCD_Init(2,16);     
     adc_init();
    
     LCD_Clear();
  LCD_GoToXY(0,0);  
  
  LCD_DisplayString("  g-Electron"); 
  _delay_ms(1000); 
  
 while(1) 
 {  
       adc_value1 =  volt_read_disply();
    LCD_GoToLine(1);  
    LCD_DisplayString(" Volt : ");    
    LCD_DisplayNumber(10,adc_value1,3);   
    LCD_DisplayString("V");  
    _delay_ms(1300);
 } 
}

double volt_read_disply()
{   int i,adc_value[40]={0}; int temp =0;
 
 adc_init();

  for(i=0; i<40;i++)                        // samples taking from 41 times 9.4milli second taken about on complte half cycle
   { 
   adc_value[i] = read_adc(0);  // reading voltage           
  }
   
  temp = adc_value[0];  
 for(i=0; i<40; i++)
 {
  if(temp<adc_value[i])
  temp=adc_value[i];
 }  
 
      return ((double)temp*0.224828935); // int to double casting
   
}

Design of Digital Voltmeter By using Microcontroller

By
Tutorial for Atmeag8 /AVR based Voltmeter

               It measures the Ac voltage and shows readings in RMS value.

Basics Of AC signal 

The AC signal ,its amplitude varying in accordance with time. In india AC frequency is 50Hz.

Then the Time period one full cycle ,
        
  T = 1/frequency 
  T = 1/50Hz = .002second 
                     = 20milli Second
                     = 10 Milli second for Half Cycle








There are a lot of methods for measuring AC volt digitally

we could find the RMS value by multipliying the Peak Voltage with 0.707. 

   Vrms = Peak Voltage * 0.707 .

Approximatly Indian Line AC Peak volatge is 325v.

  Example : 
                 325v *0.707 = 229.775Volt      .(appro = 230Vrms).

But Microcontroller could only sense  up to 5 volt  as well as it couldnt sense negative values

so we cannot  give 230 volt directly to It .
It can be rectify by using a Stepdown transformer ,which has an advantage of safety.
Ac voltage can be reduce by using transformer to comfortable range . (ie 0 to 5volt DC)

make the calculation  as   ,
 The voltage Divider would give a 5 volt when the Vrms 230v. [will be more give details on the way ].


The full wave rectifier output will give to ADC of micro controller . Then do corresponding coding.

Microcontroller Section 
I am using here Amega8. 
we need to mesure only one half cycles repeatedly because  the waves same are repeating 
Basics

I selected , the F_cpu frequency is the internal RC Oscillator 8MHz.
Atmega8 ADC uses Prescalar [frequency reducer or divider by 2th,4th etc]
Atmega ADC  Prescale Frequency is in between 50Khz to 200Kz
ADC conversion time is in between 13 to 260 micro second.

ADC frequency = F_cpu / Prescaler

                         = 800,000HZ  / 8
  
                        = 62.5KHz

At high frequency ADC conversion would be fast while at lower frequency the conversion will be more accuracy.

ADC conversion time Calculation 

Conversion Time = 1/ADC frequency

                           = 1/62500 
                           = 0.000016 Second
                           = 0.016 Milli Second
                           = 16 Micro Second.     [At 62.500KHz]

So 16 mirco second would taken for one cycle of  conversion.with 62,5KHz.

13 ADC cycles required for one conversion

ie,
    13 * 16Micro Second = 230 Micro Second [approximately]
                                      = 230us.

The Half wave has 10milli second time duration.[100000microsecond].

There the available conversion times is 

                                        =  Total time period for a half cycle /one ADC conversion time  
                                        
                                        = 10000 micro second / 230 micro second
                 
                                        = 43.4 samples  [ for one half cycleie 10 milli second]

                                       
    Image Shows only 7 Samples per half cycles .in our case it is 43

And again reduced the sampling to 40 .

calculation of Vpeak

 Takes the largest Vpeak from the 40 samples.
Vrms = Vpeak * .707
*****************************************************************************

Atmega8 ADC StepSize Calculation

The Atmega8 ADC is a 10 Bit /[ie the Maximum high value is 1023 =1111111111] at which the ADC will give fullscale Value .
The ADC  require a clock as well as a reference voltage .
The resolution of ADC output decide the Step size.

ADC o/p = Vin * 1024 / Vref

Examples;
  Vin =5volt , Vref =5volt 

                 ADC o/p = 5 * 1023 /5 = 1023 [ADC highest Value]

               Step Size  voltage = Vref / 1023 = 0.004887 volt =4.88millivolt
             One binary digit changes when 4.88volt changes takes place


           

     

Image's Step Size is 1.25 volt




*******************************************************************************************************

Design of Digital Voltmeter By using Microcontroller

By
Tutorial for Atmeag8 /AVR based Voltmeter

               It measures the Ac voltage and shows readings in RMS value.

Basics Of AC signal 

The AC signal ,its amplitude varying in accordance with time. In india AC frequency is 50Hz.

Then the Time period one full cycle ,
        
  T = 1/frequency 
  T = 1/50Hz = .002second 
                     = 20milli Second
                     = 10 Milli second for Half Cycle








There are a lot of methods for measuring AC volt digitally

we could find the RMS value by multipliying the Peak Voltage with 0.707. 

   Vrms = Peak Voltage * 0.707 .

Approximatly Indian Line AC Peak volatge is 325v.

  Example : 
                 325v *0.707 = 229.775Volt      .(appro = 230Vrms).

But Microcontroller could only sense  up to 5 volt  as well as it couldnt sense negative values

so we cannot  give 230 volt directly to It .
It can be rectify by using a Stepdown transformer ,which has an advantage of safety.
Ac voltage can be reduce by using transformer to comfortable range . (ie 0 to 5volt DC)

make the calculation  as   ,
 The voltage Divider would give a 5 volt when the Vrms 230v. [will be more give details on the way ].


The full wave rectifier output will give to ADC of micro controller . Then do corresponding coding.

Microcontroller Section 
I am using here Amega8. 
we need to mesure only one half cycles repeatedly because  the waves same are repeating 
Basics

I selected , the F_cpu frequency is the internal RC Oscillator 8MHz.
Atmega8 ADC uses Prescalar [frequency reducer or divider by 2th,4th etc]
Atmega ADC  Prescale Frequency is in between 50Khz to 200Kz
ADC conversion time is in between 13 to 260 micro second.

ADC frequency = F_cpu / Prescaler

                         = 800,000HZ  / 8
  
                        = 62.5KHz

At high frequency ADC conversion would be fast while at lower frequency the conversion will be more accuracy.

ADC conversion time Calculation 

Conversion Time = 1/ADC frequency

                           = 1/62500 
                           = 0.000016 Second
                           = 0.016 Milli Second
                           = 16 Micro Second.     [At 62.500KHz]

So 16 mirco second would taken for one cycle of  conversion.with 62,5KHz.

13 ADC cycles required for one conversion

ie,
    13 * 16Micro Second = 230 Micro Second [approximately]
                                      = 230us.

The Half wave has 10milli second time duration.[100000microsecond].

There the available conversion times is 

                                        =  Total time period for a half cycle /one ADC conversion time  
                                        
                                        = 10000 micro second / 230 micro second
                 
                                        = 43.4 samples  [ for one half cycleie 10 milli second]

                                       
    Image Shows only 7 Samples per half cycles .in our case it is 43

And again reduced the sampling to 40 .

calculation of Vpeak

 Takes the largest Vpeak from the 40 samples.
Vrms = Vpeak * .707
*****************************************************************************

Atmega8 ADC StepSize Calculation

The Atmega8 ADC is a 10 Bit /[ie the Maximum high value is 1023 =1111111111] at which the ADC will give fullscale Value .
The ADC  require a clock as well as a reference voltage .
The resolution of ADC output decide the Step size.

ADC o/p = Vin * 1024 / Vref

Examples;
  Vin =5volt , Vref =5volt 

                 ADC o/p = 5 * 1023 /5 = 1023 [ADC highest Value]

               Step Size  voltage = Vref / 1023 = 0.004887 volt =4.88millivolt
             One binary digit changes when 4.88volt changes takes place


           

     

Image's Step Size is 1.25 volt




*******************************************************************************************************

Atmega-based-Menu-building-lcd-16x2

By

A menu system Applicable for various microcntroller projects ,Not fully completed only for learning the full code and proteus are available below to download for learning purpose thanking you 

/*
* push_button__lcdMenu.c
*
* Created: 7/30/2017 11:48:27 AM
* Author: Krishna
*/

#include
#include "lcd.h"
#include "delay.h"
#include "button_key.h"
# define F_CPU 1000000UL



struct menu s1= {0}; //s1.menu_up-key =1;


int main(void)
{ int a;
struct menu s1= {0}; //s1.menu_up-key =1;
const char *menu_display[10];
menu_display[0] = " Select Menu";
menu_display[1] = " Set Time";
menu_display[2] = " Set Date";
menu_display[3] = " Set Alaram";
menu_display[4] = " Set Alaram ";
//sub menu
menu_display[5] = " Enter Time ";
menu_display[6] = " Enter Date ";
menu_display[7] = " Enter Alarm ";
menu_display[8] = " Enter Alarm";
LCD_SetUp(PB_0,PB_1,PB_2,P_NC,P_NC,P_NC,P_NC,PB_4,PB_5,PB_6,PB_7);
LCD_Init(2,16);
LCD_GoToLine(0);

DELAY_ms(100);
//LCD_Clear();
while(1)
{

// key_display( key_value);
menu_key_display (s1,menu_display);


LCD_Clear();
for(a=0; a<5 a="" d="" lcd_printf="" pre="" s1.time="">
/*
* button_key.c
*
* Created: 7/30/2017 12:02:39 PM
* Author: Krishna
*/ #include
#include "delay.h"
#include "button_key.h"
#include "lcd.h"

void menu_key_display(struct menu s1,const char *menu_display[]);
void UP_Down_Keyvalue(struct menu s1,int i,int j);

/* Function Key Value For get key */
int Key_pressed(void)
{
while(1){
if (LEFT_S) { while(LEFT_S);return 1; }
if (RIGHT_S){ while(RIGHT_S);return 2; }
if (UP_S) { while(UP_S); return 3; }
if (DOWN_S) { while(DOWN_S);return 4 ; }
if (OK_S) { while(OK_S);return 5 ; }
}
}


/* Function Key Value For Up Key & Enter*/

void menu_key_display(struct menu s1,const char *menu_display[])
{
int ch;
int a;
int menu_position =0;
LCD_DisplayString(menu_display[menu_position]);
do{

repat:
ch = Key_pressed();
if(ch==1||ch==2)
{
if(ch==2)
{ if(ch==2)
{ if(s1.menu_side_key==4)
s1.menu_side_key = 0;
LCD_Clear();
LCD_GoToLine(0);
LCD_DisplayString(*((++s1.menu_side_key)+menu_display));
menu_position=1;

}
}
else if(ch==1)
{
if(ch==1)
{if(s1.menu_side_key==1 ||s1.menu_side_key==0)
{
s1.menu_side_key=5;
}
LCD_Clear();
LCD_DisplayString(*((--s1.menu_side_key)+menu_display));
menu_position=1;
}
}
}

if(menu_position==0)
goto repat;
}while(ch!=5);

a = s1.menu_side_key;
switch(a)
{
case 1: // set time
{
LCD_Clear();
LCD_GoToLine(0);
LCD_DisplayString(menu_display[5]);
LCD_GoToLine(1);
LCD_DisplayString(" HH:MM:SS:PM/AM");
UP_Down_Keyvalue(s1,2,4);
break;
}
case 2: // Set date
{
LCD_Clear();
LCD_GoToLine(0);
LCD_DisplayString(menu_display[6]);
LCD_GoToLine(1);
LCD_DisplayString(" DD:MM:YY");
UP_Down_Keyvalue(s1,2,3);
break;
}

case 3: // set alarm
{
LCD_Clear();
LCD_GoToLine(0);
LCD_DisplayString(menu_display[7]);
LCD_GoToLine(1);
LCD_DisplayString(" HH:MM:SS:AM/PM");
UP_Down_Keyvalue(s1,2,4);
break;
}
case 4: // set alarm
{
LCD_Clear();
LCD_GoToLine(0);
LCD_DisplayString(menu_display[8]);
LCD_GoToLine(1);
LCD_DisplayString(" HH:MM:SS:PM/AM");
UP_Down_Keyvalue(s1,2,4);
break;
}
}

while(Key_pressed()!=5);


}




/* Function Key Value For UP_Down Key */
void UP_Down_Keyvalue(struct menu s1,int i,int j)
{

int ch,lower,upper;
do{
if(j==4)
{
if(i==2)upper=1;
if(i==3)upper=9;
if(i==5)upper=5;
if(i==8)upper =5;
if(i==9)upper =9;
}
if(UP_S)
{
while(UP_S);
if(s1.menu_up_key==upper)
s1.menu_up_key = lower-1;
LCD_GoToXY(1,i);
LCD_Printf("%d",++s1.menu_up_key);
s1.time[i-2]=s1.menu_up_key;
}
else if(DOWN_S) // down

{ while(DOWN_S);
if (s1.menu_up_key==lower)
s1.menu_up_key = upper+1;
LCD_GoToXY(1,i);
LCD_Printf("%d",--s1.menu_up_key);
s1.time[i-2]=s1.menu_up_key;
}
if(RIGHT_S)

{ while(RIGHT_S);
s1.menu_up_key=0;
if(i==9) goto exit1;
if(i==3||i==6)
++i;
i++;
}
exit1:
if (LEFT_S)
{ while(LEFT_S);
s1.menu_up_key=0;
if(i==2) goto exit2;
if(i==5||i==8)
--i;
i--;

}
exit2:continue;


} while (ch!=5); // if Okay key exit loop

}






https://youtu.be/bNwrHuY4Kxk

Atmega-based-Menu-building-lcd-16x2

By

A menu system Applicable for various microcntroller projects ,Not fully completed only for learning the full code and proteus are available below to download for learning purpose thanking you 

/*
 * push_button__lcdMenu.c
 *
 * Created: 7/30/2017 11:48:27 AM
 *  Author: Krishna
 */ 

#include 
#include "lcd.h"
#include "delay.h"
#include "button_key.h"
# define F_CPU 1000000UL



struct menu s1= {0}; //s1.menu_up-key =1;


int main(void)
{   int a;
 struct menu s1= {0}; //s1.menu_up-key =1;
 const char *menu_display[10];
 menu_display[0] = "   Select Menu";
 menu_display[1] = "  Set Time";
 menu_display[2] = "  Set Date";
 menu_display[3] = "  Set Alaram";
 menu_display[4] = "  Set Alaram ";
 //sub menu
 menu_display[5] = "  Enter Time ";
 menu_display[6] = "  Enter Date ";
 menu_display[7] = "  Enter Alarm ";
 menu_display[8] = "  Enter Alarm";
    LCD_SetUp(PB_0,PB_1,PB_2,P_NC,P_NC,P_NC,P_NC,PB_4,PB_5,PB_6,PB_7);
    LCD_Init(2,16);
    LCD_GoToLine(0);
   
    DELAY_ms(100);
 //LCD_Clear();  
  while(1)
 {
     
  // key_display( key_value); 
   menu_key_display (s1,menu_display);
   
  
   LCD_Clear();
   for(a=0; a<5 a="" d="" lcd_printf="" pre="" s1.time="">
/*
 * button_key.c
 *
 * Created: 7/30/2017 12:02:39 PM
 *  Author: Krishna
 */ #include 
 #include "delay.h"
  #include "button_key.h"
  #include "lcd.h"  
    
void menu_key_display(struct menu s1,const char *menu_display[]);
void UP_Down_Keyvalue(struct menu s1,int i,int j);

 /* Function Key Value For get key  */
int Key_pressed(void)
 { 
 while(1){
    if (LEFT_S) {  while(LEFT_S);return 1; }      
 if (RIGHT_S){  while(RIGHT_S);return 2; }
 if (UP_S)  {  while(UP_S); return 3; }
 if (DOWN_S) { while(DOWN_S);return 4 ; }
 if (OK_S) { while(OK_S);return 5 ; }
 } 
 } 
 
 
 /* Function Key Value For Up Key  & Enter*/
 
 void menu_key_display(struct menu s1,const char *menu_display[])
 {   
  int ch; 
   int a; 
  int  menu_position =0;
   LCD_DisplayString(menu_display[menu_position]);
            do{  
    
    repat:          
    ch = Key_pressed();
    if(ch==1||ch==2)
    {
                  if(ch==2)
                    {  if(ch==2)
                   { if(s1.menu_side_key==4)
                     s1.menu_side_key = 0;
                  LCD_Clear();
                  LCD_GoToLine(0);
                              LCD_DisplayString(*((++s1.menu_side_key)+menu_display)); 
         menu_position=1;            
         
                 } 
                      }
                   else if(ch==1)
                   {   
                             if(ch==1)
                    {if(s1.menu_side_key==1 ||s1.menu_side_key==0)
                      {
                    s1.menu_side_key=5;
                      }
                      LCD_Clear();
                            LCD_DisplayString(*((--s1.menu_side_key)+menu_display));                            
          menu_position=1;   
                         }
                   }  
          }
      
    if(menu_position==0)
    goto repat;
        }while(ch!=5);
       
        a = s1.menu_side_key; 
  switch(a)
     { 
 case 1: // set time
          { 
    LCD_Clear();
       LCD_GoToLine(0);
       LCD_DisplayString(menu_display[5]);
    LCD_GoToLine(1);
    LCD_DisplayString("  HH:MM:SS:PM/AM");
    UP_Down_Keyvalue(s1,2,4);    
          break;
          } 
 case 2: // Set date
        {
         LCD_Clear();
         LCD_GoToLine(0);
         LCD_DisplayString(menu_display[6]);
      LCD_GoToLine(1);
      LCD_DisplayString("  DD:MM:YY");
      UP_Down_Keyvalue(s1,2,3);     
         break;
        }
 
 case 3: // set alarm
          {
         LCD_Clear();
            LCD_GoToLine(0);
         LCD_DisplayString(menu_display[7]);
      LCD_GoToLine(1);
      LCD_DisplayString(" HH:MM:SS:AM/PM");
      UP_Down_Keyvalue(s1,2,4);      
          break;
             }
 case 4:  // set alarm
           {
            LCD_Clear();
          LCD_GoToLine(0);
          LCD_DisplayString(menu_display[8]);
    LCD_GoToLine(1);
    LCD_DisplayString("  HH:MM:SS:PM/AM");
    UP_Down_Keyvalue(s1,2,4);    
          break;
            }
     } 
    
  while(Key_pressed()!=5); 
  
       
 } 
 
 
 
 
 /* Function Key Value For UP_Down Key */
 void UP_Down_Keyvalue(struct menu s1,int i,int j)
 {    
  
  int ch,lower,upper;    
  do{  
    if(j==4)
     {
      if(i==2)upper=1;
      if(i==3)upper=9;
      if(i==5)upper=5;
      if(i==8)upper =5;
      if(i==9)upper =9;
     } 
      if(UP_S)   
      {
      while(UP_S);    
      if(s1.menu_up_key==upper)
      s1.menu_up_key = lower-1;
      LCD_GoToXY(1,i); 
      LCD_Printf("%d",++s1.menu_up_key);
      s1.time[i-2]=s1.menu_up_key;          
      }
   else if(DOWN_S) // down 
             
          {    while(DOWN_S);
            if (s1.menu_up_key==lower)
            s1.menu_up_key = upper+1;        
            LCD_GoToXY(1,i);
            LCD_Printf("%d",--s1.menu_up_key);
      s1.time[i-2]=s1.menu_up_key;       
     }
          if(RIGHT_S)
       
             { while(RIGHT_S);
       s1.menu_up_key=0;
          if(i==9) goto exit1;
          if(i==3||i==6)
          ++i;
          i++;
              }
      exit1:
           if (LEFT_S)
             { while(LEFT_S);
        s1.menu_up_key=0;
            if(i==2) goto exit2;         
            if(i==5||i==8)
            --i;
            i--;
     
             }
    exit2:continue;
   
   
  } while (ch!=5);  // if Okay key exit loop
  
 }
 
 
 



https://youtu.be/bNwrHuY4Kxk

More Posts

gElectron. Powered by Blogger.

Contributors

16x2 LCD Interfacing with STM32,STM32F103C6

 16x2 LCD  Interfacing with STM32,STM32F103C6 lcd_init(); LCD_LINE1; lcd_String(" GeElectron"); LCD_LINE2; lc...

Contact Form

Name

Email *

Message *

Contact us

Name

Email *

Message *

Follow Us

https://www.facebook.com/gElectron-393939667321867/ FBbox/https://www.facebook.com/IVYthemes

Comments

[blogger]

MKRdezign

Test

Latest

[recent][newsticker]

Technology

Top Ads

RECENT COMMENTS

Subscribe Via Email

Subscribe to our newsletter to get the latest updates to your inbox. ;-)


Your email address is safe with us!

RECENT COMMENTS