Sie sind auf Seite 1von 15

Project Report

Temperature Monitoring by using Microcontroller PIC 18F6722


Prof : CEDRIC BRAZEILLES

Name of members group : DIALLO Mamadou Lamine KUSHARDIANTO NurCahyono NURDIANSARI Henna

I.

Introduction The objective of this project is to read the datum of temperature into personal computer (PC) by using microcontroller PIC 18F6722. Component 1. 2. 3. 4. 5. This project is consist of : Personal Computer Microcontroller PIC 18F6722 Board AMI ELECTRONIQUE Type E1416 Carte SD SD card Serial Cable RS 232

II.

Sensor LM35

PIC 18F6722

RS 232 PC

Figure 1.Schema in this system

Flowchart of this project

Start

Sensor

Main program Usart.c Usart.h

Output

End

Figure 2.Flowchart in this system

III. Theory III.1 Thermal Sensor The LM35 series are precision integrated-circuit temperature sensors, whose output voltage is linearly proportional to the Celsius (Centigrade) temperature. The LM35 does not require any external calibration or trimming to provide typical accuracies of 1 4C at room temperature and 34C over a full 55 to +150C temperature range. Low cost is assured by trimming and calibration at the wafer level. The LM35s low output impedance, linear output, and precise inherent calibration make interfacing to readout or control circuitry especially easy. It can be used with single power supplies, or with plus and minus supplies. As it draws only 60 A from its supply, it has very low self-heating, less than 0.1C in still air. The LM35 is rated to operate over a 55 to +150C temperature range, while the LM35C is rated for a 40 to +110C range (10 with improved accuracy). The LM35 series is available packaged in hermetic TO-46 transistor packages, while the LM35C, LM35CA, and LM35D are also available in the plastic TO-92 transistor package. The LM35D is also available in an 8-lead surface mount small outline package and a plastic TO-220 package. As we show you in figure 3 below. [1]

Figure 3, Thermal Sensor LM35

III.2 Microchip PIC 18F6722

Figure 4.Microchip PIC 18F6722 PIC is a family of modified Harvard architecture microcontrollers made by Microchip Technology,it is derived from the PIC1650originally developed by General Instrument's Microelectronics Division. The name PIC initially referred to "Peripheral Interface Controller". We can se the outlook of microchip PIC 18F6722 as in the figure 4 above. [2] PICs are popular with both industrial developers and hobbyists alike due to their low cost, wide availability, large user base, extensive collection of application notes, availability of low cost or free development tools, and serial programming (and re-programming with flash memory) capability[3].

In this project we use PIC 18F6722. This microcontroller is ideal for large low power (nanoWatt) and connectivity applications that benefit from the availability of four serial ports: double synchronous serial ports (I2C and SPI) and double asynchronous (LIN capable) serial ports. Large amounts of RAM memory for buffering and FLASH program memory make it ideal for instrumentation panels, TCP/IP enabled embedded applications as well as metering and industrial control and monitoring applications. While operating up to 40 MHz, it is also backward software and hardware compatible with the PIC18F6722. Before we build software to run the program, first we should have to know the basic initialization interrupt register for microcontroller PIC18F6722. In this project we use 1 important initialization interrupt register such as : INTCON Registersand 1 important timer controlTIMER0 MODULE. Also we use the serial I/O modules in microcontroller PIC 18F6722 is USART. The PIC18FXX2 devices have multiple interrupt sources and an interrupt priority feature that allows each interrupt source to be assigned a high priority level or a low priority level. The high priority interrupt vector is at 000008h and the low priority interrupt victories at 000018h. High priority interrupt events will override any low priority interrupts that may be in progress . Each interrupt source, except INT0, has three bits to control its operation. The functions of these bits are: Flag bit to indicate that an interrupt event occurred Enable bit that allows program execution to branch to the interrupt vector address when the flag bit is set Priority bit to select high priority or low priority

III.2.1 INTCON The INTCON registers are readable and writableregisters which contain various enable, priority and flagbits. Interrupt flag bits are set when an interruptcondition occurs, regardless of the state ofits corresponding enable bit or the globalinterrupt enable bit. User software shouldensure the appropriate interrupt flag bitsare clear prior to enabling an interrupt.This feature allows for software polling.

III.2.2 TIMER0 MODULE The Timer0 module incorporates the following features: Software selectable operation as a timer orcounter in both 8-bit or 16-bit modes Readable and writable registers Dedicated 8-bit, software programmableprescaler Selectable clock source (internal or external) Edge select for external clock Interrupt-on-overflow The T0CON register (Register 12-1) controls allaspects of the modules operation, including theprescale selection. It is both readable and writable.

