Santoshhh
Newbie level 6
Hi all, I am trying to design a digital thermometer using LM35, PIC16F877A, and JHD162A LCD. I have coded the microcontroller program in MPLAB IDE and compiled it using HITEC C compiler. I burnt the program using PICKIT2. After breadboarding and finally running the circuit, I came up with an annoying result. There were 16 square blocks being displayed in the LCD in the second line and nothing in the first line. I have used a crystal of 20MHz. And I grounded those crystal pins using 0.1 uF capacitors because 22pF were unavailable. In the actual circuit diagram in the internet I've seen that 22 pF capacitors are used. Can that be a reason? The LCD displayed the same result as it showed without using the crystal. ALso, all the data pins in port B were high. Are they all supposed to be high all the time? I have attached the code herewith. My another problem is that during the simulation in PROTEUS, when I give an input of 24 degree celsius to LM35, 12 degree is displayed in the LCD, when 25 is given, 13 is displayed and when it is changed to 26, still 13 is displayed. On changing the input to 27 degree celsius, output is displayed as 14 and so on i.e. linearity is present but the output is one-halved of the expected output.
The code is:
- - - Updated - - -
This is the schematic on PROTEUS.
The code is:
Code:
#include<htc.h>
#define data PORTB
#define RS RD0
#define EN RD1
__CONFIG(HS & PWRTEN & BORDIS & WDTDIS & LVPDIS);
int ad_result;
/*************us delay****************/
void delay_100us(int n )
{
TMR1H=0xFE;
TMR1L=0x0C;
T1CKPS1=0;
T1CKPS0=0;
TMR1CS=0;
TMR1IF=0;
TMR1ON=1;
while(n>0)
{
while(!TMR1IF) { }
TMR1IF=0;
TMR1H=0xFE;
TMR1L=0x0C;
n--;
}
}
/***********************ms delay****************/
void delay_ms(int n )
{
TMR1H=0xEC; // EC77H=60535d
TMR1L=0x77;
T1CKPS1=0;
T1CKPS0=0;
TMR1CS=0;
TMR1IF=0;
TMR1ON=1;
while(n>0)
{
while(!TMR1IF) { }
TMR1IF=0;
TMR1H=0xEC;
TMR1L=0x77;
n--;
}
}
/******************ADC Initialisation**************/
void init_ADC()
{
PCFG3=0; PCFG2=0; PCFG1=0; PCFG0=0; //Taking channel A as analog input
ADCS1=1; ADCS0=0; ADCS2=0; //Using 32 Tosc
ADFM=0; //Left Justification
}
/**************LCD Write********************/
void LCD_Write(unsigned char value,int rs)
{
data = value;
RS = rs;
EN = 1;
delay_ms(1);
EN = 0;
}
/**************LCD Clear********************/
void LCD_clear(void)
{
LCD_Write(0x01,0);
}
/**************LCD GoTo********************/
void LCD_goto(unsigned char row,unsigned char column)
{
if(row==1)
{
LCD_Write(0x80+column,0); //0x80 takes the cursor at 1st row
}
else if(row==2)
{
LCD_Write(0xC0+column,0); //0xC0 takes the cursor at 2ns row
}
}
/**************LCD Num********************/
void LCD_num(int n)
{
if(n<=9)
{
LCD_Write(48+n,1);
}
else if(n<=99)
{
LCD_Write((n/10)+48,1);
LCD_Write((n%10)+48,1);
}
else if(n<=999)
{
LCD_Write((n/100)+48,1);
LCD_Write(((n%100)/10)+48,1);
LCD_Write((n%10)+48,1);
}
}
/**************LCD Initialisation********************/
void initLCD(void)
{
//PORT configuration
TRISB = 0x00;
TRISD=0x00;
//////////////////
LCD_Write(0x30,0);
data = 0x3; // 8 bit mode
EN=1; EN = 0;
LCD_Write(0x38,0);
delay_ms(1);
LCD_Write(0x0E,0); //display on , cursor blinking
delay_ms(1);
LCD_Write(0x01,0); // clear display screen
delay_ms(1);
LCD_Write(0x06,0);
//LCD_Write(0x0F,0); //blinking cursor
delay_ms(1);
LCD_clear();
LCD_goto(1,1);
LCD_Write('T',1);LCD_Write('e',1); LCD_Write('m',1); LCD_Write('p',1);LCD_Write('=',1);
}
/***************** ADC *****************/
void ADC()
{
ADON=1;
CHS2=0; CHS1=0; CHS0=0;
delay_100us(3);
ADGO = 1;
while(ADGO);
ad_result=(int)ADRESH;
LCD_goto(1,5);
if(ad_result<10)
{
LCD_Write(' ',1);
LCD_Write(' ',1);
}
else if(ad_result<100)
{
LCD_Write(' ',1);
}
LCD_num(ad_result);
}
/********************** Main Function ****************************/
void main()
{
TRISB=0x00; //Configuring all pins of B port as output.
PORTB=0x00; //output at all pins will be low
TRISA=0xff; //Configuring all pins of A port as input
TRISD0=TRISD1=0;
RD0=RD1=0;
ADIE=0; //A/D interrupt disabled
ADIF=0; //A/D flag reset
GIE=0;
init_ADC();
initLCD();
while(1)
{
ADC(); //call ADC
}
}
- - - Updated - - -
This is the schematic on PROTEUS.