krishnaraj916
Newbie level 6
HI I AM USING PIC16F877A TO JUST MEASURE THE VOLTAGE AT THE A1 PIN ( ANALOGUE) AND DISPLAY THE CORRESPONDING 8 BITS AS THE OUTPUT OF PORT B
but wn trying to simulate with the code below ..nothing happens...
pls help me!!
#include<htc.h>
#FUSES NOWDT //No Watch Dog Timer
#FUSES HS //high freq osc > 200 khz
#FUSES NOPROTECT //Code not protected from reading
#FUSES NOBROWNOUT //No brownout reset
#FUSES NOCPD //No EE protection
#FUSES NOPUT //No Power Up Timer
#use delay(clock=4000000)
void init_a2d(void)
{
ADCON0=0; // select Fosc/2
ADCON1=0x01; // select right justify result. A/D port configuration 0
ADON=1; // turn on the A2D conversion module
}
/* Return an 8 bit result */
unsigned char 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); // return 8 MSB of the result
}
void main(void){
unsigned char x;
init_a2d(); // initialise the A2D module
GIE=0; // don't want interrupts
TRISB=0x00; // the 8 bits of POTRB will be used in output mode
while(1){
x=read_a2d(1); // sample the analog value on RA0
PORTB = x; //to give corresponding bcd
}
}
but wn trying to simulate with the code below ..nothing happens...
pls help me!!
#include<htc.h>
#FUSES NOWDT //No Watch Dog Timer
#FUSES HS //high freq osc > 200 khz
#FUSES NOPROTECT //Code not protected from reading
#FUSES NOBROWNOUT //No brownout reset
#FUSES NOCPD //No EE protection
#FUSES NOPUT //No Power Up Timer
#use delay(clock=4000000)
void init_a2d(void)
{
ADCON0=0; // select Fosc/2
ADCON1=0x01; // select right justify result. A/D port configuration 0
ADON=1; // turn on the A2D conversion module
}
/* Return an 8 bit result */
unsigned char 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); // return 8 MSB of the result
}
void main(void){
unsigned char x;
init_a2d(); // initialise the A2D module
GIE=0; // don't want interrupts
TRISB=0x00; // the 8 bits of POTRB will be used in output mode
while(1){
x=read_a2d(1); // sample the analog value on RA0
PORTB = x; //to give corresponding bcd
}
}