không hiểu lỗi do đâu mà 2 led sáng không liên tục,cứ nhấp nháy ,mong mọi người sửa giúp:
code:
__#include <16F877A.h>
#device *=16 adc=10 //Su dung adc 10bit
#fuses HS,NOWDT
#use delay(clock=20000000)
#use fast_io(c)
unsigned char const Number[10]={0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x0 9}; //mang chua so 0,1,2,3,4,5,6,7,8,9 .
unsigned int Num_chuc , Num_donvi;
float gt_adc , nhiet_do;
void Chuyendoi_7seg(unsigned int gt)
{
Num_chuc=gt / 10; // lay chu so hang chuc cua nhiet do.
Num_donvi=gt % 10; //lay chu so hang don vi cua nhiet do.
}
//
void Hienthi_7seg()
{
//hien thi chu so hang chuc.
output_high(PIN_C0); //set PORTC.0 =1 de dieu khien Led 7 hien thi chu so hang chuc.
output_B(Number[Num_chuc]);
output_low(PIN_C0);// set PORTC.0 = 0 .
delay_us(100);
//hien thi chu so hang don vi
output_high(PIN_C1);
output_B(Number[Num_donvi]);
output_low(PIN_C1);
}
void main()
{
set_tris_A(0xff); //khoi tao PORTA la dau vao.
set_tris_B(0x00); //khoi tao PORTB la dau ra.
set_tris_C(0x00); //khoi tao PORTC la dau ra.
setup_adc_ports(AN0); //chon PORTA.0 la chan lay tin hieu Analog , dien ap chuan la 5V.
setup_adc(ADC_CLOCK_INTERNAL); //chon thoi gian lay mau bang xung clock.
set_adc_channel(0); //doc ADC tu PORTA.0 .
delay_ms(10);
while(TRUE)
{
gt_adc=(float)read_adc(); //doc gia tri cua adc.
nhiet_do =(gt_adc*500)/1023;
/*
Su dung: adc = 10bit thi gia tri cua adc 0 -> 1023 tuc la co 1024 gia tri
va co 1023 khoang lay gia tri, buoc thay doi la 5/1023.
Neu lay V tham chieu: Vref = 5V.
Su dung LM35:
10mV tuong ung 1 oC.
5000mV <----------> 1023 (ADC 10 bits)
dan den:
500 oC <-----------> 1023
x oC <------------> read_adc();
Suy ra:
Nhiet do do duoc:
x = 500 * read_adc()/1023 (don vi oC)
*/
Chuyendoi_7seg((unsigned int)nhiet_do);
Hienthi_7seg();
}
}
____link file ảnh __________________________________________________ _______________________
http://i.upanh.com/vipscm
code:
__#include <16F877A.h>
#device *=16 adc=10 //Su dung adc 10bit
#fuses HS,NOWDT
#use delay(clock=20000000)
#use fast_io(c)
unsigned char const Number[10]={0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x0 9}; //mang chua so 0,1,2,3,4,5,6,7,8,9 .
unsigned int Num_chuc , Num_donvi;
float gt_adc , nhiet_do;
void Chuyendoi_7seg(unsigned int gt)
{
Num_chuc=gt / 10; // lay chu so hang chuc cua nhiet do.
Num_donvi=gt % 10; //lay chu so hang don vi cua nhiet do.
}
//
void Hienthi_7seg()
{
//hien thi chu so hang chuc.
output_high(PIN_C0); //set PORTC.0 =1 de dieu khien Led 7 hien thi chu so hang chuc.
output_B(Number[Num_chuc]);
output_low(PIN_C0);// set PORTC.0 = 0 .
delay_us(100);
//hien thi chu so hang don vi
output_high(PIN_C1);
output_B(Number[Num_donvi]);
output_low(PIN_C1);
}
void main()
{
set_tris_A(0xff); //khoi tao PORTA la dau vao.
set_tris_B(0x00); //khoi tao PORTB la dau ra.
set_tris_C(0x00); //khoi tao PORTC la dau ra.
setup_adc_ports(AN0); //chon PORTA.0 la chan lay tin hieu Analog , dien ap chuan la 5V.
setup_adc(ADC_CLOCK_INTERNAL); //chon thoi gian lay mau bang xung clock.
set_adc_channel(0); //doc ADC tu PORTA.0 .
delay_ms(10);
while(TRUE)
{
gt_adc=(float)read_adc(); //doc gia tri cua adc.
nhiet_do =(gt_adc*500)/1023;
/*
Su dung: adc = 10bit thi gia tri cua adc 0 -> 1023 tuc la co 1024 gia tri
va co 1023 khoang lay gia tri, buoc thay doi la 5/1023.
Neu lay V tham chieu: Vref = 5V.
Su dung LM35:
10mV tuong ung 1 oC.
5000mV <----------> 1023 (ADC 10 bits)
dan den:
500 oC <-----------> 1023
x oC <------------> read_adc();
Suy ra:
Nhiet do do duoc:
x = 500 * read_adc()/1023 (don vi oC)
*/
Chuyendoi_7seg((unsigned int)nhiet_do);
Hienthi_7seg();
}
}
____link file ảnh __________________________________________________ _______________________
http://i.upanh.com/vipscm