chuong trinh viet cho VDK PIC16F877A de do du lieu ADC tu kenh AN0 lm35
//chuong trinh viet cho VDK PIC16F877A de do du lieu ADC tu kenh AN0
//cam bien nhiet su dung la lm35 (10mv/1doC)
//hien thi gia tri nhiet do tren 2 led 7 doan
//portB noi voi cac doan
//chan c0,c1 cua portC quet led
//-------------------------------------------------------------------
#include"16f877a.h"
#include"def_877a.h"
#device *=16 adc=10 //chon dc 10 bit
#use delay(clock=4mhz)
//ding nghia ma 7 doan
const int ma_7doan[10]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90};
// khai bao bien
int adc_read,chuc,don_vi,chuc_7doan,don_vi_7doan;
//chuong trinh con hien thi
void hien_thi()
{
portb=don_vi_7doan;
rc0=0;
delay_us(100);
rc0=1;
portb=chuc_7doan;
rc1=0;
delay_us(100);
rc1=1;
}
//chuong trinh chinh
void main()
{
//thiet lap cac dau vao ra
trisb=0; //dat port b lam dau ra
trisc0=0;
trisc1=0; //dau ra quet led
trisa0=1; //dau vao analog
//------------------------
setup_adc_ports(an0);
setup_adc(adc_clock_internal);
// o day ta su dung adc 10 bit voi vref+=5V, vfef-=0v
// ma 1 do C ung voi 10mv ( dung cam bien LM35)
// 5000mv - - - voi - - - 1024 ( 2^10)
// 10mv - - - voi x >>> x=10mv*1024/5000mv=2.048 so dem
while(true)
{
adc_read=read_adc();
adc_read=adc_read/2.048;
chuc=adc_read/10;
chuc_7doan=ma_7doan[chuc];
don_vi=adc_read%10;
don_vi_7doan=ma_7doan[don_vi];
hien_thi();
}
}
Bạn đang đọc truyện trên: Truyen247.Pro