Nguyên văn bởi Vinhanboy
Xem bài viết
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 mèomướp1. Tìm hiểu đc thì càng tốt, bận thì thôi. Ko cần quá quan trọng
2. Số tự động cho đơn giản, kiểu như đi xe ga ấy ạ
3. Học lý thuyết tử tế ok
4.ok
5.có. đủ số km, tgian cầm lái là đc
6.đi ăn tập thể,...-
Channel: Tâm tình dân kỹ thuật
Hôm qua, 16:34 -
-
Trả lời cho Tìm bạn thân quen cũ.bởi lvhnE nhớ bác Vivanpham làm bên điện tử y sinh, có lần đó cái sơ đồ máy chụp x quang sao có mấy con thryristor làm gì mà ko ai trả lới đúng cả
...
-
Channel: Tâm tình dân kỹ thuật
07-08-2026, 09:17 -
-
Trả lời cho Amply bị rò DC 22 voltbởi lvhnBác kiểm tra lại đường mạch, mối hàn xem có bị hở hoặc dẫn không tốt không?
Thay cầu diode lớn hơn càng tốt không vấn đề gì cả....-
Channel: Điện thanh
07-08-2026, 09:12 -
-
bởi LantheChào bạn.
Trục đầu ra của hộp số hành tinh xoắn ốc được kết nối với mặt bích của khách hàng thông qua một trục răng trong. Sau chưa đầy sáu tháng hoạt động, nó phát ra tiếng kêu lách cách và độ rơ lớn đáng báo động.
Việc...-
Channel: Thiết bị điện tử cá nhân
06-08-2026, 13:05 -
-
bởi ittcChào các anh em nhé, mình dự định sắp tới sẽ đi học lái xe Ôtô, thi lấy bằng lái. Cụ thể mình sẽ học và thi lấy giấy phép lái xe hạng B. Thật sự mình là người chưa có kiến thức hiểu biết gì về Ôtô cả ? tất nhiên mình sẽ phải...-
Channel: Tâm tình dân kỹ thuật
-

Comment