16f877a with ds18b20

Collapse
X
 
  • Giờ
  • Show
Clear All
new posts
  • tdm
    Đệ tử 7 túi
    • May 2005
    • 258

    #1

    16f877a with ds18b20

    gởi các bạn tài liệu để tham khảo:
    Attached Files
    viết chương trình cho vdk chạy ổn định là cả một vấn đề.
  • motu
    Đệ tử 4 túi
    • Oct 2007
    • 79

    #2
    Đang bị stress với con DS18b20 này, để test thử code chạy ok o. Thk bạn nhiều.
    Dao nao cung la dao, dao cao dai cung la dao.

    Comment

    • motu
      Đệ tử 4 túi
      • Oct 2007
      • 79

      #3
      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.
      Dao nao cung la dao, dao cao dai cung la dao.

      Comment

      • huchigo
        Nhập môn đệ tử
        • Jul 2010
        • 1

        #4
        con tuyet chieu nao ko gui len luon

        Comment

        • pdkxlily
          Đệ tử 2 túi
          • Mar 2011
          • 27

          #5
          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

          Comment

          • motu
            Đệ tử 4 túi
            • Oct 2007
            • 79

            #6
            Nguyên văn bởi pdkxlily View Post
            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.
            Dao nao cung la dao, dao cao dai cung la dao.

            Comment

            • anhhungne69
              Nhập môn đệ tử
              • Oct 2010
              • 4

              #7
              xin sua giup code , minh dang lam do an nhiet dung 18b20 wet led 7 doan.thank

              #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);
              }

              Comment

              • anhhungne69
                Nhập môn đệ tử
                • Oct 2010
                • 4

                #8
                xin sua giup code , minh dang lam do an nhiet dung 18b20 wet led 7 doan.thank

                #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);
                }

                Comment

                • mrtddiep
                  Nhập môn đệ tử
                  • May 2009
                  • 8

                  #9
                  thank cac bac nha minh cung dang lam ma chua dc.hi vong vot xong code ban share minh se lam duoc

                  Comment

                  • mrtddiep
                    Nhập môn đệ tử
                    • May 2009
                    • 8

                    #10
                    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);
                    }
                    }

                    Comment

                    • haibang3000
                      Nhập môn đệ tử
                      • May 2010
                      • 3

                      #11
                      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

                      Comment

                      • noidongcoida
                        Nhập môn đệ tử
                        • Feb 2013
                        • 1

                        #12
                        thank bạn nhiều, mình đang cần cái này.

                        Comment

                        Working...