SilverWingz
New Member
I am a pic beginner working on a 16F877A trainer kit.
I Intended to write an ADC code on MPLab,the MSB of which i intended to feed to the PWM module's CCPR1L register to have manual pwm control.
I managed to get the PWM code running,however,got stuck on the ADC section.
Problem:ADRESH byte seems to send nothing to PortB
Here is my code:
Can anyone please point out if i am making any stupid logical errors?
I hope i got the polling format right...i was just following the PIC datasheet
Thanks in advance
I Intended to write an ADC code on MPLab,the MSB of which i intended to feed to the PWM module's CCPR1L register to have manual pwm control.
I managed to get the PWM code running,however,got stuck on the ADC section.
Problem:ADRESH byte seems to send nothing to PortB
Here is my code:
Code:
#include <htc.h>
#ifndef _XTAL_FREQ
#define _XTAL_FREQ 20000000
#endif
void init(void)
{
TRISA = 0xFF; //PortA as Input
TRISB = 0x00; //PortB as Outputs
PORTB = 0x00; //Initialise
ADCON1 = 0b00000000; //left justified,all analog
ADCON0 = 0b10101001; //Fosc/16 ; pin5 as analog in ;
}
void main(void)
{
init();
while(1){
__delay_ms(2); //wait
GODONE=1; //start conversion
while(GODONE); //wait for conversion to complete
PORTB=ADRESH; //transfer to portB for dilslay on LED
}
}
Can anyone please point out if i am making any stupid logical errors?
I hope i got the polling format right...i was just following the PIC datasheet
Thanks in advance