nguyenlien89
Thành viên mới

- Tham gia
- 21/7/11
- Bài viết
- 1
- Được thích
- 0
#include <16F877A.h>
#include <def_877a.h>
#device *=16 adc=10
#FUSES NOWDT, HS, NOPUT, NOPROTECT, NODEBUG, NOBROWNOUT,NOLVP, NOCPD, NOWRT
#use delay(clock=20000000)
#include <LCD4bit.h> // Thu vien ham cho LCD
#define temp_default 25
unsigned int tram,chuc,donvi;
int do_F;
float value;
int8 template1; //nhiet do mau a
unsigned int16 count;
//================================================================
void convert_bcd(int8 x);
void display();
void welcome();
#int_timer0
void ngat_time0()
{
set_timer0(5);
count++;
if(count==200*10000){
if (do_F == 1) do_F=0;
else do_F=1;
count=0;
}
}
void main()
{
trisa = 0xFF;
trisb = 0xFF;
do_F=0;
LCD_init();
//==== Khoi tao cho ngat ngoai===============================================
enable_interrupts (INT_EXT);
ext_int_edge(H_TO_L);
enable_interrupts (GLOBAL);
//=========== Khoi tao che do cho bo ADC=====================================
setup_adc_ports(ALL_ANALOG);
setup_adc(ADC_CLOCK_INTERNAL);
//=========Khoi tao Time0=======================
enable_interrupts(INT_TIMER0);
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_2);
set_timer0(5);
welcome();
template1=temp_default;
while (1)
{
LCD_Cmd(0x01);
LCD_Char("4r:codientu.org");
display();
delay_ms(1000);
}
}
void display()
{
//=================Channel AN1===============
set_adc_channel(1);
value = (float)read_adc();
delay_ms(10);
value=value/2.048;
if(value<50)
{
LCD_Cmd(0xc0);
LCD_Char("Nhiet do:");
if (do_F==1)
value=1.8*value+32;
convert_bcd((int8)value);
LCD_Cmd(0xCA);
if(value>100)
LCD_Char(tram);
LCD_Char(chuc);
LCD_Char(donvi);
if (do_F==0)
LCD_Char("^C ");
else
LCD_Char("^F ");
}
}
void convert_bcd(int8 x)
{
tram =x/100;
chuc =x/10;
chuc = chuc %10;
donvi =x%10;
tram = tram +0x30;
chuc = chuc + 0x30;
donvi = donvi + 0x30;
}
//============================Run a text on LCD to welcom=======================
Void welcome(){
int x=0;
LCD_Cmd(0x01); //=========Clear LCD=========================
LCD_Position(0xF);
LCD_Char("SU DUNG LM35");
LCD_Cmd(0xCF);
LCD_Char("S G E S V N");
while (x<35){
LCD_Cmd(0x18);
delay_ms(400);
x++;
}
}
#include <def_877a.h>
#device *=16 adc=10
#FUSES NOWDT, HS, NOPUT, NOPROTECT, NODEBUG, NOBROWNOUT,NOLVP, NOCPD, NOWRT
#use delay(clock=20000000)
#include <LCD4bit.h> // Thu vien ham cho LCD
#define temp_default 25
unsigned int tram,chuc,donvi;
int do_F;
float value;
int8 template1; //nhiet do mau a
unsigned int16 count;
//================================================================
void convert_bcd(int8 x);
void display();
void welcome();
#int_timer0
void ngat_time0()
{
set_timer0(5);
count++;
if(count==200*10000){
if (do_F == 1) do_F=0;
else do_F=1;
count=0;
}
}
void main()
{
trisa = 0xFF;
trisb = 0xFF;
do_F=0;
LCD_init();
//==== Khoi tao cho ngat ngoai===============================================
enable_interrupts (INT_EXT);
ext_int_edge(H_TO_L);
enable_interrupts (GLOBAL);
//=========== Khoi tao che do cho bo ADC=====================================
setup_adc_ports(ALL_ANALOG);
setup_adc(ADC_CLOCK_INTERNAL);
//=========Khoi tao Time0=======================
enable_interrupts(INT_TIMER0);
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_2);
set_timer0(5);
welcome();
template1=temp_default;
while (1)
{
LCD_Cmd(0x01);
LCD_Char("4r:codientu.org");
display();
delay_ms(1000);
}
}
void display()
{
//=================Channel AN1===============
set_adc_channel(1);
value = (float)read_adc();
delay_ms(10);
value=value/2.048;
if(value<50)
{
LCD_Cmd(0xc0);
LCD_Char("Nhiet do:");
if (do_F==1)
value=1.8*value+32;
convert_bcd((int8)value);
LCD_Cmd(0xCA);
if(value>100)
LCD_Char(tram);
LCD_Char(chuc);
LCD_Char(donvi);
if (do_F==0)
LCD_Char("^C ");
else
LCD_Char("^F ");
}
}
void convert_bcd(int8 x)
{
tram =x/100;
chuc =x/10;
chuc = chuc %10;
donvi =x%10;
tram = tram +0x30;
chuc = chuc + 0x30;
donvi = donvi + 0x30;
}
//============================Run a text on LCD to welcom=======================
Void welcome(){
int x=0;
LCD_Cmd(0x01); //=========Clear LCD=========================
LCD_Position(0xF);
LCD_Char("SU DUNG LM35");
LCD_Cmd(0xCF);
LCD_Char("S G E S V N");
while (x<35){
LCD_Cmd(0x18);
delay_ms(400);
x++;
}
}