PIC16F877A LM35/LM36 Temperature sensor interface using MikroC coding

Опубликовано: 19 Март 2026
на канале: Learning Microcontrollers
8,270
112

Guys, My lectures are free for everyone.
If you want to support my channel, then become a Youtube member by following link below:

   / @learningmicrocontrollers3561  

Seek knowledge from the cradle to the grave
/// /////////////////////////////////////////////////////**********************************///////////////////////////////// Hello guys,
Welcome to Learning Microcontrollers youtube Channel,

Guys I have also compiled course on Udemy as well. Where you will learn under my direct supervision in a more supervised way.
Here is the links to the courses I have on Udemy, By taking any of these courses you will be supporting my channel aswell.
This will help me to make more videos with better hardware in the future. I hope you look forward to it.
Courses Links:

1- https://www.udemy.com/course/pic16f87...
2- https://www.udemy.com/course/mikroc-f...
3- https://www.udemy.com/course/mikroc-f...
4- https://www.udemy.com/course/pic-micr...
5- https://www.udemy.com/course/learn-ar... ///////////////////////////////////////////////////// Hello Ladies and Gentlemen,
This video is about how to interface a LM 35 temperature sensor with PIC16f877A with full coding support. If you still have any problem let me know. Always happy to help.

A remastered version of this video wih voiceover has been uploaded and its link is in description below:

   • PIC16F877A interface LM35 temperature sens...  

Here is the code:

// Lcd pinout settings
sbit LCD_RS at RB0_bit;
sbit LCD_EN at RB1_bit;
sbit LCD_D7 at RB5_bit;
sbit LCD_D6 at RB4_bit;
sbit LCD_D5 at RB3_bit;
sbit LCD_D4 at RB2_bit;

// Pin direction
sbit LCD_RS_Direction at TRISB0_bit;
sbit LCD_EN_Direction at TRISB1_bit;
sbit LCD_D7_Direction at TRISB5_bit;
sbit LCD_D6_Direction at TRISB4_bit;
sbit LCD_D5_Direction at TRISB3_bit;
sbit LCD_D4_Direction at TRISB2_bit;
int vref = 5 ; // its your applied voltage change if 3.3 or 3.7 etc
int tmp; // intialzie variable int as tmp
int temp_celcius;
char tmp1[3]; // intialize char to store a string of 3 chars
void main() {


LCD_Init(); //Intializes the LCD modules
DElay_ms(250);
ADC_Init(); // Initializes the ADC Module for ADC Conversions
Delay_ms(250);

LCD_OUT(1,1, " Learning ");// LCD Will display at row 1 column 1 Learning.
LCD_OUT(2,2, "Microcontrollers"); // LCD Will display at row column 2 Microcontrollers.
Delay_ms(3200); // Will display this for 2 seconds
Lcd_Cmd(_LCD_CLEAR); // Will clear LCD for new valuse to be displayed
while(1) // Needed for operations its an internal loop which keeps on executing
{
tmp = ADC_Read(0); // ADC read from pin AN 0
Delay_ms(50);

temp_celcius = ( tmp * vref )/ 10 ;
delay_ms(20);

IntToStr(temp_celcius, tmp1);// will convert values of tmp to tmp1
delay_ms(20);

// Now we can display this string on LCD

Lcd_Cmd(_LCD_CLEAR); // Precaution clear for readings to be displayed

LCD_OUT(1,1, "Temp = ");
LCD_OUT(1,10,tmp1); // I changed column number to display result after above helping string
Delay_ms(800); // Keep displaying same value for 0.5 sec

Lcd_Cmd(_LCD_CLEAR); // Then clear LCD for new values




}

}