Electronic thermometer 1602 LCD display or digital tube display

Publisher:qin199099Latest update time:2015-08-25 Source: eefocus Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere
#include
#define uchar unsigned char
#define uint unsigned int
sbit DS=P2^2;           //define interface
uint temp;             // variable of temperature
uchar flag1;            // sign of the result positive or negative
sbit dula=P2^6;
sbit temperature=P2^7;
sbit beep=P2^3;
//unsigned char code table[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,
//                        0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71};
//unsigned char code table1[]={0xbf,0x86,0xdb,0xcf,0xe6,0xed,0xfd,
//                        0x87,0xff,0xef};
 
sbit lcden=P3^4; //LCD en port
sbit lcdrs=P3^5; // LCD RS port
 
void delay(uint count)      //delay
{
  uint i;
  while(count)
  {
    i=200;
    while(i>0)
    i--;
    count--;
  }
}
void dsreset()        //DS18B20 reset
{
  uint i;
  DS=0;
  i=103;
  while(i>0)i--;
  DS=1;
  i=4;
  while(i>0)i--;
}
bit tmpreadbit()        //DS18B20 reads one bit repeatedly
{
   uint i;
   bit that;
   DS=0;i++;           //i++ is used for delay
   DS=1;i++;i++;
   dat=DS;
   i=8;while(i>0)i--;
   return (that);
}
 
uchar tmpread()    //DS18B20 reads one byte repeatedly
{
  flying i,j,dat;
  that=0;
  for(i=1;i<=8;i++)
  {
    j=tmpreadbit();
    dat=(j<<7)|(dat>>1);    //The lowest bit of the read data is at the front, so there is exactly one byte in DAT
  }
  return(that);
}
void tmpwritebyte(uchar dat)    //DS18B20 writes one byte to the microcontroller
{
  uint i;
  flying j;
  bit testb;
  for(j=1;j<=8;j++)
  {
    testb=that&0x01;
    that=that>>1;
    if(testb)      //write 1
    {
      DS=0;
      i++;i++;
      DS=1;
      i=8;while(i>0)i--;
    }
    else
    {
      DS=0;        //write 0
      i=8;while(i>0)i--;
      DS=1;
      i++;i++;
    }
 
  }
}
void tmpchange()   //DS18B20 data conversion
{
  dsreset(); // reset
  delay(1);
  tmpwritebyte(0xcc);  
  tmpwritebyte(0x44);   //   Start temperature conversion instruction
}
uint tmp()                //Get temperature value
{
  float tt;
  fly a,b;
  dsreset();
  delay(1);
  tmpwritebyte(0xcc);
  tmpwritebyte(0xbe);
  a=tmpread();
  b=tmpread();
  temp=b;
  temp<<=8;              //Two 8-bit bytes are combined into a 16-bit integer data
  temp=temp|a;
  tt=temp*0.0625;
  temp=tt*10+0.5;
  return temp;
}
 
void write_com(uchar com) // sub-function with a parameter, this section is the write instruction sub-function
{
lcdrs=0; //write data when rs=1, write instructions when rs=0
P0=com; //send command
delay(5); //When EN=1 sends a high pulse, delay TSP1 time after the instruction and rs (see chip timing diagram for LCD)
lcden=1; //EN high pulse, start sending data
delay(5); //High level lasts for TPW time
lcden=0; // Pull the level down continuously
}
void write_data(uchar date) // sub-function with a parameter, this section is the sub-function for writing data
{
lcdrs=1; //write data when rs=1, write instructions when rs=0
P0=date; //send command
delay(5); //When EN=1 sends a high pulse, delay TSP1 time after the instruction and rs (see chip timing diagram for LCD)
lcden=1; //EN high pulse, start sending data
delay(5); //High level lasts for TPW time
lcden=0; // Pull the level down continuously
}
 
void write_1602(uchar add,uchar dat) //Put the two sub-functions of writing instructions and writing data into a total 1602 function for easy calling
{
write_com(0x80+0x40+add); //Write instruction, that is, write an address to write data, specify the address to write data
write_data(dat); //Write data, write what you want to write
}
 
void init()//initialization function
{
game=0;
temperature=0;
lcden=0; //Because data is read and written only when EN is high pulse, so initialize EN=0
write_com(0x38);
write_com(0x0c); //LCD initialization display mode setting, call sub-function, write in the initialization instruction code to set its function
write_com(0x06); //After writing a character, the cursor address increases by 1
write_com(0x80); //The address pointer points to the first position of the first line
write_com(0x01); //initialize and clear the screen
}
 
