xbee voltmeter using pic16f887

Bluetooth, XBee, RF......

xbee voltmeter using pic16f887

Postby ganeson » Sun Apr 28, 2013 12:37 am

hi,
im new to programming..
but managed to do this...below..
i want to measure the actual voltage that is being measured..but everytime i tried its not displaying anything...
after some editing i managed to display the adc value that is being read by the pic16f887...
can anyone help me on how to display the 0-5vdc that is measured?? in the virtual terminal in proteus?i dont know how else to do it..:(
thanks in advance..
here is my code..


void main() {
int adc_rd;
char text[12];

ANSEL = 0b00000100; // Configure AN2 pin as analog
ANSELH=0; //other are digital
INTCON=0; //disable interrupts
ADCON0=1; //ADC enable(bit1)
CM1CON0=0; //disable comparators
CM2CON0=0;
//ADCON1 = 0x80; //Setting result format, conversion clock and activating ADC function.
//TRISA = 0x2F; //Setting Port A as input.
//TRISE = 0x07; //Setting Port E as input.
//TRISC = 0x80; //Setting Port C as input and output
TRISA=0xFF; // PORTA is input
PORTA=0;

ADC_init();
UART1_Init(9600); // Initialize UART module at 9600 bps
Delay_ms(100); // Wait for UART module to stabilize

UART1_Write_Text("Start");
UART1_Write(10);
UART1_Write(13);

while(1) {
delay_ms(250);
adc_rd = ADC_read(2); // get ADC value from 2nd channel
//adc_rd = adc_rd*5;
//adc_rd = adc_rd/10;

inttostr(adc_rd,text);
UART1_write_text(text);
UART1_write_text("\n");
UART1_write_text("\r");
}
ganeson
Fledgling
 
Posts: 1
Joined: Sat Apr 27, 2013 11:40 pm

Re: xbee voltmeter using pic16f887

Postby waiweng83 » Wed May 08, 2013 12:28 pm

For 10-bit ADC:
Voltage = ADC_Value * 5 / 1023.

For 8-bit ADC:
Voltage = ADC_Value * 5 / 255.


This assume that the AVDD = 5V.

Please take note that the voltage is in float.
With the power of dream, nothing is impossible...
User avatar
waiweng83
Moderator
 
Posts: 157
Joined: Wed Apr 15, 2009 2:17 pm


Return to Wireless Device

Who is online

Users browsing this forum: No registered users and 19 guests

cron