微波EDA网,见证研发工程师的成长!
首页 > 研发问答 > 微波和射频技术 > 天线设计和射频技术 > help plz 16F877 ADC Module

help plz 16F877 ADC Module

时间:04-07 整理:3721RD 点击:
Hi guys
i am very much biggner! Well i've started working with 16F877 adc modules..
bt i am confused:? abt the programming. how to set range of input from 0 to +5V and setting resolution...bla bla
could anyone please send me some simple programes in C. I am using PICC complier and Proteus 7.4 for circuit operation.
my work is attached!


long value;
void main()
{
setup_adc(ADC_CLOCK_INTERNAL);
setup_adc_ports(1);
setup_spi(SPI_SS_DISABLED);
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DISABLED,0,1);
setup_comparator(NC_NC_NC_NC);
setup_vref(FALSE);

TRISB=0x00;
adcon0=0x81;
adcon1=0xCE;

// TODO: USER CODE!
while(1)
{
set_adc_channel(0);
delay_ms(100);
PORTB = read_adc();

}

}

the resolution depends on your PICs ADC hardware. In this case, in 16F877, ADC is 10 bit. Then your resolution is 10bit.
the values are in ADRESH and ADRESL registers. you can get further details in PICs instruction manual. It is really helpful.

set_adc_channel(0);
delay_ms(100);
PORTB = read_adc();

declare a variable for example "adin"

adin = read_adc();
PORTB = (adin/4)

the adc module devide 5v to 1024(10bit)
PORTB support value until 255
so that why "adin" should be divided to 4

tx buddy! it cleared my mind... bye the way there was problm in my complier. thats y read_adc() wasn't working. thanks 4 ur help.

Copyright © 2017-2020 微波EDA网 版权所有

网站地图

Top