// LCD module connections
sbit LCD_RS at LATB0_bit;
sbit LCD_EN at LATB1_bit;
sbit LCD_D4 at LATB2_bit;
sbit LCD_D5 at LATB3_bit;
sbit LCD_D6 at LATB4_bit;
sbit LCD_D7 at LATB5_bit;
sbit LCD_RS_Direction at TRISB0_bit;
sbit LCD_EN_Direction at TRISB1_bit;
sbit LCD_D4_Direction at TRISB2_bit;
sbit LCD_D5_Direction at TRISB3_bit;
sbit LCD_D6_Direction at TRISB4_bit;
sbit LCD_D7_Direction at TRISB5_bit;
// End LCD module connections
#include "USBdsc.c"
#define TAILLE_BUFFER 64
#define TAILLE_MOYENNE 10
#define PE 5.
#define N 1024.
#define ALPHA 0.0039
#define E 5.
#define VOIE_OFFSET 2
#define VOIE_PT500 1
#define VOIE_LM35 0
#define GAIN_INA126 5
char ReadBuffer[TAILLE_BUFFER], WriteBuffer[TAILLE_BUFFER];
void Vider_Buffer(char * Buffer)
{
char i;
for (i=0;i<TAILLE_BUFFER;i++) Buffer[i]=0;
}
void interrupt()
{
if (PIR2.USBIF == 1)
{
USB_Interrupt_Proc();
}
}
void InitPic() {
ADCON1=0b1011;
CMCON = 7;
TRISB = 0;
//------------- USB -------------
TRISC.f4=1; //D-
TRISC.f5=1; //D+
HID_Enable(&ReadBuffer,&WriteBuffer);
}
int GetSample (int channel) {
int i;
int mean;
mean = 0;
for (i=0; i<TAILLE_MOYENNE; i++)
{
mean += ADC_Read(channel);
Delay_ms(1);
}
mean /= TAILLE_MOYENNE;
return mean;
}
void main() {
float value;
float offset;
float temp_pt500 = 0;
char ligne1[17];
char ligne2[17];
InitPic();
Lcd_Init();
Lcd_Cmd(_LCD_CLEAR);
Lcd_Cmd(_LCD_CURSOR_OFF);
while(1) {
value = GetSample(VOIE_LM35) * PE / N;
sprintf(ligne2, "LM35: %2.1f °C ",value/0.01);
Lcd_Out(2,1,ligne2);
offset = (GetSample(VOIE_OFFSET) * PE / N);
value = ((GetSample(VOIE_PT500) * PE / N) - offset)/GAIN_INA126;
temp_pt500 = (4. * value) / (ALPHA * (2.*value + E));
sprintf(ligne1, "Pt500: %2.1f °C ",temp_pt500);
Lcd_Out(1,1,ligne1);
Delay_ms(100);
}
}