III.3 Recommended Standard 232 (RS 232) It is independent channels that isestablished for two-way (full-duplex) serial communications. The RS232 signals are represented by voltage levels with respect to a system common (power / logic ground). RS232 data is bi-polar +3 to +12 volts indicates an "ON or 0-state (SPACE) condition" while data bipolar is -3 to -12 volts indicates an "OFF" 1-state (MARK) condition.[4] To explain eachfunction of DB9 RS232 in this communication using serial port we can show in figure 5. [5]

Figure 5.Schema of DB9 connector of RS 232 5

III.4

ADDRESSABLE UNIVERSAL SYNCHRONOUS ASYNCHRONOUS RECEIVER TRANSMITTER (USART)

USART stands for Universal Synchronous Asynchronous Receiver Transmitter. It issometimes called the Serial Communications Interface or SCI.Synchronous operation uses a clock and data line while there is no separate clockaccompanying the data for Asynchronous transmission.Since there is no clock signal in asynchronous operation, one pin can be used fortransmission and another pin can be used for reception [6]. Both transmission andreception can occur at the same time this is known as full duplex operation.Transmission and reception can be independently enabled. However, when the serialport is enabled, the USART will control both pins and one cannot be used forgeneral purpose I/O when the other is being used for transmission or reception.The USART is most commonly used in the asynchronous mode. In this presentationwe will deal exclusively with asynchronous operation.The most common use of the USART in asynchronous mode is to communicate to aPC serial port using the RS-232 protocol. In order to configure pins RC6/TX/CK and RC7/RX/DTas the Universal Synchronous Asynchronous ReceiverTransmitter: bit SPEN (RCSTA<7>) must be set (= 1), bit TRISC<6> must be cleared (= 0), and bit TRISC<7> must be set (=1). Register 16-1 shows the Transmit Status and Control. Register (TXSTA) and Register 16-2 shows the. Receive Status and Control Register (RCSTA). The standart USART to set this microchip base on the datasheet IC PIC 18F6722 as we well as we show you in this datasheet table of USART below :

III. 5 Analog-to-Digital converter (ADC) in PIC 18F6722 The Analog-to-Digital (A/D) converter module has12 inputs for the 64-pin devices and 16 for the 80-pindevices. This module allows conversion of an analoginput signal to a corresponding 10bit digital number. The module has five registers: A/D Result High Register (ADRESH) A/D Result Low Register (ADRESL) A/D Control Register 0 (ADCON0) A/D Control Register 1 (ADCON1) A/D Control Register 2 (ADCON2) The ADCON0 register, shown in Register 21-1,controls the operation of the A/D module. TheADCON1 register, shown in Register 21-2, configuresthe functions of the port pins. The ADCON2 register,shown in Register 21-3, configures the A/D clocksource, programmed acquisition time and justification [7].

IVSource Program IV.1 USART.H This program define all of he function which are used in the system, including the open connection function of serial RS 232, also read and write function of the serial connector. In this term we will write the output of the sensor LM35 to the hyperterminal as a result measurement of temperature.
#ifndef USART_H #define USART_H #include "p18f6722.h" //declare function of open connection voidUSARTInit(); //declare funtcion of write mode byte voidwrite_byte(char); //declare funtcion of write mode string voidwrite_string(const char *); //declare funtcion of write mode integer voidwrite_int(int ,unsigned char); //declare funtcion of read unsigned char read_byte(); #endif

IV.2 USART.C In this program usart.c file contains all of the functions that used in this usart communication. The void USARTInit() is a function for initializing the usart. void write_byte ( ) is a function to write the ouput from sensor to the hyperterminal in mode byte. There are another function of write in this program, but in different mode of write function, such as mode write string and integer. The last function is void read_byte ( ), this function are used for read the input from hyperterminal (through serial connection) than redirect the input as task for microcontroller.
#include "p18f6722.h" #include "usart.h" //open connection to serial via USART void USARTInit() { //Baud Rate = 57600 Bits per Second SPBRG1=86; //TXSTA REG TXSTA1bits.TXEN=1; TXSTA1bits.BRGH=1; //TXSTA1bits.SYNC=0; //RCSTA RCSTA1bits.SPEN=1;

RCSTA1bits.CREN=1; //BAUDCON BAUDCON1bits.BRG16=1; }

//Enable Receiver (RX)

