Vous êtes sur la page 1sur 3

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;
char seconds, minutes, hours, day, month, year;
/*******declaration des fonctions**********/
void temperature(int *cond);
void lcd(int li, int co, int nb, char receive[14]);
/***********************************Fonction temperature************************
****************/
void temperature(int *cond)
{ char temp[7], /*temptxt[]="T= ",*/ LSB;
signed char MSB;
I2C1_Start(); //Dtermine si l'I2C est libre et lance le signal
I2C1_Wr(0x90); //Mode de contrle en mode criture
I2C1_Wr(0xAA); //Lecture de la temprature
I2C1_Stop(); //Arrt du signal
I2C1_Start(); //Dtermine si l'I2C est libre et lance le signal
I2C1_Wr(0x91); //Mode de contrle en mode lecture
MSB = I2C1_Rd(1); //Nombre sign donnant la temprature entre +125 et -55C
LSB = I2C1_Rd(0); //Si bit 7 = 1 temprature MSB +0,5C
I2C1_Stop(); //Arrt du sigal
if(MSB<0)
{
MSB = abs(MSB); // Si temperature ngative valeur absolue de MSB
Temp[0]=45; //Signe - affect en ascii
}
else
{
Temp[0]=43; //signe + affect en ascii
}
Temp[1]=(MSB/10)+48; //Valeur des dizaines affect en ascii
Temp[2]=(MSB%10)+48; //Valeur des units affect en ascii
Temp[3]=44; //Virgule affect en ascii
if (LSB==128) //Si bit 7 1 alors +0.5
{
Temp[4]='5';
}
else //Si bit 7 0 alors +0.0
{
Temp[4]='0';
}
Temp[5]=223; // degr affect en ascii
Temp[6]=67; //C affect en ascii
if(*cond==10){ //Appel la fonction LCD tous les 1000
//lcd(2, 10, 11, temptxt); // affiche la valeur comprise dans la variable tempt
xt sur la ligne 1,colonne 1 du LCD
lcd(2, 10, 16, temp); //Affiche la valeur comprise dans la variable temp sur la
ligne 2, colonne 1
*cond=0; //Remise a 0 de la condition
}}
/************************************Fonction affichage*************************

**********/
void lcd(int li, int co, int nb, char receive[14])
{
int i;
for(i=0; i<=nb ; i++){ //Boucle for
Lcd_chr(li, (co+i), receive[i]); //Affiche les caractres jusqu' i
}}
void Read_Time() {
I2C1_Init(100000);
I2C1_Start(); // Issue start signal
I2C1_Wr(0xA0); // Address PCF8583, see PCF8583 datasheet
I2C1_Wr(2); // Start from address 2
I2C1_Repeated_Start();
// issue I2C signal repeated start
// s
end byte (device address + R)
I2C1_Wr(0xA1); // Start from address 2
seconds = I2C1_Rd(1); // Read seconds byte
minutes = I2C1_Rd(1); // Read minutes byte
hours = I2C1_Rd(1); // Read hours byte
day = I2C1_Rd(1); // Read year/day byte
month = I2C1_Rd(0); // Read weekday/month byte
I2C1_Stop(); // Issue stop signal
//-------------------- Formats date and time
}
void Transform_Time() {
seconds = ((seconds & 0xF0) >> 4)*10 + (seconds & 0x0F); // Transform seconds
minutes = ((minutes & 0xF0) >> 4)*10 + (minutes & 0x0F); // Transform months
hours = ((hours & 0xF0) >> 4)*10 + (hours & 0x0F); // Transform hours
//year = (day & 0xC0) >> 6; // Transform year
day = ((day & 0x30) >> 4)*10 + (day & 0x0F); // Transform day
month = ((month & 0x10) >> 4)*10 + (month & 0x0F); // Transform month
}
//-------------------- Output values to LCD
void Display_Time() {
Lcd_Chr(1, 6, (day /
Lcd_Chr(1, 7, (day %
Lcd_Chr(1, 9, (month
Lcd_Chr(1,10, (month
//Lcd_Chr(1,15, year

10) + 48); // Print tens digit of day variable


10) + 48); // Print oness digit of day variable
/ 10) + 48);
% 10) + 48);
+ 56); // Print year vaiable + 8 (start from year 2008)

Lcd_Chr(2, 1, (hours / 10) + 48);


Lcd_Chr(2, 2, (hours % 10) + 48);
Lcd_Chr(2, 4, (minutes / 10) + 48);
Lcd_Chr(2,5, (minutes % 10) + 48);
Lcd_Chr(2,7, (seconds / 10) + 48);
Lcd_Chr(2,8, (seconds % 10) + 48);
}
//------------------ Performs project-wide init
/*void Init_Main() {
//Soft_I2C_Init(); // Initialize Soft I2C communication
Lcd_Init(); // Initialize LCD
Lcd_Cmd(_LCD_CLEAR); // Clear LCD display
Lcd_Cmd(_LCD_CURSOR_OFF); // Turn cursor off
Lcd_Out(1,1,"Date:"); // Prepare and output static text on LCD
Lcd_Chr(1,8,':');

Lcd_Chr(1,11,':');
Lcd_Out(2,1,"Time:");
Lcd_Chr(2,8,':');
Lcd_Chr(2,11,':');
Lcd_Out(1,12,"200");
}
*/
void main() {
int cond=0;//Condition pour l'affichage sur l'cran LCD
PORTB=0; //initialisation du portB
PORTC=0; //initialisation du portB
TRISB=0; //configuration du portB en sortie
TRISC=0xF; //configuration du portA en entre
Lcd_Init(); // Initialize LCD
Lcd_Cmd(_LCD_CLEAR); // Clear LCD display
Lcd_Cmd(_LCD_CURSOR_OFF); // Turn cursor of
while(1){
//Lcd_Out(1,1,"Date:"); // Prepare and output static text on LCD
Lcd_Chr(1,8,'/');
Lcd_Chr(1,11,'/');
Lcd_Out(1,12,"2014");
//Lcd_Out(2,1,"Time:");
Lcd_Chr(2,3,':');
Lcd_Chr(2,6,':');
I2C1_Init(100000); //initialisation de la communication I2C
I2C1_Start(); //Dtermine si l'I2C est libre et lance le signal
I2C1_Wr(0x90); //Mode de contrle en mode criture
I2C1_Wr(0xAC); //Accs au registre de configuration
I2C1_Wr(0x0A); //Registre de configuration mesure en continu
I2C1_Stop(); //Arrt du signal
I2C1_Start(); //Dtermine si l'I2C est libre et lance le signal
I2C1_Wr(0x90); //Mode de contrle en mode criture
I2C1_Wr(0xEE); //Dbut de la conversion
I2C1_Stop(); //Arrt du signal
//while (1) { // Endless loop
Read_Time(); // Read time from RTC(PCF8583)
Transform_Time(); // Format date and time
Display_Time(); // Prepare and display on LCD
cond=cond+1; //Incrmente la variable cond
temperature(&cond); //Appel la fonction temperature
}
}