Wireless measurement and transmission of temperature through infrared

Source: Internet
Author: User
Tags binary to decimal

to maintain a certain degree of independence of netizens, the author hangs out mostSource ( not all ) for reference, refuse to use the hand of the party! 1. Introduction

The system consists of two parts :

    • Temperature acquisition End
    • Temperature Display End
    • Principle: The temperature sensor collects the temperature display on the LCD screen or the digital tube, and sends the temperature through the infrared to the infrared receiver head, then demodulation decodes the data, the temperature displays, realizes the temperature wireless measurement

2. selection of the controllerScenario I: Using MSP430 to handleMThe sp430 is an ultra-low-power mixed-signal processor with a streamlined instruction set that can execute a single instruction at all times, faster than 51. So the data returned by the 430来 processing comparator is relatively fast, but the price is rather expensive. 430 power supply is 3.3V, and the operation is more complex. Scenario Two: The use of 51 core single-chip microcomputersingle-chip microcomputer operation convenient and fast, low cost, rich development resources, bit addressing convenience, etc., to the data does not require a large data processing process, 51 has been completely able to win the convenience, so the device uses STC89c52single-chip microcomputer for processing, the single-chip machine a clock cycle to execute an instruction, can not decrypt, low power consumption, ultra-low price, high speed, high reliability. 3. Selection of temperature display mode Scheme one: Using digital tube displayThe digital tube is a 8-shape device that is packaged together by multiple LEDs, and the leads are internally connected, simply by drawing out their individual strokes and common electrodes. Can be used to display numbers and letters. Scenario Two: using LCD1602a lattice-type LCD module designed to display letters, numbers, symbols, etc. It consists of a number of dot-matrix character bits, such as 5x7 or 5x11, each dot can display a character, each with a point spacing between them, can display two lines, each line 16 digits or characters. 1602 using the standard 16 feet excuse, compared to the digital tube, the same pin case, the display of more content, welding more convenient and fast, so we choose the display part of the selection of LCD1602.
3.1. The infraredCodingand decoding
    • Serial code with pulse width modulation
    • ---------binary "0" represents---------
    • Pulse Width: 0.565ms
    • Interval: 0.56ms
    • Cycle: 1.125ms
    • -------------Split Line---------------

    • ---------binary "1" represents---------
    • Pulse Width: 0.565ms
    • Interval: 1.685ms
    • Cycle: 2.25ms
    • -------------Split Line--------------
" , as shown in the waveform:

>>>> the above "0" and "1" composed of 32-bit binary code by 38KHZ carrier frequency two times modulation to improve the transmission efficiency, to reduce power consumption.

>>>> then emits infrared radiation to space by infrared emitting diodes. Coded data, carrier, emission.

"To receive the decoding as shown:

- ---"Temperature sensor ds18b20 the temperature collected

- ------" through the single-chip computer processing display on the LCD

-----The temperature data is encoded , and The temperature information is emitted through the infrared emission circuit.

4. Software Design

This is for the Dsl8b20 as a temperature sensor for temperature acquisition, and then convert the temperature data into electrical signals, through the infrared emission, and then let the receiving end receive temperature information, and displayed. Because the welding is the smallest system of single-chip microcomputer, so, we use the wireless infrared transmitter and wireless infrared receiver tube to achieve the transmission end and receive data transfer, the basic can achieve more than five meters distance information transmission.

The receiving side main loop always detects whether the infrared receives completes, if completes the clear completion flag, and carries on the data verification, the verification passes to the infrared data to convert, the temperature is the global, will be in the DISPLAY.C by the timer scanning the digital tube to display. The flicker of the signal is controlled by the ledcount variable self-reduction

The main loop of the transmitting end is 18b20 temperature reading at a certain interval, then converts the temperature data into infrared data code, carries on the infrared emission, accompanies the signal flashing

Timer 0 for 38K carrier generation. Infrared Data into the Ir_code array, the first two bits of the boot code 3--18 for the verification code 19--41 data specific code 0 and 1 of the reference to the NEC Infrared protocol, the encoding time for 0 1 increased appropriately to avoid other infrared remote control interference.



5, Program module 5.1, data acquisition

#include "18b20.h" void delayus2x (unsigned char t) {while (--T); }void delayms (unsigned char t)//Delay tms{while (t--) {delayus2x (245);D elayus2x (245);}//Approximate delay 1mS}/*--------------------- ---------------------------18b20 Initialization------------------------------------------------*/bit Init_ds18b20 (        void) {bit DAT=0;DQ = 1;     DQ Reset Delayus2x (ten);D q = 0; A little delay//microcontroller will be DQ pull low delayus2x (200); DELAYUS2X (200);   Precision delay greater than 480us less than 960us DQ = 1; DELAYUS2X (50);  The 60-240US Pulse DAT=DQ is received after pulling the high bus//15~60us;  DELAYUS2X (25); If X=0 is initialized successfully, X=1 fails to initialize//delay returns to return dat;} /*------------------------------------------------read one byte----------------------------------------------  --*/unsigned char Readonechar (void) {unsigned char i=0;unsigned char dat = 0;for (i=8;i>0;i--) {DQ = 0; dat>>=1; DQ = 1; Give pulse signal//to pulse signal if (DQ) dat|=0x80;delayus2x (25);  } return (DAT);} /*------------------------------------------------Write a byte------------------------------------------------*/void writeonechar (unsigned char dat) {unsigned char i=0; for (i=8; i>0; i--) {DQ = 0; DQ = dat&0x01;  DELAYUS2X (25);  DQ = 1;  dat>>=1; }DELAYUS2X (25);} /*------------------------------------------------Read temperature------------------------------------------------*/unsi gned int readtemperature (void) {unsigned char a=0;unsigned int b=0;unsigned int t=0;init_ds18b20 ();         Writeonechar (0xCC);         Skip the Operation Writeonechar (0x44) that reads the ordinal column number; Starting temperature conversion delayms (); Init_ds18b20 ();         Writeonechar (0xCC);         Skip the Operation Writeonechar (0xBE) to read the sequence number.            Read temperature registers, etc. (total readable 9 registers) The first two are temperature A=readonechar ();            Low B=readonechar (); High-level t = ((int) b << 8) + A;return (t);}


