I am trying to make my pic to send the value of the potentiometer (on PICKIT 1) through serial. At this step I am using an oscilloscope to see if it is doing well.
I wrote the code below, but nothing is changed on the scope screen when I move pot meter. Can you have a look please?
void delay_ms(uns16 millisec)
{
char next=0;
OPTION=2;
TMR0=1;
do {next+=125; while(TMR0!=next);}
while(--millisec!=0);
}
void main()
{
char byte;
int state = 1;
uns16 y=255;
TRISA=0b11000010; //RA1 is input
ANSEL=0b00000001; //analogue input ANO
CMCON0=7; //to switch off the comparator
TRISC.4=1; //USART will automatically configure input-output.
ADCON1=0b00010000; //Fosc/32
ADCON0=0b00000001; //reference voltage VDD
SPBRG=32; // the nearest int to achieve 9600 baud for 20MHZ
BRG16 =0; //8 bit generator.
BRGH=0; //recommended to be set to reduce baud rate error. clear is better.
SYNC=0;// select asychronous
SPEN=1;//serial port enable
ADCON0=0; //ANO selected
ADFM=0; //Left justified
ADCON0.0=1; //Enable conversion
TXEN=1; //Enable transmission
//delay_ms(y); //wait while he's converting
ADCON0.1=1; //GO but turned on.
while (1)
{
byte=ADRESH;
TXREG=byte;
delay_ms(100); //a short delay
}
}