Ernest Clyde Chua
Newbie level 6
- Joined
- Jul 29, 2014
- Messages
- 13
- Helped
- 0
- Reputation
- 0
- Reaction score
- 0
- Trophy points
- 1
- Activity points
- 69
hi im making a digital thermometer using lm34 and pic16f877a,
heres the code
when the reading is greater than 64 it reverts back to zero and increments as the reading rise.
what is wrong with the code and also how can i get decimal reading?
heres the code
Code:
sbit LCD_RS at RB4_bit;
sbit LCD_EN at RB5_bit;
sbit LCD_D4 at RB0_bit;
sbit LCD_D5 at RB1_bit;
sbit LCD_D6 at RB2_bit;
sbit LCD_D7 at RB3_bit;
sbit LCD_RS_Direction at TRISB4_bit;
sbit LCD_EN_Direction at TRISB5_bit;
sbit LCD_D4_Direction at TRISB0_bit;
sbit LCD_D5_Direction at TRISB1_bit;
sbit LCD_D6_Direction at TRISB2_bit;
sbit LCD_D7_Direction at TRISB3_bit;
//-----------------------------------------------------
void staticprint(){
LCD_Out(2,1,"TIME");
LCD_Out(2,14,":");
LCD_Out(2,11,":");
LCD_Out(2,8,":");
LCD_Out(1,1,"TEMP");
LCD_Chr(1,15, 223);
LCD_Out(1,16,"F");
}
//--------------------------------------tahmids code for lm35----------------
void readtemp()
{
unsigned long ADRead;
unsigned int vDisp[3];
unsigned char Display[7];
ADRead = (ADC_Get_Sample(0) * 500) >> 10;
vDisp[0] = ADRead / 100;
vDisp[1] = (ADRead / 10) % 10;
vDisp[2] = ADRead % 10;
Display[1] = vDisp[0] + 48;
Display[2] = vDisp[1] + 48;
Display[3] = vDisp[2] + 48;
LCD_Chr(1, 8, Display[0]);
LCD_Chr(1, 9, Display[1]);
LCD_Chr(1, 10, Display[2]);
LCD_Chr(1, 11, Display[3]);
}
//------------------------------------------------------
void mydelay()
{
readtemp();
staticprint();
Delay_ms(250);
readtemp();
staticprint();
Delay_ms(250);
readtemp();
staticprint();
Delay_ms(250);
readtemp();
staticprint();
Delay_ms(250);
}
//------------------------------------------------------
//-----------------------------------------------------------------------------
void main()
{
//-----------------------------
PORTA = 0;
TRISA = 0X01;
PORTB = 0;
TRISB = 0;
LCD_Init();
LCD_Cmd(_LCD_CURSOR_OFF);
LCD_Cmd(_LCD_CLEAR);
ADCON1 = 0x0E;
ADC_Init();
//----------------------------
//////////////////////////////////////////////////////////////////////////
while (1)
{
//------------variables-----------------------
char secs[7];
char mins[7];
char hours[7];
char days[7];
unsigned int s;
unsigned int m;
unsigned int h;
unsigned int d;
//-------------------------------------------
for(d = 0;d<40;d++)
{
IntToStr(d,days);
if(d<10)
{
LCD_Out(2,7,Ltrim(days));
LCD_Out(2,6, "0");
}
if (d>9)
{
LCD_Out(2,6,Ltrim(days));
}
for(h = 0;h<24;h++)
{
IntToStr(h,hours);
if(h==24)
{
d++;
}
if(h<10)
{
LCD_Out(2,10,Ltrim(hours));
LCD_Out(2,9,"0");
}
if (h>9)
{
LCD_Out(2,9,Ltrim(hours));
}
for(m = 0;m<60;m++)
{
IntToStr(m,mins);
if(m==60)
{
h++;
}
if(m<10)
{
LCD_Out(2,13,Ltrim(mins));
LCD_Out(2,12, "0");
}
if (m>9)
{
LCD_Out(2,12,Ltrim(mins));
}
for(s = 0;s<60;s++)
{
IntToStr(s,secs);
if(s==60)
{
m++;
}
if(s<10)
{
LCD_Out(2,16,Ltrim(secs));
LCD_Out(2,15, "0");
}
if (s>9)
{
LCD_Out(2,15,Ltrim(secs));
}
mydelay();
}
}
}
}
}
}
what is wrong with the code and also how can i get decimal reading?