#include <stdio.h>
#include <pic.h>
#include "usart.h"
void init_a2d(void){
ADCON1=0x80; // select right justify result.
ADCON0=0; // select Fosc/2
ADON=1; // turn on the A2D conversion module
}
short read_a2d(unsigned char channel){
channel&=0x07; // truncate channel to 3 bits
ADCON0&=0xC5; // clear current channel select
ADCON0|=(channel<<3); // apply the new channel select
ADGO=1; // initiate conversion on the selected channel
while(ADGO)continue;
return((ADRESH<<8)+(ADRESL)); // return the result
}
void main(void){
unsigned char input;
int a,b,c;
float an;
init_a2d(); // initialise the A2D module
init_comms(); // set up the USART - settings defined in usart.h
for(;;){
for(a=0;a<300;a++){
for(c=0;c<500;c++){}}
for(b=0;b<8;b++){
for(a=0;a<300;a++){
for(c=0;c<500;c++){}}
an=read_a2d(b);
an=5*an/1023;
printf("%1.2f %d ",an,b);}
printf("\r \n");
}
}