PDA

View Full Version : 16f877a with ds18b20


tdm
23-02-2010, 02:29 PM
gởi các bạn tài liệu để tham khảo:

motu
12-03-2010, 03:52 PM
Đang bị stress với con DS18b20 này, để test thử code chạy ok o. Thk bạn nhiều.

motu
12-03-2010, 10:11 PM
Mạch đã chạy, giải tỏa được stress, một lần nữa xin cảm ơn bạn tdm rất nhiều.

huchigo
08-07-2010, 05:46 PM
con tuyet chieu nao ko gui len luon

pdkxlily
14-04-2011, 02:15 AM
bác thử kết nối thêm realtime 1307 gt I2C chưa . e làm đang làm con này thêm 1307 mà vẫn chưa chạy

motu
21-04-2011, 11:54 PM
bác thử kết nối thêm realtime 1307 gt I2C chưa . e làm đang làm con này thêm 1307 mà vẫn chưa chạy

Bạn phải hỏi cụ thể thì mới trả lời được chứ, mình đã làm cái đồng hồ có đo nhiệt độ luôn, hai con này chạy độc lập mà, đâu có liên quan gì đâu, bạn nên làm riêng chạy ổn định rồi hãy ghép vào chung mạch, như vậy dễ dò ra lỗi hơn. Chúc vui.

anhhungne69
26-09-2011, 08:14 PM
#include<16F877A.h>
#device *=16
#fuses HS,NOPROTECT,NOLVP, NOWDT, NOLVP, NOBROWNOUT,NOPUT
#USE delay(clock=2000000)
#define TOUCH_PIN pin_a0
#include<touch.c>
void hienthi(int8 a,int8 b,int8 c);
int8 const seg7[10]=
{0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90 };
//chuong trinh chinh======//
void main(){
int8 tam1=0,tam2,ss,i;
int8 led1,led2,led3;
int16 nd;
//=====cai dat chuyen doi nhiet do 9bit========
//========================
touch_present();
touch_write_byte(0xcc);// phat lenh skip ROM
touch_write_byte(0x4e);// phat lenh ghi 2byte du lieu to Scratchpad
touch_write_byte(0x33);// ghi 2 byte Trong
touch_write_byte(0x33);//
touch_write_byte(0x1f);// cau hinh cho thanh ghi nhiet do (do phan giai 9 bit)
touch_present();
touch_write_byte(0xCC);// skip ROM
touch_write_byte(0x48);//Sao chep Sratchpad vao Eeprom
//====vong lap chuong trinh chinh=====//
while(TRUE){
do{
if(touch_present())
{
touch_write_byte(0xCC);
touch_write_byte(0x44);//xuat lenh chuyen doi nhiet do
for(i=0;i<7;++i)
{
hienthi(led1,led2,led3);
}
touch_present();
touch_write_byte(0xCC);
TOUCH_WRITE_BYTE(0xBE);//lenh doc bo nho nhap
tam1=touch_read_byte();//doc 2 byte nhiet do
tam2=touch_read_byte();//doc 2 byte nhiet do
}
}
while(tam1==ss);// so sanh gia tri nhiet do doc duoc voi gia tri truoc do
ss=tam1;
//==chuyen doi nhiet do sang so thap nhan====
nd=make16(tam2,tam1);
nd=nd>>4;//dich phat 4 bit
nd=nd&0x0ff;//lay 8 bit thap
if(bit_test(nd,7))//neu gia tri nhiet do am
{
led3=10;//led3 hien thi dau""-""
nd=~(--nd);//lay bu 2 gia tri nhiet do
nd=nd&0x0ff;// xoa byte cao
}
else// neu gia tri nhiet do duong
{
led3=nd/100;//led3 hien thi so hang tram
nd=nd%100;
}
led2=nd/10;//led2 hien thi so hang chuc
led1=nd%10;//led1 hien thi so hang don vi
}
}
//chuong trinh hien thi_quet led===
void hienthi(int8 a,int8 b,int8 c)
{
output_b(seg7[a]);
output_low(pin_d7);
delay_ms(1);
output_high(pin_d7);
output_b(seg7[b]);
output_low(pin_d6);
delay_ms(1);
output_high(pin_d6);
output_b(seg7[c]);
output_low(pin_d5);
delay_ms(1);
output_high(pin_d5);
}