void display(uint temp) //display program
{
   uchar A1,A2,A2t,A3;
   A1=temp/100;
   A2t=temp0;
   A2=A2t/10;
   A3=A2t;
 
 
write_1602(1,A1+0x30);
write_1602(2,A2+0x30);
write_1602(3,0x2e);
write_1602(4,A3+0x30);
write_1602(6,'C');
 
 
}
void main()
{
flying a;
heat();
while(1)
{
    tmpchange();
for(a=10;a>0;a--)
  {   
  display(tmp());
  }
if(temp>=310) //When the temperature exceeds 31 degrees (for testing only, it can be set to a higher value), the buzzer will sound an alarm.
{
P1=0x00;
beep=0;
}
else
{
beep=1;
P1=0xff;
}
}
}
Reference address:Electronic thermometer 1602 LCD display or digital tube display

Previous article:Keil Chinese annotations are prone to problems
Next article:Driver for msp430g2553 and serial port communication

Recommended ReadingLatest update time:2024-11-16 03:27

MCU timer to achieve real-time clock program - lcd1602 display
The schematic diagram used in this program can be downloaded from:  http://www.51hei.com/f/HL-1V6.5.pdf  . The microcontroller chip used is stc89c52; just find the schematic diagram of the 1602 LCD part. This is an overall picture of the microcontroller development board. Below is the source code of the program: /*
[Microcontroller]
Understand LCD1602 liquid crystal display module in 10 minutes
1. Introduction to LCD1602 Liquid Crystal Module What does LCD1602 mean? LCD stands for Liquid Crystal Display, and 1602 means that 16 characters can be displayed in one line, and there are two lines in total. The actual picture is as follows: 2. Thinking Analysis LCD1602 is a display module, and its main function
[Microcontroller]
Understand LCD1602 liquid crystal display module in 10 minutes
Homemade MCU Part 5 (1) ... LCD1602 Driver
LCD1602 is very common, I won't go into details, most of the character LCDs on the market are based on HD44780 LCD chip, the control principle is exactly the same, so the control program written by HD44780 can be easily applied to most of the character LCDs on the market. Character LCDs usually have 14 pins or 16 pins
[Microcontroller]
Homemade MCU Part 5 (1) ... LCD1602 Driver
51 MCU digital clock simulation (LCD1602 liquid crystal display) + source program + circuit schematic diagram
The following is the 51 single-chip digital clock program: #include AT89X52.h #define DSbus P0 #define LCDbus P1 //Define the control lines of DS12C887 and LCD sbit DS_CS = P2^7; //Pin 13, chip select signal input, low level is valid. sbit DS_AS = P2^4; //Pin 14, address select input. sbit DS_RW = P2^5; //Pin 15,
[Microcontroller]
51 MCU digital clock simulation (LCD1602 liquid crystal display) + source program + circuit schematic diagram
LCD1602 program displays string
1602 lcd connection line diagram: | DB0-----P0.0 | DB4-----P0.4 | RW-------P2.0       | | DB1-----P0.1 | DB5-----P0.5 | RS-------P2.1       | | DB2-----P0.2 | DB6-----P0.6 | E--------P2.2       | | DB3-----P0.3 | DB7-----P0.7 | VLCD connects 1K resistor to GND | Display: The first line shows welcome!
[Microcontroller]
PIC microcontroller DS18B20 sampling LCD1602 display
#include "18b20.h"  #include "main.h"  //--------------Generate reset pulse--------------------//  void tx_reset()  {      ADCON1=0X06;      TR ISA 5=0;     DQ=1;      delay_us2(10,5); //65us      while(!DQ); //Judge whether the bus is busy      DQ=0;      delay_us2(10,23); //730us  }  //----------------Waiting for t
[Microcontroller]
LCD1602 four data line driver based on 51
/This program has been debugged  //The following is a calling example  ////////////////////////////////////// //LCD1602 read-write header file //Four-line drive mode //////////////////////////////////// #include   #include "LCD1602.h"  /*-----------  Pin definition in the LCD header file  -----------*/  void main(void
[Microcontroller]
LCD1602 simple calculator program based on 51 single chip microcomputer
/* S16 S12 S8 S4 are 123+ S15 S11 S7 S3 are 456- S14 S10 S6 S2 are 789* S13 S9 S5 S1 are 0 CE =/ */ /* Realize the operation of two numbers, the number of digits of each number can be at least eight (displayed on the LCD1602) */ #include reg52.h typedef unsigned char uint8; typedef unsigned int uint16; sbit rw=
[Microcontroller]
Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号