Design sharing | single chip microcomputer digital thermometer

Specific implementation functions

Specific functions:

The temperature is measured by DS18B20, and the temperature value is displayed in real time by four digit nixie tube.

Design Introduction

Introduction to single chip microcomputer

51 single chip is a low-power, high-performance CMOS 8-bit microcontroller with   8K   In system programmable Flash   Memory. On a single chip, it has a smart 8   Bit CPU   And in system programmable Flash, STC89C51 provides highly flexible and super effective solutions for many embedded control application systems. It has the following standard functions: 8K byte Flash, 512 byte RAM, 32 bytes   Bit I/O   Port line, watchdog timer, built-in 4keeprom, MAX810 reset circuit, three 16   position   Timer / counter, a 6-vector 2-level interrupt structure, full duplex serial port. in addition   STC89X51   It can be reduced to 0Hz   Static logic operation, support 2 kinds of software, and select power saving mode. CPU in idle mode   Stop working and allow RAM, timer / counter, serial port and interrupt to continue working. In the power down protection mode, the RAM content is saved, the oscillator is frozen, and all the work of the single chip microcomputer stops until the next interrupt or hardware reset. The maximum operating frequency is 35Mhz, 6T/12T optional.

Design ideas

Literature research method: collect and sort out the relevant research data of MCU intelligent Bracelet system, carefully read the literature and prepare for the research;

Investigation and research method: through investigation, analysis and specific trial, it is found that the current situation, existing problems and solutions of single chip microcomputer intelligent Bracelet system;

Comparative analysis method: compare the specific principles of different single-chip microcomputer intelligent Bracelet systems and the performance differences of the same kind of sensors, and analyze the research status and development prospect of single-chip microcomputer intelligent Bracelet system;

Software and hardware design method: realize the specific hardware object through software and hardware design, and finally test whether each function meets the requirements.

Design content

Simulation diagram

This design uses Protues 8.7 software to realize the simulation design, as shown in the figure.

Protues is also one of the commonly used design software in MCU simulation design. By designing the hardware circuit diagram and writing the driver, we can debug the circuit without realizing the hardware. In addition, Protues can also realize PCB design and joint debugging with KEIL in simulation, which is convenient for program debugging, supports a variety of platforms and is simple and convenient to use.

program

This design uses KEIL5 software to realize program design, as shown in the figure. As the first programming language learned during the undergraduate course, C language is one of the most familiar programming languages. Of course, because of its powerful function, C language is the most widely used and popular programming language in the world. In the design of single chip microcomputer, C language has gradually and completely replaced assembly language, because compared with assembly language, C language is very convenient for compilation, operation and debugging, high portability, good readability, and easy to burn and write into hardware system. Therefore, C language is widely used in the design of single chip microcomputer. Keil software, which is compatible with the design of single chip microcomputer, can realize rapid debugging and generate burning files. It is widely used in the writing of C language and the design of single chip microcomputer.

