PIC Vietnam

Go Back   PIC Vietnam > Truyền thông > Giao tiếp USB, CAN, I2C, SPI, USART...

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

Giao tiếp USB, CAN, I2C, SPI, USART... Những giao tiếp được tích hợp trên PIC

 
 
Ðiều Chỉnh Xếp Bài
Prev Previous Post   Next Post Next
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
 


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à 06:22 AM.


Đượ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