Ðề tài: Sht71
View Single Post
Old 21-05-2010, 08:43 AM   #1
chungcb86
Đệ tử 1 túi
 
chungcb86's Avatar
 
Tham gia ngày: Dec 2009
Bài gửi: 24
:
Sht71

xin mọi người xem giúp phần code cho SHT71 viết cho PIC6f88 sao không chạy? không bít sai chỗ nào nữa.ma mô phỏng toàn sai thôi!
Thank!

code:
#include <16f88.h>
#include "def_88.h"
#include <stdio.h>
#fuses xt,nowdt,nolvp,noprotect
#use delay(clock=4000000)
#include "flex_lcd.c"
#use i2c(master,sda=pin_a1,scl=pin_a0)
#use rs232(baud=9600,parity=n,xmit=pin_a4,rcv=pin_a5)
#use fast_io(a)
#use fast_io(b)
unsigned int tempH,tempL,doamH,doamL;
float tempI,doamI;
float tempF,doamF,doamFI;

//hien thi so BCD
void lcd_putnum(int8 x)
{
long y,z,t;
//y=x/10; //lay hang chuc
//z=x-y*10; //lay hang don vi
//t=x*10-y*100-z*10; //lay phan le
y=x/100;
z=(x%100)/10;
t=(x%100)%10;
//chuyen qua ma ACSII
lcd_putc(y+48);
lcd_putc(z+48);
lcd_putc(",");
lcd_putc(t+48);
}

void main()
{
lcd_init();
trisa0=0;
//cho cam bien on dinh
delay_ms(15);
//reset qua trinh
i2c_start();
i2c_write(0xff);
while(true)
{
i2c_start();
delay_ms(5);
i2c_stop();
output_low(pin_a0);//keo SCK xuong muc 0
//phat mot lenh do nhiet do
tempH=i2c_write(0x03);
//doi cam bien do nhiet song
trisa1=1;
while(ra1==1)
{}
//doc gia tri nhiet do tra ve
tempH=i2c_read(1);
tempL=i2c_read(1);
//tinh gia tri cua nhiet do
tempI=tempH << 8 ;//dich sang trai 8 bit de lay bit cao
tempI=tempI+tempL;// ghep thanh so 16 bit
tempF=(tempI*0.01-40.1);
//truyen ra cong noi tiep
// tempF=(int8)(tempF*10);
// trisb=0x00;
// portb=tempF;
lcd_gotoxy(1,1);
lcd_putnum(tempF);

//doc byte checksum cua SHT71
i2c_read(1);
delay_ms(1000);
}
}
File Kèm Theo
File Type: rar PIC CCS.rar (71.1 KB, 62 lần tải)

thay đổi nội dung bởi: chungcb86, 21-05-2010 lúc 10:18 AM.
chungcb86 vẫn chưa có mặt trong diễn đàn   Trả Lời Với Trích Dẫn