Skip to main content

ADC EMBEDDED C CODING

#include"adc.h"

void adcconvert(unsigned int g)
{
unsigned char temp=0,i=0;
unsigned int x=10000;
if(g==0)
lcddata(temp+0x30);
else
{
while(x)
{
temp=g/x;
if((temp!=0)&&(i==0))
i++;
if((temp!=0)||(i!=0))
lcddata(temp+0x30);
g-=(x*temp);
x/=10;
}
}
}

unsigned int adc(unsigned char chn_sel)
{
unsigned char x,y,adcon_bc;
auto int s=0;
if(chn_sel == 0)
{
CHS2 = 0; CHS1 = 0; CHS0 = 0;
}
else if(chn_sel == 1)
{
CHS2 = 0; CHS1 = 0; CHS0 = 1;
}
else if(chn_sel == 2)
{
CHS2 = 0; CHS1 = 1; CHS0 = 0;
}
else if(chn_sel == 3)
{
CHS2 = 0; CHS1 = 1; CHS0 = 1;
}
else if(chn_sel == 4)
{
CHS2 = 1; CHS1 = 0; CHS0 = 0;
}
else if(chn_sel == 5)
{
CHS2 = 1; CHS1 = 0; CHS0 = 1;
}
else if(chn_sel == 6)
{
CHS2 = 1; CHS1 = 1; CHS0 = 0;
}
else if(chn_sel == 7)
{
CHS2 = 1; CHS1 = 1; CHS0 = 1;
}
ADON=1;
delay(100);
ADGO=1;
while(ADGO==1);
x=ADRESL;
y=ADRESH;
s+=y;s<<=8;
s+=x;
delay(100);
ADON=0;
return s;
}

unsigned int adc_getvalue(unsigned char chn_sel)
{
unsigned char i=0;
unsigned int avg = 0;
for(;i<10;i++)
{
avg += adc(chn_sel);
}
return (avg/10);
}

void adc_init()
{
TRISA = 0xFF;           // set PORTA as input
/* uncoment the below code for all analog sensors*/
// TRISE = 0x07;           // set RE0 (AN5), RE0 (AN6) and RE2(AN7) as input
// ADCON1=0x80; //For configure all ADC Channels
/*************************************************/
CMCON = CMCON | 7;     // Turn off comparators
ADCON0=0x40;
// ADCON1=0x8E; //For configure one sensor and make others Digital
ADCON1=0x82; //For configure First five sensor and last three Digital
}

Comments

Popular posts from this blog

Inverted Linear Quadtree: Efficient Top K Spatial Keyword Search

Inverted Linear Quadtree: Efficient Top K Spatial Keyword Search ABSTRACT: In this paper, With advances in geo-positioning technologies and geo-location services, there are a rapidly growing amount of spatiotextual objects collected in many applications such as location based services and social networks, in which an object is described by its spatial location and a set of keywords (terms). Consequently, the study of spatial keyword search which explores both location and textual description of the objects has attracted great attention from the commercial organizations and research communities. In the paper, we study two fundamental problems in the spatial keyword queries: top k spatial keyword search (TOPK-SK), and batch top k spatial keyword search (BTOPK-SK). Given a set of spatio-textual objects, a query location and a set of query keywords, the TOPK-SK retrieves the closest k objects each of which contains all keywords in the query. BTOPK-SK is the batch processing of sets...

A simple and reliable touch sensitive security system CODING

#include <REGX51.H> #include "lcd.c" #define MAX_DELAY() delay(65000) sbit Vibra_Sense=P3^1; sbit Buz=P1^0; void intro() {  lcd_init();  lcd_str("Touch Sensitive ",0x80);  lcd_str("Security System ",0xc0);  MAX_DELAY();MAX_DELAY();  lcd_clr();  }  void main()  { unsigned int i = 0, j= 0; intro();    while(1)    { lcd_str("Security Syst On",0x80); lcd_str("No Vibra Detectd",0xc0); Buz = 1; if(Vibra_Sense == 1) { while(Vibra_Sense == 1) delay(1000); } else { while(Vibra_Sense == 0) delay(1000); } Buz = 0; lcd_str("Vibraton Detectd",0xc0);delay(65000); while(1);    }  }

A Time Efficient Approach for Detecting Errors in Big Sensor Data on Cloud

A Time Efficient Approach for Detecting Errors in Big Sensor Data on Cloud Abstract                                                                                                                                                      ...