Sign In

Lm35 Interfacing With Pic18f4550

maitreyee gupte maitreyeegupte@gmail.com India

Hardware: Pic18f4550 Running At 20Mhz Software: Mplab 8.89, 3.4v

the code written here is built using v4.46 and i am using 3.4v....plzz i need help to run the program
and i have also tried writing my own program can u plzz tell me what is wrong with it

Images

Program

//Aim:To Interface lm35 and display
// the converted output value on LCD 
#include <p18f4550.h>
#include<stdio.h>
#define LCD_EN PORTCbits.RC1
#define LCD_RS PORTCbits.RC0
#define LCDPORT PORTB

void lcd_delay(unsigned int time)
{
 unsigned int i , j ;

    for(i = 0; i < time; i++)
    {
            for(j=0;j<50;j++);
    }
}
void LCD_cmd(unsigned char command)
{
     LCD_RS = 0;		// RS low : Instruction
     LCDPORT = command;
     LCD_EN = 1;		// EN High
     lcd_delay(10);
     LCD_EN = 0;	// EN Low; command sampled at EN falling edge
     lcd_delay(10);
}

void LCD_write(unsigned char lcddata)
{
     LCD_RS = 1;		// RS HIGH : DATA
     LCDPORT = lcddata;
     LCD_EN = 1;		// EN High
     lcd_delay(10);
     LCD_EN = 0;	// EN Low; data sampled at EN falling edge
     lcd_delay(10);
}

void InitLCD(void)
{
    TRISB = 0x00; //set data port as output
    TRISCbits.TRISC0 = 0; //EN pin
    TRISCbits.TRISC1 = 0; // RS pin

    LCD_cmd(0x38);      //8 bit mode, 2 line,5x7 dots
    LCD_cmd(0x06);	// entry mode
    LCD_cmd(0x0C);	//Display ON cursor OFF
    LCD_cmd(0x01);      //Clear display
    LCD_cmd(0x80);      //set address to 0
}

void ADCInit(void)
{
    TRISEbits.TRISE1 = 1;                  //ADC channel 6 input

    ADCON1 = 0b00000111;   //Ref voltages Vdd & Vss; AN0 - AN7 channels Analog
    ADCON2 = 0b10101110; //Right justified; Acquisition time 12T; Conversion clock Fosc/64
}

unsigned short Read_ADC(void)
{
    ADCON0 = 0b00011001;      	//ADC on; Select channel 6
    ADCON0bits.GO_DONE = 1;              //Start Conversion

    while((ADCON0bits.GO_DONE) != 0 );    //Wait till A/D conversion is complete
    return ADRES;                       //Return ADC result
}

 void DisplayResult(unsigned short ADCVal)
{
 unsigned char i,text[16];
 LCD_cmd(0x80);                 //set to 1st line
(ADCVal*0.48876);
 sprintf(text,"%03X",ADCVal);         //Convert integer data to string

 for(i=0;i<3;i++)                          //Display string on LCD
 {
   LCD_write(text[i]);
 }

}

void main()
{
    unsigned short Ch_result;

    ADCInit();			//Initialise ADC module
    InitLCD();			//Initialise LCD

    while(1)
    {
        Ch_result = Read_ADC();			//Read value after ADC conversion
        DisplayResult(Ch_result);		//Display the result on LCD
        lcd_delay(5000);
    }
}



Replies

R Avinash
2017-01-29 05:11:44
post your schematic and photo of actual circuit.

Post a reply to maitreyee gupte

Think you can help maitreyee gupte ? Then post your thoughts that might help maitreyee gupte. You will earn a lot of reputation in the technical community.

If your program is in multiple files, then ZIP the entire folder and attach below

Images and Screenshots

These helps other better understand your suggestion.