![]() |
PIC 18F877A giao tiep voi DS18B20 do nhiet do
em đang có đề tài vi xử lý thầy cho mà chưa ra mong mấy bác giúp đỡ
đề tài: dùng pic16f877a giao tiếp với ds18b20 và 3 led 7 đoạn, viết chương trình đo nhiệt độ dùng assembly |
minh cung lam mach nhu z ma dung lap trinh ccs , minh cung da viet code nhung chay k
1 Attachment(s)
#include<16F877A.h>
#device *=16 #fuses HS,NOPROTECT,NOLVP, NOWDT, 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); } |
Múi giờ GMT. Hiện tại là 04:29 PM. |
Tên diễn đàn: vBulletin Version 3.8.11
Được sáng lập bởi Đoàn Hiệp.
Copyright © PIC Vietnam