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

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

By

 * main.c
*
* Created on: Aug 12, 2017
* Author: thannara123




#include
#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
}
/*
* 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

}



See You



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

By


 * main.c
 *
 *  Created on: Aug 12, 2017
 *      Author: thannara123
 



#include
#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
}
/*
 * 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
  
 }
 
 
 
See You 



16 Bit Event Counter & Displaying on LCD1

By
An External Pulse Counter Using 8051 and Dispalying on 16x2 LCD 

  A circuits which is used to count the external pulses And which is displaying on an 16x2 LCD display . You can simply use this project for various purpose .It is a default  project for counting Purpose.



Tutorials : - 


To use 16 Bit counter we need to configure some register in 8051 as follows 

TMOD Register is need to configure as follows
16 bit counter Setting with timer 0

TMOD=0x05; //  Giving 0x05 it configured so .

8051 has Two Timer (each has 16 bit ) i am taking here Timer 0 It has to part First 8 bit (TL)) and the second part is (TH0) .
This timer is using to store the Pulses from the external (ie it will increment up to 65535 or FFFF)

TL0 = 0; // that timer clearing 

TH0 = 0;  // that timer clearing 

 TR0 = 1 // TR0 setting to start the counting .


Done .................................


    After setting the above register as said  the resulted value (counting value ) will save periodically in TL0 and TH0 . That value displaying after converting it to decimal . for LCD Tutorials Go Here



Download Her the all Project Including Proteus file
Click Here

16 Bit Event Counter & Displaying on LCD1

By
An External Pulse Counter Using 8051 and Dispalying on 16x2 LCD 

  A circuits which is used to count the external pulses And which is displaying on an 16x2 LCD display . You can simply use this project for various purpose .It is a default  project for counting Purpose.



Tutorials : - 


To use 16 Bit counter we need to configure some register in 8051 as follows 

TMOD Register is need to configure as follows
16 bit counter Setting with timer 0

TMOD=0x05; //  Giving 0x05 it configured so .

8051 has Two Timer (each has 16 bit ) i am taking here Timer 0 It has to part First 8 bit (TL)) and the second part is (TH0) .
This timer is using to store the Pulses from the external (ie it will increment up to 65535 or FFFF)

TL0 = 0; // that timer clearing 

TH0 = 0;  // that timer clearing 

 TR0 = 1 // TR0 setting to start the counting .


Done .................................


    After setting the above register as said  the resulted value (counting value ) will save periodically in TL0 and TH0 . That value displaying after converting it to decimal . for LCD Tutorials Go Here



Download Her the all Project Including Proteus file
Click Here

Timer

By

Timer 

What is a Timer ? 

A Timer is device it sense the time interval and produce an output at a set value . example alarm Timer setting.(Timer in Wikipedia )


,What is the need of a timer in Micro controller ?
1) Some time  micro controller Code need some accurate  Delay  ( Example blinking An LED in each      accurate 1 sec. Look LED Blinking example

2)Some Time the code needs the code Repeat

3) Most of the Interfacing devices with micro-controller needs a clock (accurate interval of clocks)
   Example:   LCD module require Clock  Signal Look LCD Interfacing
               

Timer in 8051

Also a Timer actually require a clock pulse  (pling) .These pulse are given from controller  (actually it is in software based not giving ) see below picture
8051 type controller has  two Timer Timer 0 and Timer 1 (These two timer is the length of 16 bit ,0000 to  FFFF ).These Timer is named as TR0 and TR1. 



The Timer Setting/configuring  can controlling by the TMOD register 



These TMOD register Values is used to decide how the Timer Works .
Sample program




download the fullcode and Test

Timer

By

Timer 

What is a Timer ? 

A Timer is device it sense the time interval and produce an output at a set value . example alarm Timer setting.(Timer in Wikipedia )


,What is the need of a timer in Micro controller ?
1) Some time  micro controller Code need some accurate  Delay  ( Example blinking An LED in each      accurate 1 sec. Look LED Blinking example

2)Some Time the code needs the code Repeat

3) Most of the Interfacing devices with micro-controller needs a clock (accurate interval of clocks)
   Example:   LCD module require Clock  Signal Look LCD Interfacing
               

Timer in 8051

Also a Timer actually require a clock pulse  (pling) .These pulse are given from controller  (actually it is in software based not giving ) see below picture
8051 type controller has  two Timer Timer 0 and Timer 1 (These two timer is the length of 16 bit ,0000 to  FFFF ).These Timer is named as TR0 and TR1. 



The Timer Setting/configuring  can controlling by the TMOD register 



These TMOD register Values is used to decide how the Timer Works .
Sample program




download the fullcode and Test

Rotation Counter using 8051

By

Rotation Counter using 8051


 I need to make a counter for a transformer winding machine .In that the winding is made by hand . so the roation  need to be keep in mind ,that is too much difficult .So the winding shaft rotaion counting by an infrared sensor module which is connected with 89S52 microcontroler and a LCD .

Infrared based Rotation Counter by 805 or  (contact less Rotation Counter  or Rotation counter without using Interrupt.



 

Code : 


INFRARED Module 


Download the Full Project  CODE and with Proteus  Here

Rotation Counter using 8051

By

Rotation Counter using 8051


 I need to make a counter for a transformer winding machine .In that the winding is made by hand . so the roation  need to be keep in mind ,that is too much difficult .So the winding shaft rotaion counting by an infrared sensor module which is connected with 89S52 microcontroler and a LCD .

Infrared based Rotation Counter by 805 or  (contact less Rotation Counter  or Rotation counter without using Interrupt.



 

Code : 


INFRARED Module 


Download the Full Project  CODE and with Proteus  Here

ADC Reading With Internal Adc Of AVR - Atemga 32 And Displaying On LCD

By

Download HereADC Reading With Internal Adc Of  AVR - Atemga 32 And Displaying On LCD

According to data sheet there are 3 registers are used to works the ADC in AVR atmega 32 
ie , 

1) ADMUX
2)ADSCR
3)ADC



1) ADMUX :-

 It is an 8 bit Register ,each bit has some functions as follows 

REFS1 & REFS0 :- is used for the reference Voltage  with respect to our analog input (for resolution)  to know more search this blog.
I am giving 5volt as reference so selected REFS1 = 0 & REFS0 = 1

ADMUX=(1<<REFS0); // AVcc with external capacitor at AREF  ,giving a high to REFS0.

MUX0-MUX4  :- it is used to select the input channel ,ie 8  analog input channel can be given so desired one selection by giving appropriate value .
  ADLAR : - used to shift the resulted data (ADC Value) left or right .I am using right shift so makes as low.
.....................................................................................................................................

2) ADSCR :-  ADCSRA = (1<<ADEN)|(1<<ADPS2)|(1<<ADPS1)|(1<<ADPS0);

It is also an 8 bit register .

Bit 7 used to ADC ON (ADC Turn ONing by applying a high bit )
Bit6 ADSC is used to start the conversion .and still maintain it value as high  up to the conversion . after conversion it becomes low (Zero)
ADATE and ADIF is not used by me now .(not by using Intruppet
Bit 0 to bit2  is used for select ADC frequency . 

\
2) ADC: It is a 16 bit to 8 bit register ADCL & ADCH. By applying right shift value it is autmatically set as normal value so we can take simple value from it

 eg :  return (ADC);
 adc_value = read_adc(ch_sec); 

The program as follows . The full program can be download below including Proteus simulation file.






ADC Reading With Internal Adc Of AVR - Atemga 32 And Displaying On LCD

By

Download HereADC Reading With Internal Adc Of  AVR - Atemga 32 And Displaying On LCD

According to data sheet there are 3 registers are used to works the ADC in AVR atmega 32 
ie , 

1) ADMUX
2)ADSCR
3)ADC



1) ADMUX :-

 It is an 8 bit Register ,each bit has some functions as follows 

REFS1 & REFS0 :- is used for the reference Voltage  with respect to our analog input (for resolution)  to know more search this blog.
I am giving 5volt as reference so selected REFS1 = 0 & REFS0 = 1

ADMUX=(1<<REFS0); // AVcc with external capacitor at AREF  ,giving a high to REFS0.

MUX0-MUX4  :- it is used to select the input channel ,ie 8  analog input channel can be given so desired one selection by giving appropriate value .
  ADLAR : - used to shift the resulted data (ADC Value) left or right .I am using right shift so makes as low.
.....................................................................................................................................

2) ADSCR :-  ADCSRA = (1<<ADEN)|(1<<ADPS2)|(1<<ADPS1)|(1<<ADPS0);

It is also an 8 bit register .

Bit 7 used to ADC ON (ADC Turn ONing by applying a high bit )
Bit6 ADSC is used to start the conversion .and still maintain it value as high  up to the conversion . after conversion it becomes low (Zero)
ADATE and ADIF is not used by me now .(not by using Intruppet
Bit 0 to bit2  is used for select ADC frequency . 

\
2) ADC: It is a 16 bit to 8 bit register ADCL & ADCH. By applying right shift value it is autmatically set as normal value so we can take simple value from it

 eg :  return (ADC);
 adc_value = read_adc(ch_sec); 

The program as follows . The full program can be download below including Proteus simulation file.






ADC reading with Internal adc of PIC16F77 and displaying on LCD

By
In PIC16F877 has 8 channels are available for adc input ie AN0 to AN7.Any one can be use ,we can select the the channel by selecting channel selection bit.

The Whole project Can be download at the Bottom of the post .


            In ADC the Vref voltage is important in accuracy of the ADC conversion.Low Vref gets more accuracy . But This PIC has a 10 bit result ion so it is enough As follows some example

If    Vref             =    4.096 volt
     Bit resolution  = 8 ie 2^8 =256
then  4.096/256 = 16Millvolt Per Bit
        3.88/256 = 15mv/bit
        2.56/256 = 10mv/bit
giving vcc as vref (5Volt) in 10 bit Resolution
Vref =5 v
Bit resolution  = 10 bit ,ie 2^10 = 1024
so
            5/1024 = 4.8828 millivolt /Bit
Here  taking 5 volt as vref

For getting ADC value the following steps are needed

 * Initialization of ADC
 * Reading ADC value


 Initialization of ADC

 Initialization of ADC mean that
Configure the ADC PORT  for that PIC has 4 registers they are
* ADCON 0
* ADCON 1
* ADRESH
*ADRESL

ADCON0 :- it is an 8 bit register it decide how the ADC worrks in accordance with the following bit have to set .
Lasr(msb bit) two bit decide the clock of the ADC ie the conversion speed.if we select the the main PIC crystal frequency as 20MHz
then I will select the First tw register value is 10
ie 10 = Fosc/32
after calculating the clock speed there must be a time 1.6 micro second for one bit conversion these time is called TAD . So to convert  10 bit  need 10x1.6 microsecond .,Look Data sheet page No .133 Section 11-2.

 I am selecting the ADC clock selection bit is 10

ADCS1  = 1
ADCS0  = 0
ie fosc/32    Look Datasheet Page No. 130 section 11.2

Calculation
            20Mhz/32 = 625000Hz ie 1.6Microsecond
           For one TAD is 1.6 is correct .(Look Data sheet page No .133 Section 11-2)

Then ,
The the 3rd,4the and 5th bit is the analog channel selection Bit from the Port AN0 to AN7.




The second bit(GO/DONE) is used to Start the conversion  of analog value to digital when its value is one .And automatically reset (become zero) whenever the completion take place  

 GO/DONE: A/D Conversion Status bit
When ADON = 1:
1 = A/D conversion in progress (setting this bit starts the A/D conversion which is automatically
cleared by hardware when the A/D conversion is complete)
0 = A/D conversion not in progress  

The Second Bit is not used Leave it as Zero

The First Bit is the Bit to Turn On the ADC .(powering on the ADC).

So the ADCON0 value is 10000001 in Hex a 0x81;

ADCON1 :-
         
         
       
The Bit From Bit 0 to Bit 3  are used decide  to How act the Analog PIN . How the Vref and GND voltage are given. I am selecting the first one
0000 becuase the 8 bit of AN is selected as Analog (denoted above as "A")
And the Vref is taken as VDD ie 5volt (VCC)
* channel selected
So the ADCON1 value is 10000000 in hex format = 0x80;

The Last Bit of ADCON1 is ADFM is used to alignment the result of adc (ie the value )
If its value is One The 10 bit adc value is right alimented
If its value is zero The 10 bit is left aligned

ADRESH :- is the Register (8bit) the result of ADC saved here . Our result is 10 bit if we use 10 bit resolution. But the ADRESH register is 8 bit So the 8 bit of the 10 bit adc result is saved in ADRESH the balance 2 bit is saved in ADRESL .



Circuit diagram 






Main Programm
/* 
* File: adc_main.c
* Author: gElectron/Gireesh
*
* Created on September 27, 2015, 6:24 AM
*/


