Ðề tài: 16f877a with ds18b20
View Single Post
Old 31-07-2012, 05:58 PM   #10
mrtddiep
Nhập môn đệ tử
 
Tham gia ngày: May 2009
Bài gửi: 8
:
moi nguoi oi giup minh voi ! minh dang viet chuong trinh bang ccs cho pic16f877a doc nhiet do tu ds18b20 hien thi len lcd 16x2 .ma khong the nao doc nhiet do tu ds18b20 duoc luc nao lcd cung hien thi 84 ma minh tang giam ds18b20 thi tren lcd van khong thay doi. minh cung lam mach that va mo phong tren protues nhung ket qua nhu nhau thoi,cao thu nao xem giup minh sai cho nao voi ?. minh up code va mo phong o link duoi.
http://www.mediafire.com/?ood3ibt0qd1j3iw
#include <16F877A.h>
#fuses XT,NOWDT,NOPROTECT,NOLVP
#device adc=16
#include <lcd420.c>
#include <math.h>
#define dp pin_c0
#use delay(clock=4000000)

//---------reset--------------
void reset()
{
output_low(dp);
delay_us(500);
output_float(dp);
delay_us(500);
}

//-------------------------read----------------------
int read()
{
int a,data;
for(a=0;a<8;a++)
{
output_low(dp);
delay_us(10);
shift_right(&data,1,input(dp));
delay_us(45);
output_float(dp);
delay_us(2);
}
return(data);
}

//----------------------write-----------------------------
void write(int data)
{
int a;
for(a=0;a<8;a++)
{
set_tris_c(0x00);
output_low(dp);
delay_us(15);
output_bit(dp, shift_right(&data,1,0));
delay_us(45);
output_float(dp);
delay_us(2);
}
}
//---------------------chuong trinh chinh-------------------
void main()
{
int8 data,tem1,tem2,busy=0;
int16 temp;
float t;
reset();
write(0xcc);
write(0x44);
delay_ms(1000);
while(busy==0)
busy=read();
reset();
write(0xcc);
write(0xbe);
tem1=read();
tem2=read();
temp=make16(tem2,tem1);
temp=temp>>4;
t=(float)(temp);
while(true)
{
lcd_init();
lcd_gotoxy(1,2);
t=(int8)floor(t);
printf(lcd_putc,"%x",t);
delay_ms(1000);
}
}
mrtddiep vẫn chưa có mặt trong diễn đàn   Trả Lời Với Trích Dẫn