Hi , I am currently learning PIC16F877 . I am trying to write a code to convert the analogue value on the potentiometer attached to RA0 and display the scaled conversion on an LCD display attached to PORTD such that when the 0V 5V range of RA0 is converted the display reads on line 1 VOLTAGE = X.XX V where XXX has a value from 000 to 500.
here is the code i have for convertion , but i have no idea about how to combine this code to complete the above requests. Any help is appreicated =) .
My email : microctrler@hotmail.com
P.S. full code is always the best =P
//analogue input on RA0 with result sent to PORTB and PORTC
#include <pic.h>
void init_ports(void);
void init_a_d(void);
void init_ports(void)
{
TRISB = 0x00;
TRISC = 0x00; // set portb and portc as outputs
TRISA = 0xFF; // set the porta bits to inputs
}
void init_a_d(void)
{
ADCS1 = 1;
ADCS0 = 1; // A/D conversion clock derived from RC osc
CHS2 = 0;
CHS1 = 0;
CHS0 = 0; //select channel 0
ADON = 1; // A/D switched ON
ADCON1 = 0x00; // enable all analogue inputs
ADFM = 1; // right justified result - 6 most sig bits
//of ADRESH read as '0'
}
void main(void)
{
int result;
init_ports();
init_a_d();
while(1)
{
ADGO = 1; // start the conversion
while (ADGO= =1){}; // now wait here until the conversion is done
result = (ADRESH <<8 )+ ADRESL;
PORTB = (result>>8) & 0x00FF;
PORTC = (result & 0x00FF);
}
}
here is the code i have for convertion , but i have no idea about how to combine this code to complete the above requests. Any help is appreicated =) .
My email : microctrler@hotmail.com
P.S. full code is always the best =P
//analogue input on RA0 with result sent to PORTB and PORTC
#include <pic.h>
void init_ports(void);
void init_a_d(void);
void init_ports(void)
{
TRISB = 0x00;
TRISC = 0x00; // set portb and portc as outputs
TRISA = 0xFF; // set the porta bits to inputs
}
void init_a_d(void)
{
ADCS1 = 1;
ADCS0 = 1; // A/D conversion clock derived from RC osc
CHS2 = 0;
CHS1 = 0;
CHS0 = 0; //select channel 0
ADON = 1; // A/D switched ON
ADCON1 = 0x00; // enable all analogue inputs
ADFM = 1; // right justified result - 6 most sig bits
//of ADRESH read as '0'
}
void main(void)
{
int result;
init_ports();
init_a_d();
while(1)
{
ADGO = 1; // start the conversion
while (ADGO= =1){}; // now wait here until the conversion is done
result = (ADRESH <<8 )+ ADRESL;
PORTB = (result>>8) & 0x00FF;
PORTC = (result & 0x00FF);
}
}