đây là code làm cho bài tập lớn đây ko biết sai chỗ nào mà nó cứ hiẻn ra LCD là 0 độ.
Các bác xem hộ giúp em
#include <16F877A.h>
#device 16F877*=16
#device ADC=10
#fuses NOWDT, HS, NOPUT, NOPROTECT, NODEBUG, NOBROWNOUT, NOLVP, NOCPD, NOWRT
#use delay(clock=20000000)
#use rs232 (Baud=9600)
#include"lcd_lib_4bit.c"
#include"def_877a.h"
#include"1wire.c"
byte CONST SO[10]={0x30,0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x3 9};
int8 read_ds1820()
{
byte mang[8];
int8 busy=0,i;
signed int16 temp3;
float result;
onewire_reset();
onewire_write(0xCC); //cho phep truy cap den DS1820
onewire_write(0x44); // chuyen doi gia tri nhiet do thanh so nhi phan
delay_ms(200); // thoi gian chuyen doi
while (busy == 0) //
{
busy = onewire_read();
}
onewire_reset();
onewire_write(0xCC);
onewire_write(0xBE); //cho Phep MU doc data trong DS1820
for(i=0;i<8;i++)
{
mang[i]= onewire_read();
}
temp3 = make16(mang[1],mang[0]);
result = (float) temp3/8.0 ;//TINH TOAN CHO DS18B20
// result = (float) temp3 / 16.0; //do phan giai 0.1
// delay_ms(200);
return(result);
}
void hienthi_temp(long x)
{
int tram,chuc,donvi,y;
tram=x/100;
y=x%100;
chuc=y/10;
donvi=y%10;
lcd_putcmd(0x89);
if(x>=100)
{
lcd_putchar(SO[tram]);
lcd_putchar(SO[chuc]);
lcd_putchar(SO[donvi]);
lcd_putchar("C");
}
else if (x<100)
{
lcd_putchar(SO[chuc]);
lcd_putchar(SO[donvi]);
lcd_putchar("C");
lcd_putcmd(0x8c);
lcd_putchar(" ");
}
}
void main()
{
float temp;
//setup_ADC(ADC_clock_internal);
//setup_ADC_ports(analog_RA3_Ref);
//set_ADC_channel(0);
LCD_Init();
/*
lcd_putcmd(0x80);
lcd_putchar("Welcome PIC16F87");
lcd_putcmd(0xc0);
lcd_putchar("7A");
lcd_putchar(" test LCD-4bit");
delay_ms(10);
lcd_putcmd(0x80);
lcd_putchar(" ");
lcd_putcmd(0xc0);
lcd_putchar(" ");
*/
lcd_putcmd(0x80);
lcd_putchar("NHIET DO:");
while(true)
{
temp=read_ds1820();
hienthi_temp(temp);
delay_ms(500);
}
}
Các bác xem hộ giúp em
#include <16F877A.h>
#device 16F877*=16
#device ADC=10
#fuses NOWDT, HS, NOPUT, NOPROTECT, NODEBUG, NOBROWNOUT, NOLVP, NOCPD, NOWRT
#use delay(clock=20000000)
#use rs232 (Baud=9600)
#include"lcd_lib_4bit.c"
#include"def_877a.h"
#include"1wire.c"
byte CONST SO[10]={0x30,0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x3 9};
int8 read_ds1820()
{
byte mang[8];
int8 busy=0,i;
signed int16 temp3;
float result;
onewire_reset();
onewire_write(0xCC); //cho phep truy cap den DS1820
onewire_write(0x44); // chuyen doi gia tri nhiet do thanh so nhi phan
delay_ms(200); // thoi gian chuyen doi
while (busy == 0) //
{
busy = onewire_read();
}
onewire_reset();
onewire_write(0xCC);
onewire_write(0xBE); //cho Phep MU doc data trong DS1820
for(i=0;i<8;i++)
{
mang[i]= onewire_read();
}
temp3 = make16(mang[1],mang[0]);
result = (float) temp3/8.0 ;//TINH TOAN CHO DS18B20
// result = (float) temp3 / 16.0; //do phan giai 0.1
// delay_ms(200);
return(result);
}
void hienthi_temp(long x)
{
int tram,chuc,donvi,y;
tram=x/100;
y=x%100;
chuc=y/10;
donvi=y%10;
lcd_putcmd(0x89);
if(x>=100)
{
lcd_putchar(SO[tram]);
lcd_putchar(SO[chuc]);
lcd_putchar(SO[donvi]);
lcd_putchar("C");
}
else if (x<100)
{
lcd_putchar(SO[chuc]);
lcd_putchar(SO[donvi]);
lcd_putchar("C");
lcd_putcmd(0x8c);
lcd_putchar(" ");
}
}
void main()
{
float temp;
//setup_ADC(ADC_clock_internal);
//setup_ADC_ports(analog_RA3_Ref);
//set_ADC_channel(0);
LCD_Init();
/*
lcd_putcmd(0x80);
lcd_putchar("Welcome PIC16F87");
lcd_putcmd(0xc0);
lcd_putchar("7A");
lcd_putchar(" test LCD-4bit");
delay_ms(10);
lcd_putcmd(0x80);
lcd_putchar(" ");
lcd_putcmd(0xc0);
lcd_putchar(" ");
*/
lcd_putcmd(0x80);
lcd_putchar("NHIET DO:");
while(true)
{
temp=read_ds1820();
hienthi_temp(temp);
delay_ms(500);
}
}
Comment