Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
hkBattousai have you included the float.h file ?
#include <p18f2550.h>
#include "delays.h"
#include "glcd.h"
#pragma config WDT = OFF
#pragma config MCLRE = ON
#pragma config DEBUG = OFF
#pragma config LVP = OFF
#pragma config PLLDIV = 5 // need 5 for 20MHz xtal
#pragma config CPUDIV = OSC1_PLL2 // CPU Clock = 96 MHz/2 = 48 MHz
#pragma config USBDIV = 2 // 96MHz PLL/2 = 48 MHz for USB clock
#pragma config FOSC = HSPLL_HS // High Speed Crystal / Resonator with PLL enabled
void main (void)
{
int temp;
float temperature;
ADCON0 = 0x01;
ADCON1 = 0x0e;
ADCON2 = 0xbe;
CMCON=7;
TRISAbits.TRISA0 = 1;
glcd_Init();
while (1)
{
// Do A/D conversion
ADCON0 |= 0x02;
while(ADCON0 & 0x02);
// Read higher part of digital data
temp = (int) ADRESH; // Always zero since LM35 outputs only 0.18V
// Multiply by 256
if (temp == 1) temp = 256;
else if (temp == 2) temp = 512;
else if (temp == 3) temp = 768;
// Add lower part
temp += (int) ADRESL;
// Convert digital data to Celcius
temperature = 0.48828f * (float) temp;
// Clear LCD screen
glcd_ClearScreen();
// Format and print the string
glcd_SetPosition(0, 17);
glcd_PutMessage("The temperature is: ");
glcd_WriteFloat(temperature);
// Delay before next update
for (i=0; i<5; i++) Delay10KTCYx(0);
}
}
void glcd_WriteInteger(int num)
{
int i;
char str[7];
sprintf(str, "%d", num);
for (i=0; str[i]!=0; i++) glcd_PutChar(str[i]);
}
void glcd_WriteFloat(float num)
{
int frac;
glcd_WriteInteger((int) num);
glcd_PutChar('.');
frac = (int) (100.0f * (num - ((int) num)));
if (frac == 0)
{
glcd_PutChar('0');
glcd_PutChar('0');
}
else if (frac < 10)
{
glcd_PutChar('0');
glcd_WriteInteger(frac);
}
else
{
glcd_WriteInteger(frac);
}
}
Hi hkBattousai bat for use the sprintf functioun is not necessary include the string.h library ?
Can you put the code for the glcd_PutRAMMessage function or your glc.c ?
I check the your code bat no work in my board.
Thank you very much.
I'll try it and have to modify the code for use whith one 18f4550 and the EasyPic5.
Sorry for my bad English