#include "reg51.h"#include "intrins.h"     //The delay function uses #define disata P1 / / segment code output port #define Disan P3 / / scan port #define uchar unsigned char #define uint unsigned intsbit DQ = P3 ^ 7// Temperature input port sbit DIN = P1 ^ 7// LED decimal point control uint h; uchar code ditab[16]={0x00,0x01,0x01,0x02,0x03,0x03,0x04,0x04,0x05,0x06,0x06,0x07,0x08,0x08,0x09,0x09};// The decimal part of the temperature is calculated by the look-up table method uchar code dis_7[12]={0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8,0x80,0x90,0xff,0xbf};/*  Common Yang LED segment code table "0" "1" "2" "3" "4" "5" "6" "7" "8" "9" "not on" "-" * / uchar code scan_ con[4]={0xfe,0xfd,0xfb,0xf7};   //  Column scan control word uchar data temp_ data[2]={0x00,0x00};               //  Read out the temperature and temporarily put uchar data display [5] = {0x00,0x00,0x00,0x00}// Display unit data, a total of 4 data, one operation is temporarily stored with void delay(uint t)//11 microsecond delay function {for (; t > 0; t --);}
scan()//Display scanning function {char K; for (k = 0; K < 4; K + +) / / four digit LED scanning control {displaydata = dis_7 [display [k]]; if (k = = 1) {DIN = 0;} can = ~ scan_con [k]; delay (90); can = 0x00;}}
ow_reset(void)//18B20 reset function {char presence = 1; while (presence) {while (presence) {DQ = 1; _nop_ (); _nop_ (); DQ = 0; delay (50); / / 550us DQ = 1; delay (6); / / 66us presence = DQ; / / presence = 0 continue to the next step} delay(45); / / delay 500uspresence = ~DQ;}DQ=1;} 
void write_byte(uchar val)//18B20 write command function {uchar I; for (I = 8; I > 0; I --) / / {DQ = 1; _nop_ (); _nop_ (); DQ = 0; _nop_ (); _nop_ (); _nop_ (); _nop_ (); / / 5usdq = Val & 0x01; / / move the lowest bit out of delay (6); / / 66usval = Val / 2; / / move one bit right} DQ = 1;delay(1);}

uchar read_byte(void)//Read a byte {uchar I; uchar value = 0; for (I = 8; I > 0; I --) {DQ = 1; _nop_ (); _nop_ (); value > > = 1; DQ = 0; / / _nop_ (); _nop_ (); _nop_ (); / / 4usdq = 1; _nop_ (); _nop_ (); _nop_ (); _nop_ (); _nop_ (); / / 4us if (DQ) value| = 0x80; delay (6); / / 66us} DQ = 1; return (value);}
read_temp()//Read the temperature function {ow_reset(); / / bus reset write_byte(0xCC); / / issue the Skip ROM command write_byte(0xBE); / / issue the read command temp_data[0]=read_byte(); / / issue the low temperature 8-bit temp_data[1]=read_byte(); / / high temperature 8-bit ow_reset(); write_byte(0xCC); / / issue the skip romwrite_byte (0x44); / / issue the conversion command}
work_temp()//The temperature data processing function is {uchar, n = 0; / / the data processing function {uchar. The data processing function for the temperature data is {{data data data [1] = (256 - tempu u data [1]); the temperature data is a part of the process. The {uchar. The {uchar. This is the one that ''s the one that's the one that's the one for the price data data [1]] > 127 is the one way to get the data data [1]] [1] > 127. There's a way for the / / / if if the data data data data is [1] > 127 is a 127. There''s a data data data [1] = (256 - 256 - temptemptemptempu data [data [1 [1 [1 [1 [1 [1 [data [1]) [1 [data [data [1 [0]) [0]]]] [0]); all [0]]] wherewhere where where where is a data data [0 is a [y [1] = display [4]% 100; display [2] = display [1] /10. Display [1] = display [1]% 10; if (! Display [3]) {display [3] = 0x0a; if (! Display [2]) {display [2] = 0x0a;}} / / if(n){display[3]=0x0B;} / / the highest bit is not displayed when the highest bit is 0;} / / if(n){display[3]=0x0B;} / / the highest bit is displayed when the temperature is negative "}
main()//Main function {Disdata=0xff; / / initialize the port. Discan = 0xff; for (H = 0; H < 4; H + +) {display [H] = 8;} / / start up and display 8888ow_reset(); / / start up and convert write_byte(0xCC); // Skip ROMwrite_byte(0x44); / / issue the conversion command for (H = 0; H < 500; H + +) {scan();} / / start up and display "8888" for 2 seconds while (1) {read_temp(); / / read 18B20 temperature data work_temp() / / process the temperature data for (H = 0; H < 500; H + +) {scan();} / / display the temperature value for 2 seconds}}

For more information, please pay attention to the "Growth Diary of electronic engineers"!

Keywords: Single-Chip Microcomputer

Added by Keith Scott on Wed, 03 Nov 2021 20:20:14 +0200