//write output of serial to the hyperterminal mode byte voidwrite_byte(char ch) { //Wait for TXREG Buffer to become available while(!PIR1bits.TX1IF); //Write data TXREG1=ch; } //write output of serial to the hyperterminal mode string voidwrite_string(const char *str) { while((*str)!='\0') { //Wait for TXREG Buffer to become available while(!PIR1bits.TX1IF); //Write data TXREG1=(*str); //Next goto char str++; } } //write output of serial to the hyperterminal mode integer voidwrite_int(intval,unsigned char field_length) { char str[5]={0,0,0,0,0}; int i=4,j=0; if(val<0) { write_byte('-'); val=(val*(-1)); }

//Write '-' sign for negative numbers. //Make it positive.

//Convert Number To String and pump over Tx Channel. while(val) { str[i]=val%10; val=val/10; i--; } if(field_length>5) while(str[j]==0) j++; else j=5-field_length; for(i=j;i<5;i++) { write_byte('0'+str[i]); }

} //Read function --> Read the input of serial from hyperterminal unsigned char read_byte() { while(!PIR1bits.RCIF); //Wait for a byte return RCREG1; }

IV.3 MAIN.C This is the main program of the system, several function which defined and developed in usart.h and usart.c are executed here. First, to get the output from sensor temperature, we should initialized ADC (Analog Digital Converter). Then, with the function void ACDInit ( ) the configuration of microcontroller to get the data from the sensor are established. The function of USARTInit is important too, this function activate Serial Connection. The process of getting data output from sensor and write this data to the hyperterminal, are initiated in this main program. So, several variable character and integer are needed for completed the process.
#include "p18f6722.h" #include <math.h> #include "usart.h" unsigned char word[]="Temperature : "; unsignedintadcval; //ADC Value unsigned char kar,kar1; //function to initialize ADC void ADCInit() { ADCON2=0x0F; ADCON0=0x00;//Select ADC Channel //Voltage Reference Configuration bits 00, Vref+ = AVDD, Vref- = AVSS ADCON1=0x00; } //Function to Read given ADC channel in order to read the output of sensor unsignedintADCRead() { unsigned char dat; ADCON0bits.ADON=1; ADCON0bits.GO_DONE=1;//Start conversion while(ADCON0bits.GO_DONE); //wait for the conversion to finish //PIR1bits.ADIF=0; ADCON0bits.ADON=0; //switch off adc dat=ADRESH; returndat; } //delay paramatre voiddelay_ms(intval) { int i; for(i=0;i<val;i++);

10

} //------ Main Program---------// void main() { chari,var; //Initialize the USART USARTInit(); ADCInit(); TRISAbits.TRISA0 = 1; TRISB=0x00; for (i=0;i<sizeof(word);i++) { var=word[i]; write_byte(var); } write_byte(' write_byte(' write_byte(' write_byte(' write_byte(' '); '); '); '); ');

while(1) { adcval=ADCRead(); //Read Channel 0 PORTB=adcval; //write the value of the output in hyperterminal delay_ms(500); kar=(adcval/10)+0x30; kar1=(adcval%10)+0x30; write_byte(8); write_byte(8); write_byte(8); write_byte(8); write_byte(8); write_byte(kar); write_byte(kar1); write_byte(' '); write_byte(248); write_byte('C'); } }

11

VI. 4 Schema proteus of this system In figure 6 we provide the full schema of the system that consist of : Sensor LM35 Microcontroller PIC18F6722 Connector RS232 LED Power and Ground Modul

1. 2. 3. 4. 5.

Figure 6. Schema Proteus of The System The output temperature reading from hyperterminal has been represented in figure 7 below . The temperature is relevant to the output of sensor LM35 which is sent by microcontroller through RS232.

Figure 7 Output Hyperterminal 12

V. Conclusion 1. Base on the Figure 7. Output hyperterminal, we can make a conclusion that the communication between the sensor and personal computer can be establised using microcontroller trough serial connection. 2. However, the system is running well, but actually there is a dificulty to match the sensor and the microcontroller (syncronization between sensor and microcontroller). It is very complex setting. 3. This system will completely perfect if we can add with SD card system store. But because the complexity of syncronization between microcontroller and SD card, so we cant add this system with SD card instantly.

13

[1] [2] [3] [4] [5] [6] [7]

www.8051microcontrollers.com Datasheet microchip IC PIC 18FXX2 http://en.wikipedia.org/wiki/PIC_microcontroller RS232 Data Interface a Tutorial on Data Interface and cables. http://www.arcelect.com/rs232.htm http://www.eti.pg.gda.pl/katedry/ksg/dydaktyka/dla_studentow//usart.pdf Datasheet PIC18F8722 Family

14

Das könnte Ihnen auch gefallen