5.2 Transmitter Module (sub-function part source code)

/************** Data Conversion function ***************** function name: dataconversion*** parameter: number to be converted num, infrared code storage address irdata*** function: Convert value to infrared emitter code * * * return value: None #define IR_CODE_0 20//TX Code 0#define ir_code_1 50#define ir_code_start 240//TX Code Start # define Ir_code_sizi 42//TX Code Number *****************************************/void dataconversion (unsigned int num,unsigned char* irdata) {unsigned  Char I=ir_code_sizi-3,n=1,f=1;ircodereset (); Store initialization for (n=3;n<18;n+=2)//First 8 store checksum 10101010 0xAA {if (f) {irdata[n] = ir_code_1;f=0;} else {irdata[n] = ir_code_0;f=1;}}    while (num!=0)//Data code holds decimal goto binary {if (num%2) {irdata[i] = ir_code_1;}   else {irdata[i] = ir_code_0;} num = num/2;i-=2;}} /************** Infrared wave emission function ***************** function name: Sendirwave () * * * parameter: Store the first address of infrared encoded data irdata*** function: Send irdata infrared waveform data in infrared * * * return value: No *****************************************/void sendirwave (unsigned char* irdata) {unsigned char count=0; unsigned char i=0;while (1)//TX Boot code checksum data code {ON_CARR;FOR (I=irdata[count]; i>0; i--)//carrier transmit delaywhen {carrierwave_delay;} Off_carr;ir_send_off;      Low-level retention count++;  for (I=irdata[count]; i>0; i--)//low-level delay {low_delay;       }if (count = = ir_code_sizi-1)//launch end {break; }count++;}}

5.3 Receiver Module
/******* Infrared Data receive initialization function ************ function name: initirreceive*** parameter  : no * * * function  : Configure the IR receive required timer and interrupt * * * return value: No **************** *************************/
void initirreceive (void) {/*------------------------------------------------timer 0 Initialization---------------- --------------------------------*/tmod|= 0x02;//Timer 0 Mode of operation 2,th0 is the reload value, TL0 is the initial values//8-bit auto-reload TH0 = 0x00;//Reload Value TL0 = 0x00;//initialization Value ET0 = 1;//Open Interrupt TR0 = 1;//Timer/counter start//------------------------------------------------external interrupt 0 initialization- -----------------------------------------------*/it0 = 1;//Specifies an external interrupt 0 falling edge trigger, INT0 (P3.2) EX0 = 1;//Enable external interrupt ea = 1;}?? 
/******* Infrared Data time counting function Function name: Irtimecount () * * Parameter: NO * * * functions: Record every two infrared pulse time interval * * * return value: No *****************************************/void Irtimecount () interrupt 1 {ir_time_count++;} /************* Infrared code receive interrupt function ************** function name: irreceive (void) * * parameter: NO * * * Function Description: Receive infrared code, deposit ir_code*** return value: No **************** /void irreceive () interrupt 0{static startflag=0,bitnum=0;if (startflag) {if (ir_time_count  <ir_start_tiem_max && ir_time_count>ir_start_tiem_min)//boot code judgment {bitnum=0;   } Ir_code[bitnum]=ir_time_count;   Boot code TC9012 The first code, 9MS+4.5MS ir_time_count=0;             bitnum++;  if (Bitnum==ir_code_sizi)//Receive complete {ir_receive_ok=1;   bitnum=0;}  } else//First trigger signal {ir_time_count=0; startflag=1; }}
/************ Infrared Code data conversion function ************** function name: dataconversion () * * * parameter:  NO * * * Function Description: Receive infrared code, deposit ir_code*** return value: Data area data ****** /unsigned int dataconversion (void) {  unsigned char i=9;  unsigned int num=0;  for (i=9;i<ir_code_sizi-1;i++)  {  if (ir_code[i]>ir_code_1) {Num+=pow (2,ir_code_sizi-2-i);//binary to Decimal}  }  return num;} /************* Infrared code data check ************** function name: Checksucceed () * * * parameter:  NO * * * Function Description: conversion ir_code 1--8 check code, compared with the pre-set values to determine the return value: Success 1 failed 0*****************************************/unsigned char checksucceed (void) {unsigned char i=1;unsigned int num= 0;for (i=1;i<9;i++)                 //Check code is located in 1--8{if (ir_code[i]>ir_code_1)  {num+=pow (2,8-i);//Conversion  }}if (num== Check_num && ir_code[0]>ir_start_tiem_min &&  ir_code[0]<ir_start_tiem_max)//check code and boot code checksum     {  return 1;  } else{   return 0;}}


Reprint Please indicate the source, the DA! Original statement: This article is-sure-original works, when reproduced please indicate "transfer from-sure-" and the original link.



Wireless measurement and transmission of temperature through infrared

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.