RP Store Tìm linh kiện theo mã, gửi BOM nhận báo giá Gửi BOM

Sht71

Collapse
X
 
  • Giờ
  • Show
Clear All
new posts
  • chungcb86
    Đệ tử 1 túi
    • Dec 2009
    • 24

    #1

    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);
    }
    }
    Attached Files
    Last edited by chungcb86; 21-05-2010, 09:18 AM.
  • chungcb86
    Đệ tử 1 túi
    • Dec 2009
    • 24

    #2
    có ai giup đệ với!
    Thank@@

    Comment

    • giang49ctu
      Nhập môn đệ tử
      • Oct 2010
      • 1

      #3
      chào mọi người!
      hiện mình đang cần một con SHT71, ai có bán thì liên hệ với mình nhé.
      sđt:01275834018 hoăc gmail:giang49ctu@gmail.com
      thanks!

      Comment

      • hawking1122
        Nhập môn đệ tử
        • Mar 2010
        • 10

        #4
        Sao bạn lại dùng giao tiếp i2c để truyền giữa VDK và sht71? Trong datasheet của SHT71 có ghi rõ là (trang 2): The serial interface of the SHTxx is optimized for sensor readout
        and power consumption and is not compatible with I2C interfaces.
        Bạn có thể xem driver giao tiếp với SHT71 trên forum của CCS nhé.

        Comment

        • nvquyvn
          Đệ tử 1 túi
          • Mar 2011
          • 15

          #5
          Ngu thế ko dùng giao tiếp I2c thì dùng ji dúng là ...)

          Comment

          • KVLV
            Đệ tử 2 túi
            • Aug 2010
            • 42

            #6
            Nguyên văn bởi nvquyvn View Post
            Ngu thế ko dùng giao tiếp I2c thì dùng ji dúng là ...)
            bạn đừng bao giờ bảo ai ngu... và đừng phán bừa...

            đây là tin tức trên datasheet:
            The serial interface of the SHT7x is optimized for sensor
            readout and effective power consumption. The sensor
            cannot be addressed by I2C protocol, however, the sensor
            can be connected to an I2C bus without interference with
            other devices connected to the bus. Microcontroller must
            switch between protocols. (trang 4/11)

            bạn có thể đọc và hiểu chứ.

            Comment

            Working...