adc pic16f877a

pls anyone explain this...i couldnt fix it

  • embedded

    Votes: 0 0.0%
  • pic16f877a

    Votes: 0 0.0%

  • Total voters
    0

Thread Starter

ramya77

Joined Apr 22, 2015
7
here is the adc pgm interfacing with lcd..i m having doubt on this c code

#include<pic.h>

#define _XTAL_FREQ 20000000

void conversion(unsigned int rx_con);

void command(unsigned int rx_cmd);

void string(unsigned char *rs_string);

void data(unsigned int rx_data);

void main()

{

unsigned int a,b,e,f,c,d;

TRISA1=1;

TRISE=0x00;

TRISB=0x00;

ADCON0=0x0d;

ADCON1=0x82;

command(0x01);

command(0x06);

command(0x0c);

command(0x38);

command(0x80);

while(1)

{

{

ADGO=1;

while(ADGO==1);

//pls explain thse steps alone sir..i couldn’t fix it..what about 256 & 49

a=ADRESH;

b=ADRESL;

a=a*256;

c=a+b;

c=c*.49;


conversion(c);

command(0x80);

data('T');

}

}

}

void command(unsigned int rx_cmd)

{

PORTE=0x04;

PORTB=rx_cmd;

__delay_ms(10);

RE2=0;

}

void data(unsigned int rx_data)

{

PORTE=0x05;

PORTB=rx_data;

__delay_ms(10);

RE2=0;

}

void conversion(unsigned int rx_con)

{

data(((rx_con/1000)+0x30));

data((((rx_con%1000)/100)+0x30));

data(((((rx_con%1000)%100)/10)+0x30));

data(((((rx_con%1000)%100)%10)+0x30));

}
 

RRITESH KAKKAR

Joined Jun 29, 2010
2,823
The ADC code only

C:
#include <htc.h>
__CONFIG(LVP_OFF & BOREN_OFF & PWRTE_ON & WDTE_OFF & FOSC_HS);
#define _XTAL_FREQ 20000000


#define DAD PORTB


main(){
    TRISB=0X00;
TRISA = 0xff ;
ADCON1=0b00000000;
ADCON0=0b10000001;//000 = channel 0, (RA0/AN0)
    ADIF=0;
    ADIE=1;
    PEIE=1;
while(1){

    //GIE=1;
  
    __delay_us(10);
GO_DONE=1;
    __delay_us(10);

PORTB=ADRESH;
    }
}
 

Thread Starter

ramya77

Joined Apr 22, 2015
7
The ADC code only

C:
#include <htc.h>
__CONFIG(LVP_OFF & BOREN_OFF & PWRTE_ON & WDTE_OFF & FOSC_HS);
#define _XTAL_FREQ 20000000


#define DAD PORTB


main(){
    TRISB=0X00;
TRISA = 0xff ;
ADCON1=0b00000000;
ADCON0=0b10000001;//000 = channel 0, (RA0/AN0)
    ADIF=0;
    ADIE=1;
    PEIE=1;
while(1){

    //GIE=1;
 
    __delay_us(10);
GO_DONE=1;
    __delay_us(10);

PORTB=ADRESH;
    }
}
 

Thread Starter

ramya77

Joined Apr 22, 2015
7
i m asking about the code which i shown in green colour sir


a=ADRESH;

b=ADRESL;

a=a*256;

c=a+b;

c=c*.49;
 

Alberto

Joined Nov 7, 2008
169
Variable a contains the high byte
Variable b contains the low byte
Variable c contains the word ( 16 bits value)
0.49 is the convertion coefficient from ADC Count to some real value.

Cheers

Alberto
 

Thread Starter

ramya77

Joined Apr 22, 2015
7
thanks alberto..but wat is a=a*256 & y we doing that...actually "a " is right justified (2 bit) & "b" is 8bit..it is configured in ADCON1=0x82(means 10000010)..
my doubt is y we multiplying 256 with "a"??????????????whether we making 2 bit to 8bit!!!!!!!!!!!!!!!!!!!!
sorry if i m confusing u
 

RRITESH KAKKAR

Joined Jun 29, 2010
2,823
Hello,
Which micro is this see the total bits of ADC!
the a,b are the unsigned int of 16bits.
the resultant value of ADC is stored in A,b variable for further processing!
the binary is converted to other resultant value may be some temperature etc etc

a=ADRESH;

b=ADRESL;
 