anhhungne69
26-09-2011, 08:21 PM
#include<16F877A.h>
#device *=16
#fuses HS,NOPROTECT,NOLVP, NOWDT, NOLVP, NOBROWNOUT,NOPUT
#USE delay(clock=2000000)
#define TOUCH_PIN pin_a0
#include<touch.c>
void hienthi(int8 a,int8 b,int8 c);
int8 const seg7[10]=
{0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90 };
//chuong trinh chinh======//
void main(){
int8 tam1=0,tam2,ss,i;
int8 led1,led2,led3;
int16 nd;
//=====cai dat chuyen doi nhiet do 9bit========
//========================
touch_present();
touch_write_byte(0xcc);// phat lenh skip ROM
touch_write_byte(0x4e);// phat lenh ghi 2byte du lieu to Scratchpad
touch_write_byte(0x33);// ghi 2 byte Trong
touch_write_byte(0x33);//
touch_write_byte(0x1f);// cau hinh cho thanh ghi nhiet do (do phan giai 9 bit)
touch_present();
touch_write_byte(0xCC);// skip ROM
touch_write_byte(0x48);//Sao chep Sratchpad vao Eeprom
//====vong lap chuong trinh chinh=====//
while(TRUE){
do{
if(touch_present())
{
touch_write_byte(0xCC);
touch_write_byte(0x44);//xuat lenh chuyen doi nhiet do
for(i=0;i<7;++i)
{
hienthi(led1,led2,led3);
}
touch_present();
touch_write_byte(0xCC);
TOUCH_WRITE_BYTE(0xBE);//lenh doc bo nho nhap
tam1=touch_read_byte();//doc 2 byte nhiet do
tam2=touch_read_byte();//doc 2 byte nhiet do
}
}
while(tam1==ss);// so sanh gia tri nhiet do doc duoc voi gia tri truoc do
ss=tam1;
//==chuyen doi nhiet do sang so thap nhan====
nd=make16(tam2,tam1);
nd=nd>>4;//dich phat 4 bit
nd=nd&0x0ff;//lay 8 bit thap
if(bit_test(nd,7))//neu gia tri nhiet do am
{
led3=10;//led3 hien thi dau""-""
nd=~(--nd);//lay bu 2 gia tri nhiet do
nd=nd&0x0ff;// xoa byte cao
}
else// neu gia tri nhiet do duong
{
led3=nd/100;//led3 hien thi so hang tram
nd=nd%100;
}
led2=nd/10;//led2 hien thi so hang chuc
led1=nd%10;//led1 hien thi so hang don vi
}
}
//chuong trinh hien thi_quet led===
void hienthi(int8 a,int8 b,int8 c)
{
output_b(seg7[a]);
output_low(pin_d7);
delay_ms(1);
output_high(pin_d7);
output_b(seg7[b]);
output_low(pin_d6);
delay_ms(1);
output_high(pin_d6);
output_b(seg7[c]);
output_low(pin_d5);
delay_ms(1);
output_high(pin_d5);
}

mrtddiep
23-07-2012, 04:31 PM
thank cac bac nha minh cung dang lam ma chua dc.hi vong vot xong code ban share minh se lam duoc

mrtddiep
31-07-2012, 05:58 PM
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);
}
}

haibang3000
06-11-2012, 01:20 PM
bạn phải đọc byte 2,3 của bộ nhớ nháp chứ! ở trên mình thấy bạn mới chỉ đọc đến byte0 và 1 chứ mấy

noidongcoida
25-02-2013, 02:24 PM
thank bạn nhiều, mình đang cần cái này.