PIC Vietnam

Go Back   PIC Vietnam > Microchip PIC > Các ngôn ngữ lập trình khác (CCS C, HT PIC,...)

Tài trợ cho PIC Vietnam
Trang chủ Đăng Kí Hỏi/Ðáp Thành Viên Lịch Tìm Kiếm Bài Trong Ngày Ðánh Dấu Ðã Ðọc Vi điều khiển

 
 
Ðiều Chỉnh Xếp Bài
Prev Previous Post   Next Post Next
Old 24-01-2014, 12:48 PM   #1
lyxa_bk
Đệ tử 1 túi
 
Tham gia ngày: Oct 2013
Bài gửi: 20
:
nhờ giúp đỡ code đo nhiệt độ hiển thi ra led dung DS18B20

đây là đoạn code của mình, ai hiểu sâu vấn đề nào vào tư vấn giúp mình với

#include <main.h>
#define DQ pin_c1 // chân C1 nối DQ
const char m[10]={0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8,0x80,0x9 0};
int nghin,tram,chuc,donvi;
// hiển thị ra led 7 đoạn, hàm này chạy tốt vì mình đã đo ADC qua hiển thị led.
void hienthiso(int16 c)
{
nghin=c/1000;
tram=(c%1000)/100;
chuc=((c%1000)%100)/10;
donvi= (((c%1000)%100)%10)/1;
while(true)
{
if(nghin>0)
{
output_d(m[nghin]);
output_a(12);
delay_ms(1);
output_d(255);
delay_ms(1);
}
if(tram>0||nghin>0)
{
output_d(m[tram]);
output_a(16);
delay_ms(1);
output_d(255);
delay_ms(1);
}
if(chuc>0||tram>0||nghin>0)
{
output_d(m[chuc]);
output_a(20);
delay_ms(1);
output_d(255);
delay_ms(1);
}
if(donvi>=0||chuc>0||tram>0||nghin>0)
{
output_d(m[donvi]);
output_a(24);
delay_ms(1);
output_d(255);
delay_ms(1);
}
}
}
// reset va start DS18B20
char reset_start()
{
int a;
output_low(DQ);
delay_us(480);
output_float(DQ);
delay_us(65);
a=!input(DQ);
delay_us(240);
if(a)
return(1);
else
return(0);
}
//doc 1 byte tu DS18B20
byte read_byte()
{
byte i;
byte Din;
for(i=0;i<8;i++)
{
output_low(DQ);
delay_us(4);
output_float(DQ);
delay_us(5);
shift_right(&Din,1,input(DQ));
delay_us(100);
}
return (Din);
}
//ghi 1 byte len DS18B29
byte write_byte(byte Dout)
{
byte i;
for(i=0;i<8;i++)
{
output_low(DQ);
delay_us(10);
if(shift_right(&Dout,1,0))
output_high(DQ);
else
output_low(DQ);
delay_us(5);
output_high(DQ);
delay_us(5);
}
return(1);
}
void config(unsigned char A_th,A_tl,mode)
{
reset_start();
write_byte(0x4e);
write_byte(A_th);
write_byte(A_tl);
write_byte(mode);
}
// doc nhiet do
float read_tem()
{
int8 busy=0, tem1, tem2;
int16 tem3;
float result;
reset_start();
write_byte(0xCC);
write_byte(0x44);
while(busy==0)
busy=read_byte();
reset_start();
write_byte(0xCC);
write_byte(0xBE);
tem1=read_byte();
tem2=read_byte();
tem3= make16(tem2,tem1);
result=(float)tem3/16.0;
delay_ms(200);
return(result);
}
void main()
{
float tem;
while(true)
{
tem = read_tem();
hienthiso(tem);
}
}


mình không rõ là sai ở đâu khi nạp code thì thấy hiện lên số 4095 trên led 7 đoan??
lyxa_bk vẫn chưa có mặt trong diễn đàn   Trả Lời Với Trích Dẫn
 

Ðiều Chỉnh
Xếp Bài

Quyền Sử Dụng Ở Diễn Ðàn
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is Mở
Smilies đang Mở
[IMG] đang Mở
HTML đang Tắt

Chuyển đến


Múi giờ GMT. Hiện tại là 05:59 PM.


Được sáng lập bởi Đoàn Hiệp
Powered by vBulletin®
Page copy protected against web site content infringement by Copyscape
Copyright © PIC Vietnam