#define uchar unsigned char sbit DQ=P1^4; volatile data temp_data[2]={0x00,0x00}; uchar data display[5]={0x00,0x00,0x00,0x00,0x00}; unsigned char code ditab[16] ={0x00,0x01,0x01,0x02,0x03,0x03,0x04,0x04, 0x05,0x06,0x06,0x07,0x08,0x08,0x09,0x09} ; //Common cathode digital tube uchar code table[11] ={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x00}; // 0,1,2,3,4,5, 6,7,8,9, hundreds digit or when the highest digit is 0, it will not be displayed uchar code table1[10]={0xbf,0x86,0xdb,0xcf,0xe6,0xed,0xfd,0x87,0xff,0xef}; // 0., 1., 2., 3., 4., 5., 6., 7., 8., 9. Each digit has a decimal point //The following is the water level display area #define uchar unsigned char #define uint unsigned int #define long unsigned long #define _rrca_() CY = ACC & 0x01 //Generate RRC A instruction #define _rlca_() CY = ACC & 0x80 //Generate RLC A instruction sbit bADcs=P1^7; sbit bADcl=P1^6; sbit bADda=P1^5; sbit flag=P1^3; //sbit str=P2^7; //sbit d=P2^6; //sbit clk=P2^5; bit choose=0; unsigned char data1; unsigned char count; unsigned char cycle; uint ge,xiao1,xiao2; unsigned long data2; unsigned char code tablewe[]= { 0xFE,0xFD,0xFB,0xF7, 0xEF,0xDF,0xBF,0x7F };//Written by myself void delay_18b20(unsigned int i) { while(i--); } //Function area water level void Delay(fly i) { while(--i); } void ad(void) { fly i; //data1=0; bADcs = 0; //When ADC0832 is not working, its CS input should be high level, and the chip is disabled. bADcl=0; sea=1; bADcl=1; bADcl=0;//i down sea=1; bADcl=1; bADcl=0; // 2 down sea=0; bADcl=1; bADcl=0; // 3 down sea=1; bADcl=1; bADcl=0; // 4 down for(i=8;i>0;i--) { data1<<=1; bADcl=0; bADcl=1; if(bADda==1) data1|=0x01; sea=1; } bADcs=1; } void cal() { data2=((head)data1*493)/252.5; ge=data2/100; xiao1=(data2%100)/10; xiao2=data2%10; } display2() { P2=tablewe[4]; //P2 port low four bits selection P0=0x00; //P0 port digital tube segment selects the fifth digital tube and does not use it delay_18b20(50); P2=tablewe[5]; P0=table1[ge]; delay_18b20(50); P2=tablewe[6]; P0=table[xiao1]; delay_18b20(50); P2=tablewe[7]; P0=table[xiao2]; } //The above is the water level function // Initialization function Init_DS18B20(void) { unsigned char x=0; DQ=1; //DQ reset delay_18b20(8); //delay a little DQ=0; //MCU pulls DQ low delay_18b20(80); //Precise delay greater than 480us DQ=1; //Pull the bus high delay_18b20(14); x=DQ; //After a short delay, if x=0, initialization is successful, if x=1, initialization fails delay_18b20(20); } ReadOneChar(void) { unsigned char i=0; unsigned char dat=0; for(i=8;i>0;i--) { DQ=0; // Give pulse signal that>>=1; DQ=1; // Give pulse signal if(DQ) that|=0x80 ; delay_18b20(4) ; } return (that) ; } [page] WriteOneChar(unsigned char dat) { unsigned char i=0; for(i=8;i>0;i--) { DQ=0; DQ=dat&0x01; delay_18b20(5); DQ=1; that>>=1; } } Read_Temperature(void) { Heat_DS18B20() ; WriteOneChar(0xCC); // Skip the operation of reading the serial number and column number WriteOneChar(0x44); // Start temperature conversion Heat_DS18B20() ; WriteOneChar(0xCC); //Skip the operation of reading the serial number and column number WriteOneChar(0xBE); //Read temperature register temp_data[0] = ReadOneChar(); //lower 8 bits of temperature temp_data[1] = ReadOneChar(); //high 8 bits of temperature } Disp_Temperature() { display[4]=temp_data[0]&0x0f; display[0]=ditab[display[4]]; //Look up the table to get the decimal value display[4]=((temp_data[0]&0xf0)>>4)|((temp_data[1]&0x0f)<<4); display[3]=display[4]/100 ; display[1]=display[4]%100 ; display[2]=display[1]/10; display[1]=display[1]%10; if(display[3]==0) //high bit is 0, not displayed { display[3]=10 ; if(display[2]==0) //The second highest bit is 0, not displayed display[2]=10 ; } } display1() { P2=tablewe[0]; //P2 port low four bits selection P0=table[display[3]]; //P0 port digital tube segment selection delay_18b20(50); P2=tablewe[1]; P0=table[display[2]]; delay_18b20(50); P2=tablewe[2]; P0=table1[display[1]]; delay_18b20(50); P2=tablewe[3]; P0=table[display[0]]; } void main() { while(1) { Read_Temperature(); Disp_Temperature(); display1(); ad(); cal(); display2(); } } This program can be used, but it just can't display temperatures below zero. Please modify it!
Previous article:The single chip microcomputer uses a digital tube to display 0-9, Af
Next article:DS1302 program based on C8051F
Recommended ReadingLatest update time:2024-11-15 16:51
- Popular Resources
- Popular amplifiers
- MCU C language programming and Proteus simulation technology (Xu Aijun)
- 100 Examples of Microcontroller C Language Applications (with CD-ROM, 3rd Edition) (Wang Huiliang, Wang Dongfeng, Dong Guanqiang)
- Single-chip microcomputer technology and application - electronic circuit design, simulation and production (edited by Zhou Runjing)
- Principles and Applications of Single Chip Microcomputers and C51 Programming (3rd Edition) (Xie Weicheng, Yang Jiaguo)
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- LED chemical incompatibility test to see which chemicals LEDs can be used with
- Application of ARM9 hardware coprocessor on WinCE embedded motherboard
- What are the key points for selecting rotor flowmeter?
- LM317 high power charger circuit
- A brief analysis of Embest's application and development of embedded medical devices
- Single-phase RC protection circuit
- stm32 PVD programmable voltage monitor
- Introduction and measurement of edge trigger and level trigger of 51 single chip microcomputer
- Improved design of Linux system software shell protection technology
- What to do if the ABB robot protection device stops
- Huawei's Strategic Department Director Gai Gang: The cumulative installed base of open source Euler operating system exceeds 10 million sets
- Download from the Internet--ARM Getting Started Notes
- Learn ARM development(22)
- Learn ARM development(21)
- Learn ARM development(20)
- Learn ARM development(19)
- Learn ARM development(14)
- Learn ARM development(15)
- Analysis of the application of several common contact parts in high-voltage connectors of new energy vehicles
- Wiring harness durability test and contact voltage drop test method
- Where is the lucky star? ——"Keysight Technology Double 11 Instrument Flash Sale"
- My design is equivalent to changing the original manual control to automatic control. The overall design idea is as follows, but at this stage it is still...
- Play with the Internet of Things and make a smart greenhouse model!
- I used the AD18STM32 library to import the chip, but the chip pins are incomplete
- MSP430 interrupt nesting mechanism
- MSP430 MCU Development Record (13)
- Current sensing crosstalk issue?
- Electronic pill box reminder solution
- The first analog I2C program learned by MSP430
- SD Card 2.0 Protocol.pdf