PIC16F877A – Interfacing Temperature sensor
PIC16F877A mini development board has on board temperature sensor MCP9700. Here in this section, we discuss the interfacing of the same with its host controller PIC16F877A. PIC16F877A has 8 channel 10-bit successive approximation ADC.
On the Mini Development Board the temperature sensor MCP9700 is connected to pin RA1 of the controller i.e, channel1 via jumper J17. The MCP9700/9700A and MCP9701/9701A family of Linear Active Thermistor™ Integrated Circuit (IC) is an analog temperature sensor that converts temperature to analog voltage. It has an accuracy of ±2°C from 0°C to +70°C (MCP9700A/9701A) ±4°C from 0°C to +70°C (MCP9700/9701) while consuming 6µA (typical) of operating current. Sensitivity is 10mV/°C. At 0°C, the output is 500mV. So that’s the spec and description for MCP9700, now lets see its actual working here below.
SchematicNote: To use temperature sensor, don’t forget to short jumper J17. Leaving it open frees RA1 and it can be used for any other desired purpose.
Sample Code
Sample code to check the temperature sensor is given below. The output is displayed on LCD.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 |
/************************************************************************* HEADER FILES **************************************************************************/ #include<pic.h> /************************************************************************* FUNCTION DECLARATIONS **************************************************************************/ void LCD_Command(int com); void LCD_Data(int data); void Display(const char Adr, const char *LCD); void Delay_us(char Delay); void Delay_100us(unsigned long int Delay); /************************************************************************* VARIABLE DECLARATIONS **************************************************************************/ int k,result; char array[5]; /************************************************************************* MAIN FUNCTION **************************************************************************/ void main() { TRISA = 0XFF; /* PORTA configured as i/p */ TRISC = 0X00; /* LCD control lines configured as o/p */ TRISD = 0X00; /* LCD data lines configured as o/p */ LCD_Command(0X30); /* LCD specification command */ Delay_us(35); LCD_Command(0X30); /* LCD specification command */ Delay_us(35); LCD_Command(0X30); /* LCD specification command */ Delay_us(35); LCD_Command(0X38); /* Double Line Display Command */ LCD_Command(0X06); /* Auto Increment Location Address Command */ LCD_Command(0X0C); /* Display ON Command */ LCD_Command(0X01); /* Clear Display Command */ Delay_100us(30); Display(0x80,"Temp: "); /* Display string in the first line */ ADCON0 = 0x89; /* Clock source=Fosc/32, channel-1, ADON=1 */ ADCON1 = 0x80; /* Result right justified */ while(1) { ADGO = 1; while(ADGO==1); /* Wait until ADGO=0 (conversion completed)*/ result = ADRESH; /* Copy the 2 bit in ADRESH to result */ result = result << 8; /* Shift it 8 bits to left */ result = result + ADRESL; /* Add left shifted value to 8 bit ADRESL */ /* Convert the result to equivalent temp. */ result = (((result / 204.5)-0.5)/0.01); for(k=0; k<=3; k++) /* Convert the result in integer to ASCII */ { array[k] = result % 10; /* Separate each digit of the integer */ result = result / 10; } LCD_Command(0X87); for(k=3; k>=0; k--) { LCD_Data(array[k]+'0'); /* Display the result on LCD */ } } } /************************************************************************* * Function : LCD_Command * * * * Description : Function to send a command to LCD * * * * Parameters : com - command to be sent * **************************************************************************/ void LCD_Command(int com) { PORTD = com; /* Write the command to data lines */ RC0 = 0; /* RS-0(Command register) */ RC1 = 1; /* E-1(Enable pin high) */ Delay_us(30); RC1 = 0; /* E-0(Enable pin low) */ } /************************************************************************* * Function : LCD_Data * * * * Description : Function to display single character on LCD * * * * Parameters : data - character to be displayed * **************************************************************************/ void LCD_Data(int data) { PORTD = data; /* Write the character to data lines */ RC0 = 1; /* RS-1(Data register) */ RC1 = 1; /* E-1(Enable pin high) */ Delay_us(30); RC1 = 0; /* E-0(Enable pin low) */ } /************************************************************************* * Function : Display * * * * Description : Function to display string on LCD * * * * Parameters : loc - location * * String to be displayed * **************************************************************************/ void Display(const char loc, const char *LCD) { LCD_Command(loc); /* Address of location to display string */ while(*LCD!='\0') /* Check for termination character */ { LCD_Data(*LCD); /* Display the character on LCD */ LCD++; /* Increment the pointer */ } } /************************************************************************* * Function : Delay_us * * * * Description : Function for 1 microsecond delay * * * * Parameter : Delay - delay in microseconds * **************************************************************************/ void Delay_us(char Delay) { while((--Delay)!=0); } /************************************************************************* * Function : Delay_100us * * * * Description : Function for delay * * * * Parameter : Delay - delay interval * **************************************************************************/ void Delay_100us(unsigned long int Delay) { Delay=Delay*15; while((--Delay)!=0); } /*************************** END OF PROGRAM ****************************/ |
Topics related to PIC16F877A Development Board-Mini
- PIC16F877A Mini Development Board – Overview
- PIC16F877A Mini Development Board – Interfacing LED
- PIC16F877A Mini Development Board – Interfacing LCD
- PIC16F877A Mini Development Board – Serial communication(USART)
- PIC16F877A Mini Development Board – Interfacing Switch
- PIC16F877A Mini Development Board – Interfacing Buzzer
- PIC16F877A Mini Development Board – Interfacing POT(ADC)
- PIC16F877A Mini Development Board – Interfacing Temperature sensor
- PIC 16F877A Mini Development Board – Interfacing Servo Motor
- PIC 16F877A Mini Development Board – Interfacing μRFID Reader
Resources
- Datasheets
How to buy?
- Click here to buy rhydoLABZ PIC 16F877A Mini Development Board
- Click here to buy rhydoLABZ PIC 18F4520 Mini Development Board
- Click here to buy rhydoLABZ PIC 18F4550 Mini Development Board
- Click here to buy rhydoLABZ PIC 18F4580 Mini Development Board
SupportPlease share your ideas with us, visit our forum for discussion
Leave a Reply
You must be logged in to post a comment.