bác nào giúp em kiểm tr xem code nào chỗ nào chưa đc với. em nghi là nó ko search đc con ds nào hay sao ý.em cảm ơn nhiều nhiều!
Code:
/* CHUONG TRINH QUET 6 LED 7 THANH PORTD CHON LED PORTB XUAT DU LIEU */ #include <1wire.h> #include <delay.h> #include <stdio.h> #include <mega16.h> #include <ds18b20.h> #include <io.h> #asm .equ __w1_port=0x1b .equ __w1_bit=6 #endasm #asm .equ __led_port=0x18 #endasm // HAM THIET LAP PORTD,B LAM CONG RA void congra(){ DDRD = 0XFF; DDRB = 0XFF; } // HAM XUAT DU LIEU void xuatdl(unsigned char x){ switch (x){ case 0: PORTB = 0xC0; break; case 1: PORTB = 0xF9; break; case 2: PORTB = 0xA4; break; case 3: PORTB = 0xB0; break; case 4: PORTB = 0x99; break; case 5: PORTB = 0x92; break; case 6: PORTB = 0x82; break; case 7: PORTB = 0xF8; break; case 8: PORTB = 0x80; break; case 9: PORTB = 0x90; break; }; } // HAM HIEN THI 1 SO 4 CHU SO CHO TRUOC void hienthitemp(unsigned short n){ int i,soled; unsigned char sothu[6]; if (n<1000) soled = 3; else soled = 4; for (i=1; i<=6; i++){ //LUU 4 CHU SO VAO MANG SOTHU sothu[i] = n%10; //BAT DAU LA SOTHU[1] LA SO HANG DON VI n = n/10; }; // QUET LED HIEN THI for (i=1; i<=soled; i++){ PORTD = 0x01; PORTB = 0x46; delay_ms(4); PORTD = PORTD<<i; xuatdl(sothu[i]); delay_ms(4); PORTB = 0xFF; }; } // HAM HIEN THI NHIET DO void temperature(){ unsigned char i,devices; unsigned char rom_code[8][9]; float temp; devices = w1_search(0xf0,rom_code); if (!devices) while (1); for (i=0; i<devices;){ if (!ds18b20_init(&rom_code[i++][0],10,40,DS18B20_12BIT_RES)) while (1); } for (i=0;i<devices;i++){ temp=ds18b20_temperature(&rom_code[i][0]); } hienthitemp(temp); } // CHUONG TRINH CHINH void main(){ while(1){ congra(); temperature(); }; }
Comment