// PIC16F877 Configuration Bit Settings

// 'C' source line config statements

#include
#include"lcd.h"
#include"adc.h"
#include
#define _XTAL_FREQ 20000000 // 20Mh
// #pragma config statements should precede project file includes.
// Use project enums instead of #define for ON and OFF.

// CONFIG
#pragma config FOSC = HS // Oscillator Selection bits (HS oscillator)
#pragma config WDTE = OFF // Watchdog Timer Enable bit (WDT disabled)
#pragma config PWRTE = OFF // Power-up Timer Enable bit (PWRT disabled)
#pragma config CP = OFF // FLASH Program Memory Code Protection bits (Code protection off)
#pragma config BOREN = ON // Brown-out Reset Enable bit (BOR enabled)
#pragma config LVP = OFF // Low Voltage In-Circuit Serial Programming Enable bit (RB3 is digital I/O, HV on MCLR must be used for programming)
#pragma config CPD = OFF // Data EE Memory Code Protection (Code Protection off)
#pragma config WRT = OFF // FLASH Program Memory Write Enable (Unprotected program memory may not be written to by EECON control)


void main()
{
TRISB = 0X00; // output for the 8 bit
TRISA =0XFF;
int adc_value=0x00,ch_sec = 0;
unsigned char digits[5];
lcd_init(); // lcd initialization
adc_init(); // adc initialization
adc_value = read_adc(ch_sec); // reading adc value
string("gElectron ");
LINE2;
digits[0] = adc_value / 1000 + 48;
digits[1] = (adc_value / 100) % 10 + 48;
digits[2] = (adc_value / 10) % 10 + 48;
digits[3] = adc_value % 10 + 48;
digits[4] = '\0';
string(digits);

while(1); // endless loop
}

ADC file
/* 
* File: adc.c
* Author: Krishna
*
* Created on September 27, 2015, 7:14 AM
*/
#include
#include"adc.h"
//#define _XTAL_FREQ 20000000
void adc_init()
{

ADCON0 = 0x81;// 10000001 TAD is fosci/32 and last bit is adc poweron
ADCON1 = 0x80; //all port selected as output ,vref= vcc,
TRISA = 0x2f; //ENANLING AS ANALOG INPUT
TRISE = 0X07; // ENANLING AS ANALOG INPUT
}

unsigned int read_adc(unsigned char ch_selection)
{
if(ch_selection>7) // checking is channel greater than 7
return 0; // yes return zero
__delay_us(50); //adc acquisition time as 19.72 ?s as datasheet
GO_nDONE = 1;
while(GO_nDONE); // after conversion GO_nDONE value become 0 autmatically.
return((ADRESH<<8)+ADRESL);

Downlaod the Whole Project Including Proteus Simulation click heredownload

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