#include <main.h>
#include <lcd4bit.c>
unsigned char Code7Seg[] = {0xC0, 0xF9, 0xA4, 0xB0, 0x99, 0x92, 0x82, 0xF8, 0x80, 0x90};
int16 kqadc,donvi,chuc;
void hienthiadcva7doan()
{
set_tris_d(0x00);
set_tris_a(0x00);
set_adc_channel(0);
setup_adc(adc_clock_div_2);
setup_adc_ports(AN0);
kqadc=0;
for(int i=0;i<200;i++)
{
kqadc=kqadc+read_adc();
delay_ms(1);
}
kqadc=kqadc/2.046;
kqadc=kqadc/200;
chuc =kqadc/10;
donvi=kqadc%10;
output_high(PIN_C0);
output_B(code7seg[chuc]);
delay_ms(1);
output_low(PIN_C0);
output_high(PIN_C1);
output_B(code7seg[donvi]);
delay_ms(1);
output_low(PIN_C1);
}
void canhbaonhietdo()
{
output_high(PIN_C2);
}
void main()
{
LCD_Init();
while(TRUE)
{
hienthiadcva7doan();
if(kqadc>=32)
{
canhbaonhietdo();
LCD_PutCmd(0x80);
LCD_PutChar("Nhiet do cao !!!");
}
else
{
output_low(PIN_C2);
LCD_PutCmd(0x80);
LCD_PutChar("Nhiet do : ");
}
LCD_PutCmd(0xc0);
WriteNum(kqadc);
}
}
Tải Project này về : https://mega.nz/#!uN8GWTqQ!7hPx-wF0Nexw3bOqOWjeJvj5OitBqFWwIZazRJ3_05Q
0 nhận xét:
Đăng nhận xét