Nguyên văn bởi Vinhanboy
Xem bài viết
Thông báo
Collapse
No announcement yet.
Báo cháy sử dụng cảm biến DS18B20 và 8051 hiển thị LCD
Collapse
X
-
Tình hình là đã xong được phần đo nhiệt độ của 4 con DS18b20, làm riêng nên viết code thật dài
. Nhưng bây giờ lại có theo một lỗi nữa, mà không biết tại làm sao. Trên LCD mình muốn hiển thị : Dòng 1 là số lượng xe , dòng 2 là nhiệt độ cao nhất . Nhưng mà khi chạy thì dòng 1 nó hiển thị sai ( ví dụ 50 thì nó hiển thị là y35) , trong khi dòng 2 vẫn hiển thị phần nhiệt độ đó được, mình ngắt kết nối với con DS18B20 ( trong hàm main vẫn gọi các lệnh đọc nhiệt độ bình thường ) thì dòng 1 lại hiển thị đúng. Các bác có cao kiến gì cho mình tham khảo với.
Code đây : Hơi dài, mong các bác thông cảm
Code:#include<stdio.h> #include<reg51.h> sbit DQ = P2^0; sbit DQ2 = P2^1; sbit DQ3 = P2^2; sbit DQ4 = P2^3; char readdata[2]; unsigned int t1,t2,t3,t4,nhietdo; int xe= 50; sbit xevao = P3^0; sbit xera = P3^1; // Khai bao cho LCD -- sbit RS = P3^6; sbit EN = P3^7; //RW=1 => doc //RS=0 => code //RS=1 => data #define lcd_PORT P0 //=========================== void delay_ms1(int n) { int k,j; for(k=0;k<n;k++) { for(j=0;j<500;j++); } } //========================== void delay_5ms(){ int i,j; for(i=0;i<250;i++) for(j=0;j<4;j++){} } //=========================== void delay_15ms(){ int i,j; for(i=0;i<250;i++) for(j=0;j<100;j++){} } //============================ void lcd_command(unsigned char c) //CT con ghi du lieu len LCD { RS=0; lcd_PORT=c; EN=1; EN=0; delay_5ms(); } //============================== void lcd_data(unsigned char c) //CT con doc du lieu tu LCD { RS=1; lcd_PORT=c; EN=1; EN=0; delay_5ms(); } //=============================== void lcd_init() // Khoi tao LCD { delay_15ms(); lcd_command(0x38); lcd_command(0x0C); lcd_command(0x01); // Xoa man hinh LCD } //============================= void lcd_putsf(unsigned char *s) { while (*s) { lcd_data(*s); s++; } } //------------------DS18b20--------------------------------------------------------------------- void DelayUs(int us) { int i; for (i=0; i<us; i++); } //---------------------------------------- // Reset DS1820 //---------------------------------------- bit ResetDS1820(void) { bit presence; DQ = 0; //pull DQ line low DelayUs(29); // leave it low for about 490us DQ = 1; // allow line to return high DelayUs(3); // wait for presence 55 uS presence = DQ; // get presence signal DelayUs(25); // wait for end of timeslot 316 uS return(presence); // presence signal returned } // 0=presence, 1 = no part //----------------------------------------- // Read one bit from DS1820 //----------------------------------------- unsigned char ReadBit(void) { unsigned char i; DQ = 0; // pull DQ low to start timeslot DQ=1; for (i=0; i<3; i++); // delay 17 us from start of timeslot return(DQ); // return value of DQ line } //----------------------------------------- // Write one bit to DS1820 //----------------------------------------- void WriteBit(char bitval) { DQ=0; if(bitval==1) DQ = 1; DelayUs(5); // delay about 39 uS DQ = 1; } //----------------------------------------- // Read 1 byte from DS1820 //----------------------------------------- unsigned char ReadByte(void) { unsigned char i; unsigned char value = 0; for (i=0;i<8;i++) { if(ReadBit()) value|=0x01<<i; DelayUs(6); } return(value); } //----------------------------------------- // Write 1 byte //----------------------------------------- void WriteByte(char val) { unsigned char i; unsigned char temp; for (i=0; i<8; i++) // writes byte, one bit at a time { temp = val>> i; temp &=0x01; WriteBit(temp); } DelayUs(5); } //----------------------------------------- // Read temperature //----------------------------------------- void ReadTemp(void) { int k; int thap, cao=0; ResetDS1820(); WriteByte(0xcc); // skip ROM WriteByte(0x44); // perform temperatur conversion while (ReadByte()==0xff); // wait for conversion complete ResetDS1820(); WriteByte(0xcc); // skip ROM WriteByte(0xbe); // read the result for (k=0; k<9; k++) // read 9 bytes but, use only one byte { readdata[k]=ReadByte(); // read DS1820 } thap = readdata[0]; cao = readdata[1]; readdata[1]=readdata[1]<<4; readdata[1]=readdata[1] & 0x70; thap=readdata[0]; thap=thap>>4; thap=thap & 0x0f; readdata[1]=readdata[1] | thap; thap=2; t1=readdata[1]; } // ---------------------------- DS18B20 --------> 2 --------------------- bit ResetDS18202(void) { bit presence; DQ2 = 0; //pull DQ line low DelayUs(29); // leave it low for about 490us DQ2 = 1; // allow line to return high DelayUs(3); // wait for presence 55 uS presence = DQ2; // get presence signal DelayUs(25); // wait for end of timeslot 316 uS return(presence); // presence signal returned } // 0=presence, 1 = no part //----------------------------------------- // Read one bit from DS1820 //----------------------------------------- unsigned char ReadBit2(void) { unsigned char i; DQ2 = 0; // pull DQ low to start timeslot DQ2 = 1; for (i=0; i<3; i++); // delay 17 us from start of timeslot return(DQ2); // return value of DQ line } //----------------------------------------- // Write one bit to DS1820 //----------------------------------------- void WriteBit2(char bitval) { DQ2=0; if(bitval==1) DQ2 = 1; DelayUs(5); // delay about 39 uS DQ2 = 1; } //----------------------------------------- // Read 1 byte from DS1820 //----------------------------------------- unsigned char ReadByte2(void) { unsigned char i; unsigned char value = 0; for (i=0;i<8;i++) { if(ReadBit2()) value|=0x01<<i; DelayUs(6); } return(value); } //----------------------------------------- // Write 1 byte //----------------------------------------- void WriteByte2(char val) { unsigned char i; unsigned char temp; for (i=0; i<8; i++) // writes byte, one bit at a time { temp = val>> i; temp &=0x01; WriteBit2(temp); } DelayUs(5); } //----------------------------------------- // Read temperature //----------------------------------------- void ReadTemp2(void) { int k; int thap, cao=0; ResetDS18202(); WriteByte2(0xcc); // skip ROM WriteByte2(0x44); // perform temperatur conversion while (ReadByte2()==0xff); // wait for conversion complete ResetDS18202(); WriteByte2(0xcc); // skip ROM WriteByte2(0xbe); // read the result for (k=0; k<9; k++) // read 9 bytes but, use only one byte { readdata[k]=ReadByte2(); // read DS1820 } thap = readdata[0]; cao = readdata[1]; readdata[1]=readdata[1]<<4; readdata[1]=readdata[1] & 0x70; thap=readdata[0]; thap=thap>>4; thap=thap & 0x0f; readdata[1]=readdata[1] | thap; thap=2; t2=readdata[1]; } // ---------------------------- DS18B20 --------> 3 --------------------- bit ResetDS18203(void) { bit presence; DQ3 = 0; //pull DQ line low DelayUs(29); // leave it low for about 490us DQ3 = 1; // allow line to return high DelayUs(3); // wait for presence 55 uS presence = DQ3; // get presence signal DelayUs(25); // wait for end of timeslot 316 uS return(presence); // presence signal returned } // 0=presence, 1 = no part //----------------------------------------- // Read one bit from DS1820 //----------------------------------------- unsigned char ReadBit3(void) { unsigned char i; DQ3 = 0; // pull DQ low to start timeslot DQ3 = 1; for (i=0; i<3; i++); // delay 17 us from start of timeslot return(DQ3); // return value of DQ line } //----------------------------------------- // Write one bit to DS1820 //----------------------------------------- void WriteBit3(char bitval) { DQ3=0; if(bitval==1) DQ3 = 1; DelayUs(5); // delay about 39 uS DQ3 = 1; } //----------------------------------------- // Read 1 byte from DS1820 //----------------------------------------- unsigned char ReadByte3(void) { unsigned char i; unsigned char value = 0; for (i=0;i<8;i++) { if(ReadBit3()) value|=0x01<<i; DelayUs(6); } return(value); } //----------------------------------------- // Write 1 byte //----------------------------------------- void WriteByte3(char val) { unsigned char i; unsigned char temp; for (i=0; i<8; i++) // writes byte, one bit at a time { temp = val>> i; temp &=0x01; WriteBit3(temp); } DelayUs(5); } //----------------------------------------- // Read temperature //----------------------------------------- void ReadTemp3(void) { int k; int thap, cao=0; ResetDS18203(); WriteByte3(0xcc); // skip ROM WriteByte3(0x44); // perform temperatur conversion while (ReadByte3()==0xff); // wait for conversion complete ResetDS18203(); WriteByte3(0xcc); // skip ROM WriteByte3(0xbe); // read the result for (k=0; k<9; k++) // read 9 bytes but, use only one byte { readdata[k]=ReadByte3(); // read DS1820 } thap = readdata[0]; cao = readdata[1]; readdata[1]=readdata[1]<<4; readdata[1]=readdata[1] & 0x70; thap=readdata[0]; thap=thap>>4; thap=thap & 0x0f; readdata[1]=readdata[1] | thap; thap=2; t3=readdata[1]; } // ---------------------------- DS18B20 --------> 4 --------------------- bit ResetDS18204(void) { bit presence; DQ4 = 0; //pull DQ line low DelayUs(29); // leave it low for about 490us DQ4 = 1; // allow line to return high DelayUs(3); // wait for presence 55 uS presence = DQ4; // get presence signal DelayUs(25); // wait for end of timeslot 316 uS return(presence); // presence signal returned } // 0=presence, 1 = no part //----------------------------------------- // Read one bit from DS1820 //----------------------------------------- unsigned char ReadBit4(void) { unsigned char i; DQ4 = 0; // pull DQ low to start timeslot DQ4 = 1; for (i=0; i<3; i++); // delay 17 us from start of timeslot return(DQ4); // return value of DQ line } //----------------------------------------- // Write one bit to DS1820 //----------------------------------------- void WriteBit4(char bitval) { DQ4=0; if(bitval==1) DQ4 = 1; DelayUs(5); // delay about 39 uS DQ4 = 1; } //----------------------------------------- // Read 1 byte from DS1820 //----------------------------------------- unsigned char ReadByte4(void) { unsigned char i; unsigned char value = 0; for (i=0;i<8;i++) { if(ReadBit4()) value|=0x01<<i; DelayUs(6); } return(value); } //----------------------------------------- // Write 1 byte //----------------------------------------- void WriteByte4(char val) { unsigned char i; unsigned char temp; for (i=0; i<8; i++) // writes byte, one bit at a time { temp = val>> i; temp &=0x01; WriteBit4(temp); } DelayUs(5); } //----------------------------------------- // Read temperature //----------------------------------------- void ReadTemp4(void) { int k; int thap, cao=0; ResetDS18204(); WriteByte4(0xcc); // skip ROM WriteByte4(0x44); // perform temperatur conversion while (ReadByte4()==0xff); // wait for conversion complete ResetDS18204(); WriteByte4(0xcc); // skip ROM WriteByte4(0xbe); // read the result for (k=0; k<9; k++) // read 9 bytes but, use only one byte { readdata[k]=ReadByte4(); // read DS1820 } thap = readdata[0]; cao = readdata[1]; readdata[1]=readdata[1]<<4; readdata[1]=readdata[1] & 0x70; thap=readdata[0]; thap=thap>>4; thap=thap & 0x0f; readdata[1]=readdata[1] | thap; thap=2; t4=readdata[1]; } //-------------- Ham hien thi nhiet do void HienThi_ADC(unsigned char so) { if ( so<100) { //lcd_data(t/100+48); lcd_data(((so/10)%10)+48); lcd_data(so%10+48); } else { lcd_data(so/100+48); lcd_data(((so/10)%10)+48); lcd_data(so%10+48); } } void Hienthiso(unsigned int count) { lcd_data(count/100+48); lcd_data(((count/10)%10)+48); lcd_data(count%10+48); } //-------------------------------------------- void main (void) { lcd_init(); IE=0XAF; IT0=1; lcd_command(0x01); lcd_command(0x80); lcd_putsf("Welcome"); lcd_command(0xC0); lcd_putsf("Bai giu xe O"); delay_ms1(100); while(1) { lcd_command(0x80); lcd_putsf("So luong xe: "); Hienthiso(xe); lcd_command(0xC0); lcd_putsf("Nhiet do: "); ReadTemp(); ReadTemp2(); ReadTemp3(); ReadTemp4(); nhietdo = t1; if(nhietdo < t2 ) nhietdo = t2; if(nhietdo < t3) nhietdo = t3; if(nhietdo < t4 ) nhietdo = t4; HienThi_ADC(nhietdo); lcd_command(0xc0+14); lcd_putsf("oC "); delay_ms1(10); } } void ngat0(void) interrupt 0 { EA=0; xe++; //if(x==100)x=0; delay_ms1(100); EA=1; } void ngat1(void) interrupt 2 { EA=0; xe--; //if(x==100)x=0; delay_ms1(100); EA=1; }
Comment
-
Mình đã chạy mô phỏng code này trên Protues thành công, nhưng không hiểu sao khi nạp vào VĐK lại chạy bị lỗi. Không phải ko chạy được, nhưng nó chỉ chạy được 1 phần thôi. Rồi đứng luôn... cái này lỗi do VĐK phải ko? Nhưng con VĐK này mình nạp ct khác thì vẫn chạy bt )Code:#include<stdio.h> #include<reg51.h> sbit DQ = P2^0; sbit DQ2 = P2^1; sbit DQ3 = P2^2; sbit DQ4 = P2^3; char readdata[2]; unsigned int t1,t2,t3,t4,nhietdo; int xe= 50; sbit xevao = P3^0; sbit xera = P3^1; // Khai bao cho LCD -- sbit RS = P3^6; sbit EN = P3^7; //RW=1 => doc //RS=0 => code //RS=1 => data #define lcd_PORT P0 //=========================== void delay_ms1(int n) { int k,j; for(k=0;k<n;k++) { for(j=0;j<500;j++); } } //========================== void delay_5ms(){ int i,j; for(i=0;i<250;i++) for(j=0;j<4;j++){} } //=========================== void delay_15ms(){ int i,j; for(i=0;i<250;i++) for(j=0;j<100;j++){} } //============================ void lcd_command(unsigned char c) //CT con ghi du lieu len LCD { RS=0; lcd_PORT=c; EN=1; EN=0; delay_5ms(); } //============================== void lcd_data(unsigned char c) //CT con doc du lieu tu LCD { RS=1; lcd_PORT=c; EN=1; EN=0; delay_5ms(); } //=============================== void lcd_init() // Khoi tao LCD { delay_15ms(); lcd_command(0x38); lcd_command(0x0C); lcd_command(0x01); // Xoa man hinh LCD } //============================= void lcd_putsf(unsigned char *s) { while (*s) { lcd_data(*s); s++; } } //------------------DS18b20--------------------------------------------------------------------- void DelayUs(int us) { int i; for (i=0; i<us; i++); } //---------------------------------------- // Reset DS1820 //---------------------------------------- bit ResetDS1820(void) { bit presence; DQ = 0; //pull DQ line low DelayUs(29); // leave it low for about 490us DQ = 1; // allow line to return high DelayUs(3); // wait for presence 55 uS presence = DQ; // get presence signal DelayUs(25); // wait for end of timeslot 316 uS return(presence); // presence signal returned } // 0=presence, 1 = no part //----------------------------------------- // Read one bit from DS1820 //----------------------------------------- unsigned char ReadBit(void) { unsigned char i; DQ = 0; // pull DQ low to start timeslot DQ=1; for (i=0; i<3; i++); // delay 17 us from start of timeslot return(DQ); // return value of DQ line } //----------------------------------------- // Write one bit to DS1820 //----------------------------------------- void WriteBit(char bitval) { DQ=0; if(bitval==1) DQ = 1; DelayUs(5); // delay about 39 uS DQ = 1; } //----------------------------------------- // Read 1 byte from DS1820 //----------------------------------------- unsigned char ReadByte(void) { unsigned char i; unsigned char value = 0; for (i=0;i<8;i++) { if(ReadBit()) value|=0x01<<i; DelayUs(6); } return(value); } //----------------------------------------- // Write 1 byte //----------------------------------------- void WriteByte(char val) { unsigned char i; unsigned char temp; for (i=0; i<8; i++) // writes byte, one bit at a time { temp = val>> i; temp &=0x01; WriteBit(temp); } DelayUs(5); } //----------------------------------------- // Read temperature //----------------------------------------- void ReadTemp(void) { int k; int thap, cao=0; ResetDS1820(); WriteByte(0xcc); // skip ROM WriteByte(0x44); // perform temperatur conversion while (ReadByte()==0xff); // wait for conversion complete ResetDS1820(); WriteByte(0xcc); // skip ROM WriteByte(0xbe); // read the result for (k=0; k<9; k++) // read 9 bytes but, use only one byte { readdata[k]=ReadByte(); // read DS1820 } thap = readdata[0]; cao = readdata[1]; readdata[1]=readdata[1]<<4; readdata[1]=readdata[1] & 0x70; thap=readdata[0]; thap=thap>>4; thap=thap & 0x0f; readdata[1]=readdata[1] | thap; thap=2; t1=readdata[1]; } // ---------------------------- DS18B20 --------> 2 --------------------- bit ResetDS18202(void) { bit presence; DQ2 = 0; //pull DQ line low DelayUs(29); // leave it low for about 490us DQ2 = 1; // allow line to return high DelayUs(3); // wait for presence 55 uS presence = DQ2; // get presence signal DelayUs(25); // wait for end of timeslot 316 uS return(presence); // presence signal returned } // 0=presence, 1 = no part //----------------------------------------- // Read one bit from DS1820 //----------------------------------------- unsigned char ReadBit2(void) { unsigned char i; DQ2 = 0; // pull DQ low to start timeslot DQ2 = 1; for (i=0; i<3; i++); // delay 17 us from start of timeslot return(DQ2); // return value of DQ line } //----------------------------------------- // Write one bit to DS1820 //----------------------------------------- void WriteBit2(char bitval) { DQ2=0; if(bitval==1) DQ2 = 1; DelayUs(5); // delay about 39 uS DQ2 = 1; } //----------------------------------------- // Read 1 byte from DS1820 //----------------------------------------- unsigned char ReadByte2(void) { unsigned char i; unsigned char value = 0; for (i=0;i<8;i++) { if(ReadBit2()) value|=0x01<<i; DelayUs(6); } return(value); } //----------------------------------------- // Write 1 byte //----------------------------------------- void WriteByte2(char val) { unsigned char i; unsigned char temp; for (i=0; i<8; i++) // writes byte, one bit at a time { temp = val>> i; temp &=0x01; WriteBit2(temp); } DelayUs(5); } //----------------------------------------- // Read temperature //----------------------------------------- void ReadTemp2(void) { int k; int thap, cao=0; ResetDS18202(); WriteByte2(0xcc); // skip ROM WriteByte2(0x44); // perform temperatur conversion while (ReadByte2()==0xff); // wait for conversion complete ResetDS18202(); WriteByte2(0xcc); // skip ROM WriteByte2(0xbe); // read the result for (k=0; k<9; k++) // read 9 bytes but, use only one byte { readdata[k]=ReadByte2(); // read DS1820 } thap = readdata[0]; cao = readdata[1]; readdata[1]=readdata[1]<<4; readdata[1]=readdata[1] & 0x70; thap=readdata[0]; thap=thap>>4; thap=thap & 0x0f; readdata[1]=readdata[1] | thap; thap=2; t2=readdata[1]; } // ---------------------------- DS18B20 --------> 3 --------------------- bit ResetDS18203(void) { bit presence; DQ3 = 0; //pull DQ line low DelayUs(29); // leave it low for about 490us DQ3 = 1; // allow line to return high DelayUs(3); // wait for presence 55 uS presence = DQ3; // get presence signal DelayUs(25); // wait for end of timeslot 316 uS return(presence); // presence signal returned } // 0=presence, 1 = no part //----------------------------------------- // Read one bit from DS1820 //----------------------------------------- unsigned char ReadBit3(void) { unsigned char i; DQ3 = 0; // pull DQ low to start timeslot DQ3 = 1; for (i=0; i<3; i++); // delay 17 us from start of timeslot return(DQ3); // return value of DQ line } //----------------------------------------- // Write one bit to DS1820 //----------------------------------------- void WriteBit3(char bitval) { DQ3=0; if(bitval==1) DQ3 = 1; DelayUs(5); // delay about 39 uS DQ3 = 1; } //----------------------------------------- // Read 1 byte from DS1820 //----------------------------------------- unsigned char ReadByte3(void) { unsigned char i; unsigned char value = 0; for (i=0;i<8;i++) { if(ReadBit3()) value|=0x01<<i; DelayUs(6); } return(value); } //----------------------------------------- // Write 1 byte //----------------------------------------- void WriteByte3(char val) { unsigned char i; unsigned char temp; for (i=0; i<8; i++) // writes byte, one bit at a time { temp = val>> i; temp &=0x01; WriteBit3(temp); } DelayUs(5); } //----------------------------------------- // Read temperature //----------------------------------------- void ReadTemp3(void) { int k; int thap, cao=0; ResetDS18203(); WriteByte3(0xcc); // skip ROM WriteByte3(0x44); // perform temperatur conversion while (ReadByte3()==0xff); // wait for conversion complete ResetDS18203(); WriteByte3(0xcc); // skip ROM WriteByte3(0xbe); // read the result for (k=0; k<9; k++) // read 9 bytes but, use only one byte { readdata[k]=ReadByte3(); // read DS1820 } thap = readdata[0]; cao = readdata[1]; readdata[1]=readdata[1]<<4; readdata[1]=readdata[1] & 0x70; thap=readdata[0]; thap=thap>>4; thap=thap & 0x0f; readdata[1]=readdata[1] | thap; thap=2; t3=readdata[1]; } // ---------------------------- DS18B20 --------> 4 --------------------- bit ResetDS18204(void) { bit presence; DQ4 = 0; //pull DQ line low DelayUs(29); // leave it low for about 490us DQ4 = 1; // allow line to return high DelayUs(3); // wait for presence 55 uS presence = DQ4; // get presence signal DelayUs(25); // wait for end of timeslot 316 uS return(presence); // presence signal returned } // 0=presence, 1 = no part //----------------------------------------- // Read one bit from DS1820 //----------------------------------------- unsigned char ReadBit4(void) { unsigned char i; DQ4 = 0; // pull DQ low to start timeslot DQ4 = 1; for (i=0; i<3; i++); // delay 17 us from start of timeslot return(DQ4); // return value of DQ line } //----------------------------------------- // Write one bit to DS1820 //----------------------------------------- void WriteBit4(char bitval) { DQ4=0; if(bitval==1) DQ4 = 1; DelayUs(5); // delay about 39 uS DQ4 = 1; } //----------------------------------------- // Read 1 byte from DS1820 //----------------------------------------- unsigned char ReadByte4(void) { unsigned char i; unsigned char value = 0; for (i=0;i<8;i++) { if(ReadBit4()) value|=0x01<<i; DelayUs(6); } return(value); } //----------------------------------------- // Write 1 byte //----------------------------------------- void WriteByte4(char val) { unsigned char i; unsigned char temp; for (i=0; i<8; i++) // writes byte, one bit at a time { temp = val>> i; temp &=0x01; WriteBit4(temp); } DelayUs(5); } //----------------------------------------- // Read temperature //----------------------------------------- void ReadTemp4(void) { int k; int thap, cao=0; ResetDS18204(); WriteByte4(0xcc); // skip ROM WriteByte4(0x44); // perform temperatur conversion while (ReadByte4()==0xff); // wait for conversion complete ResetDS18204(); WriteByte4(0xcc); // skip ROM WriteByte4(0xbe); // read the result for (k=0; k<9; k++) // read 9 bytes but, use only one byte { readdata[k]=ReadByte4(); // read DS1820 } thap = readdata[0]; cao = readdata[1]; readdata[1]=readdata[1]<<4; readdata[1]=readdata[1] & 0x70; thap=readdata[0]; thap=thap>>4; thap=thap & 0x0f; readdata[1]=readdata[1] | thap; thap=2; t4=readdata[1]; } //-------------- Ham hien thi nhiet do void HienThi_ADC(unsigned char so) { if ( so<100) { //lcd_data(t/100+48); lcd_data(((so/10)%10)+48); lcd_data(so%10+48); } else { lcd_data(so/100+48); lcd_data(((so/10)%10)+48); lcd_data(so%10+48); } } void Hienthiso(unsigned int count) { lcd_data(count/100+48); lcd_data(((count/10)%10)+48); lcd_data(count%10+48); } //-------------------------------------------- void main (void) { lcd_init(); IE=0XAF; IT0=1; lcd_command(0x01); lcd_command(0x80); lcd_putsf("Welcome"); lcd_command(0xC0); lcd_putsf("Bai giu xe O"); delay_ms1(100); while(1) { lcd_command(0x80); lcd_putsf("So luong xe: "); Hienthiso(xe); lcd_command(0xC0); lcd_putsf("Nhiet do: "); ReadTemp(); ReadTemp2(); ReadTemp3(); ReadTemp4(); nhietdo = t1; if(nhietdo < t2 ) nhietdo = t2; if(nhietdo < t3) nhietdo = t3; if(nhietdo < t4 ) nhietdo = t4; HienThi_ADC(nhietdo); lcd_command(0xc0+14); lcd_putsf("oC "); delay_ms1(10); } } void ngat0(void) interrupt 0 { EA=0; xe++; //if(x==100)x=0; delay_ms1(100); EA=1; } void ngat1(void) interrupt 2 { EA=0; xe--; //if(x==100)x=0; delay_ms1(100); EA=1; }
Các cao thủ giúp với.
Comment
Bài viết mới nhất
Collapse
-
bởi songchodep76Cảm ơn bác đã nhiệt thành chia sẻ kinh nghiệm bản thân mình cho mọi người.
Tuy nhiên, theo tiếp xúc hạn hẹp của em với mosfet thì vấn đề bác đo vôn ở cực D và thấy đỉnh nó 70V/55V Vds max, như thí nghiệm và trong hình của bác...-
Channel: Hướng dẫn sử dụng diễn đàn
Hôm qua, 09:46 -
-
Trả lời cho Yêu thơ mê nhạc, mời các bác vào đây!bởi dinhthuong92Cho tới thời điểm này, quả thật Đình Thường đây quá thất vọng, không hào hứng với Suno-AI lắm bởi ra lệnh Creat mấy chục lần với các thay đổi thì mới chọn được 2 bản hát đúng giai điệu tầm 80% để cắt ghép tạo thành bài hát...
-
Channel: Tâm tình dân kỹ thuật
06-02-2026, 17:01 -
-
Trả lời cho Yêu thơ mê nhạc, mời các bác vào đây!bởi dinhthuong92Kính chào cả nhà, nhân dịp Tết đang về, sắp 23 tháng chạp rồi, xin gởi lời chúc xuân qua bài hát sau ạ:
Bao nhiêu hân hoan
Chúc Mừng Năm Mới, xuân sang!
Nơi nơi hát vang
nâng chén vui chúc câu An Lành.
Vạn Sự đều Hanh Thông,
Rạng...-
Channel: Tâm tình dân kỹ thuật
06-02-2026, 16:46 -
-
bởi ittcChán quá các bác, em nhạt nhẽo quá nên tán em nào cũng tạch, tuyệt vọng vô cùng, nay lại được mấy anh đồng nghiệp cty đối tác mách cho em gái kia sinh năm 2K đầu, em chả biết nhóm đối tượng này phải tán ra sao bây giờ ?
Tính ra em...-
Channel: Tâm tình dân kỹ thuật
06-02-2026, 00:18 -
-
bởi bqvietCó thể, ví dụ phần phản hồi gồm vi mạch cách ly quang, zener thứ cấp, transistor và điện trở phản hồi dòng ... Bất kỳ linh kiện nào nhóm đó hỏng dẫn tới mất đường phản hồi. TNY chính hãng phát hiện được chuyện đó nhưng linh kiện...
-
Channel: Điện tử công suất
05-02-2026, 18:36 -
-
bởi Nexus 6Pcho e hỏi, khi mạch có linh kiện nào đó hư thì có làm hỏng led đắt tiền (osram) không?
-
Channel: Điện tử công suất
05-02-2026, 10:42 -
-
bởi chinhnguyen9· Thí nghiệm 1 (Mạch boost, Vcc=12V, kích bằng dao động PƯM, duty 10%):
* Không có snubber + không tải: Xuất hiện hiện tượng dao động tắt dần tại cực D Mosfet (ringing). Hình 1 cho thấy trong chu kỳ đầu, điện áp spike lên tới hàng trăm V, điện...-
Channel: Hướng dẫn sử dụng diễn đàn
04-02-2026, 09:16 -
-
bởi Nexus 6Pe dùng KiCad 9.0 và đã xuất được file PDF mạch in gòi bác...
-
Channel: Điện tử công suất
03-02-2026, 16:25 -
-
bởi bqvietBấm chuột vào các tệp sẽ bật ra chương trình tương ứng. Nên dùng bản KiCAD sau
https://kicad-downloads.s3.cern.ch/a...ll_version.exe-
Channel: Điện tử công suất
03-02-2026, 14:57 -
-
bởi Nexus 6Pe cài KiCAD 2012 khi mở ra nó chỉ hiện ntn...
-
Channel: Điện tử công suất
03-02-2026, 11:20 -

Comment