Về phần lý thuyết các bạn đọc Datasheet hoặc lên mạng tìm hoặc qua bên TUT về PIC16F877A XC8 tìm đọc nha !
- Ảnh mô phỏng protues.
- Code chương trình,
- Ảnh mô phỏng protues.
- Code chương trình,
#include <16F877A.h>
#device ADC=10
#fuses HS, NOWDT, PROTECT
#use delay(clock=20M)
#use fast_io(b)
#use fast_io(c)
static unsigned char So[]={0x03, 0x9f, 0x25, 0x0d, 0x99, 0x49, 0x41, 0x1b, 0x01, 0x09};
unsigned int8 DV, TP;
unsigned int8 Value1, Value2, Value3;
float Temp;
void Hienthi()
{
TP=Value1%10;
DV=Value1/10;
output_c(0x01);
output_b(So[DV]-0x01);
delay_ms(1);
output_c(0x02);
output_b(So[TP]);
delay_ms(1);
TP=Value2%10;
DV=Value2/10;
output_c(0x04);
output_b(So[DV]-0x01);
delay_ms(1);
output_c(0x08);
output_b(So[TP]);
delay_ms(1);
TP=Value3%10;
DV=Value3/10;
output_c(0x10);
output_b(So[DV]-0x01);
delay_ms(1);
output_c(0x20);
output_b(So[TP]);
delay_ms(1);
output_c(0x00);
output_b(0xff);
delay_ms(1);
}
void Doc_ADC()
{
set_adc_channel(0);//Chon Kenh ADC AN0
delay_us(20);//Tre toi thieu 20us de gia tri lay mau dung.
temp=read_adc();
Value1=(int8)((temp*50)/1023);
set_adc_channel(1);//Chon Kenh ADC AN1
delay_us(20);//Tre toi thieu 20us de gia tri lay mau dung.
temp=read_adc();
Value2=(int8)((temp*50)/1023);
set_adc_channel(2);//Chon Kenh ADC AN2
delay_us(20);//Tre toi thieu 20us de gia tri lay mau dung.
temp=read_adc();
Value3=(int8)((temp*50)/1023);
}
void main()
{
set_tris_b(0x00);
set_tris_c(0x00);
setup_adc(ADC_CLOCK_INTERNAL);
setup_adc_ports(AN0_AN1_AN2_AN3_AN4_AN5);
while(true)
{
Doc_ADC();
Hienthi();
}
}
- Link download project Click here#device ADC=10
#fuses HS, NOWDT, PROTECT
#use delay(clock=20M)
#use fast_io(b)
#use fast_io(c)
static unsigned char So[]={0x03, 0x9f, 0x25, 0x0d, 0x99, 0x49, 0x41, 0x1b, 0x01, 0x09};
unsigned int8 DV, TP;
unsigned int8 Value1, Value2, Value3;
float Temp;
void Hienthi()
{
TP=Value1%10;
DV=Value1/10;
output_c(0x01);
output_b(So[DV]-0x01);
delay_ms(1);
output_c(0x02);
output_b(So[TP]);
delay_ms(1);
TP=Value2%10;
DV=Value2/10;
output_c(0x04);
output_b(So[DV]-0x01);
delay_ms(1);
output_c(0x08);
output_b(So[TP]);
delay_ms(1);
TP=Value3%10;
DV=Value3/10;
output_c(0x10);
output_b(So[DV]-0x01);
delay_ms(1);
output_c(0x20);
output_b(So[TP]);
delay_ms(1);
output_c(0x00);
output_b(0xff);
delay_ms(1);
}
void Doc_ADC()
{
set_adc_channel(0);//Chon Kenh ADC AN0
delay_us(20);//Tre toi thieu 20us de gia tri lay mau dung.
temp=read_adc();
Value1=(int8)((temp*50)/1023);
set_adc_channel(1);//Chon Kenh ADC AN1
delay_us(20);//Tre toi thieu 20us de gia tri lay mau dung.
temp=read_adc();
Value2=(int8)((temp*50)/1023);
set_adc_channel(2);//Chon Kenh ADC AN2
delay_us(20);//Tre toi thieu 20us de gia tri lay mau dung.
temp=read_adc();
Value3=(int8)((temp*50)/1023);
}
void main()
{
set_tris_b(0x00);
set_tris_c(0x00);
setup_adc(ADC_CLOCK_INTERNAL);
setup_adc_ports(AN0_AN1_AN2_AN3_AN4_AN5);
while(true)
{
Doc_ADC();
Hienthi();
}
}
EmoticonEmoticon