1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100
| /*
Titre : détection de deux seuils de température
Fichier : temperature.c
Auteur : Aurelien Kameni
But : détecter deux seuils de température grâce à un capteur DS18S20 et l'afficher sur un écran LCD 2x16.
Date de creation : 26 Mars 2011
dernière modification : 28 Mars 2011
Configuration :
- µc : PIC 16F877A
- Carte de developpement : EasyPIC6
- Quartz : 8 MHz (HS)
- Modules externes : Capteur DS18S20
LCD 2x16
-Software : MikroC v4.15.0.0
*/
sbit LCD_RS at RB4_bit;
sbit LCD_EN at RB5_bit;
sbit LCD_D7 at RB3_bit;
sbit LCD_D6 at RB2_bit;
sbit LCD_D5 at RB1_bit;
sbit LCD_D4 at RB0_bit;
// Pin direction
sbit LCD_RS_Direction at TRISB4_bit;
sbit LCD_EN_Direction at TRISB5_bit;
sbit LCD_D7_Direction at TRISB3_bit;
sbit LCD_D6_Direction at TRISB2_bit;
sbit LCD_D5_Direction at TRISB1_bit;
sbit LCD_D4_Direction at TRISB0_bit;
const unsigned short TEMP_RESOLUTION = 9;
char *text = "000.0000";
// Set TEMP_RESOLUTION to the corresponding resolution of your DS18x20 sensor:
unsigned temp,ct,dt,u; //ct pour centaine, dt pour dizaine et u pour unité
unsigned short j;
void main()
{
ADCON1 = 0x82; // Configure RA5 pin as digital I/O
trisb = 0xdf;
portb = 0;
// Initialize LCD on PORTB and prepare for output
Lcd_Init();
Lcd_Cmd(_LCD_CLEAR);
Lcd_Cmd(_LCD_CURSOR_OFF);
while(1) // boucle principale
{
//acquisition de la température sur RA5 (temp)
Ow_Reset(&PORTA, 5); // Onewire reset signal
Ow_Write(&PORTA, 5, 0xCC); // Issue command SKIP_ROM
Ow_Write(&PORTA, 5, 0x44); // Issue command CONVERT_T
Delay_us(120);
Ow_Reset(&PORTA, 5);
Delay_us(120);
Ow_Write(&PORTA, 5, 0xCC); // Issue command SKIP_ROM
Ow_Write(&PORTA, 5, 0xBE); // Issue command READ_SCRATCHPAD
temp = Ow_Read(&PORTA, 5);
temp = (Ow_Read(&PORTA, 5) << 8) + temp;
Ow_Reset(&PORTA, 5);
Delay_us(120);
Display_Temperature(temp);
Delay_ms(500);
// Affichage
Lcd_Out(1, 1, "Temperature :");
temp=temp/2; //début du calcul et de l'affichage de la température
ct=temp/100 ;
Lcd_Chr_Cp(ct+0x30);
dt=(temp-100*ct)/10;
Lcd_Chr_Cp(dt+0x30);
u=temp-(ct*100+dt*10);
Lcd_Chr_Cp(u+0x30);
/*Lcd_Out(1, 1, "Cons: ");
Lcd_Chr(2,13,223);
Lcd_Chr(2,14,'C'); */
if(temp>=30)
{
portb=1;
delay_ms(500);
portb=0;
delay_ms(500);
}
else
if(temp<=20)
{
portb=0;
delay_ms(500);
}
}
} |