Trích:
Nguyên văn bởi ngoalongdochanh
Cho toi hoi tai sao khi khai bao:
#device PIC16F877 *=16 ADC=10
thi CCSC bao loi: "Can not change device type this far into the code"
Cach khac phuc
|
Đây là 1 ví dụ nhỏ về ADC,chân RA0 lấy tín hiệu Analog từ biến trở và xuất giá trị số biến đổi tương ứng qua tám led nối ở portB
Code:
#include <16F877.h>
#fuses HS,NOWDT,NOPROTECT,NOLVP
#device 16F877*=16 ADC=8
#use delay(clock=10000000)
Int8 adc;
main()
{
setup_adc(adc_clock_internal);
setup_adc_ports(AN0);
set_adc_channel(0);
delay_ms(10);
while(true)
{
adc=read_adc();
output_B(adc);
}
}