Thread Starter

ramya77

Joined Apr 22, 2015
7
thank u sir,, sorry sir i m fresher only i m just started to learn things..actually my doubt was not abot conversion...my doubt is how the high & low value is stored...and "a " have 2 bit ..while "b" have "8"bit...(we mentioned right justification in ADCON1)..am i correct or not
 

Thread Starter

ramya77

Joined Apr 22, 2015
7
anyone pls explain i^2c pgm in 8051 (hitech c)...pllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssss.........
 

Thread Starter

ramya77

Joined Apr 22, 2015
7
I WANT ANY TO HELP ME..I HAVE DOUBT ON THIS RED COLOURED AREA...PLS EXPLAIN ANYONE...I M STRUGGLING FOR THREE DAYS
//Program to interface Serial EEPROM AT24C02 with 8051 microcontroller (AT89C51)
#include<reg51.h>
#include<intrins.h> //For using [_nop_()]
sbit sda=P1^0;
sbit scl=P1^1;
sbit led=P0^3;
bit ack;
sbit led1=P0^1;
sfr lcd_data_pin=0xA0;//p2 port
sfr output=0x80;//p0 port
sbit rs=P3^0;
sbit rw=P3^1;
sbit en=P3^6;
unsigned char reead,write,write2,i,j;
unsigned int temp;
void delay(unsigned int count)
{
int i,j;
for(i=0;i<count;i++)
for(j=0;j<1275;j++);
}
void lcd_command(unsigned char comm)
{
lcd_data_pin=comm;
en=1;
rs=0;
rw=0;
delay(1);
en=0;
}
void lcd_data(unsigned char disp)
{
lcd_data_pin=disp;
en=1;
rs=1;
rw=0;
delay(1);
en=0;
}
lcd_dataa(unsigned char *disp)
{
int x;
for(x=0;disp[x]!=0;x++)
{
lcd_data(disp[x]);
}
}
void lcd_ini()
{
lcd_command(0x38); // for using 8-bit 2 row LCD
delay(5);
lcd_command(0x0F); // for display on, cursor blinking
delay(5);
lcd_command(0x80);
delay(5);
}
void aknowledge() //acknowledge condition
{
scl=1;
_nop_();
_nop_();
scl=0;

}
void start() //start condition
{
sda=1;
scl=1;
_nop_(); //No operation
_nop_();
sda=0;
scl=0;
}
void stop() //stop condition
{
sda=0;
scl=1;
_nop_();
_nop_();
sda=1;
scl=0;
}
void send_byte(unsigned char value) //send byte serially
{
unsigned int i;
unsigned char send;
send=value;
for(i=0;i<8;i++)
{
sda=send/128; //extracting MSB
send=send<<1; //shiftng left
scl=1;
_nop_();
_nop_();
scl=0;

}
ack=sda; //reading acknowledge
sda=0;

}
unsigned char read_byte() //reading from EEPROM serially
{
unsigned int i;
sda=1;
reead=0;
for(i=0;i<8;i++)
{
reead=reead<<1;
scl=1;
_nop_();
_nop_();
if(sda==1)
reead++;
scl=0;
}
sda=0;
return reead; //Returns 8 bit data here
}

void save() //save in EEPROM
{
start();
send_byte(0xA0); //device address
aknowledge();
send_byte(0x00); //word address
aknowledge();
send_byte(5); //send data
aknowledge();
send_byte(65);
aknowledge();
stop();
if(ack==0)
{
led1=1;
delay(100);
led1=0;
delay(100);
lcd_command(0x86);
lcd_data('5');
lcd_command(0x87);
lcd_data('A');
}
else
led1=1;
aknowledge();
}
void Read()
{
start();
send_byte(0xA0);
aknowledge();
send_byte(0x00);
aknowledge();
start();
send_byte(0xA1); //device address
aknowledge();
i=read_byte();
aknowledge();
j=read_byte();
aknowledge();
stop();
if(i==5)
{
led=0;
delay(100);
led=1;
delay(100);
write=i+48;
lcd_command(0xC6);
lcd_data(write);
}
else
led=1;
if(j==65)
{
lcd_command(0xC7);
lcd_data(j);
}
aknowledge();
}

void main()
{
lcd_ini();
lcd_dataa("Sent :");
lcd_command(0xC0);
lcd_dataa("Read :");
temp=0;
while(1)
{
save();
Read();
}
 
Top