#define JEDNA PORTB.F3 #define CLK PORTB.F4 #define MINUS PORTB.F5 #define RELE1 PORTB.F6 #define RELE2 PORTB.F7 #define LED PORTA.F4 unsigned char cislice1, cislice2, cislice3; unsigned char min, max, hod1, hod2,hod1_zobr,hod2_zobr, stav_zaloha ; unsigned char *h1 = "00"; unsigned char *h2 = "00"; unsigned char *h3 = "00"; unsigned int temp; unsigned char osm; unsigned char cit1, Prepni; unsigned char cislice_zmena1, cislice_zmena2, cislice_zmena3, cislice_zmena4; unsigned char Teplota, Hystereze; bit Alarm, Znamenko, ERROR, Invert; unsigned short CISLO (unsigned char cis) { switch (cis) { case (0) : return 0b11000000; case (1) : return 0b11111001; case (2) : return 0b10100100; case (3) : return 0b10110000; case (4) : return 0b10011001; case (5) : return 0b10010010; case (6) : return 0b10000010; case (7) : return 0b11111000; case (8) : return 0b10000000; case (9) : return 0b10010000; } } void posli (){ osm = 8; Loop: osm--; PORTB.B0 = cislice1.B7; PORTB.B1 = cislice2.B7; PORTB.B2 = cislice3.B7; CLK = 1; CLK = 0; cislice1 = cislice1 << 1; cislice2 = cislice2 << 1; cislice3 = cislice3 << 1; if (osm != 0) goto Loop; } void Tlacitka (){ if (RA3_BIT == 0) { Alarm = ~Alarm; if(Alarm == 1)stav_zaloha = 1; else stav_zaloha = 0; EEPROM_Write(0x03, stav_zaloha); Delay_ms (10); Prepni = 0; do{ if (RA2_BIT == 0)Prepni = 1; }while (RA3_BIT == 0); } } void Termostat (){ cislice_zmena1 = cislice_zmena1 - 1; cislice_zmena2 = cislice_zmena2 - 1; cislice_zmena3 = cislice_zmena3 - 1; cislice_zmena4 = cislice_zmena4 - 1; Alarm = 0; Delay_ms (10); do{ if (Prepni == 1){ if (Button(&PORTA, 2, 100, 0))hod1++; if (hod1 > 175)hod1 = 0; if (Button(&PORTA, 1, 100, 0))hod1--; if (hod1 == 255)hod1 = 175; hod1_zobr = hod1; if (hod1_zobr < 50){ hod1_zobr = 50 - hod1_zobr; MINUS = 0; } else { hod1_zobr = hod1_zobr - 50; MINUS = 1; } if ( hod1_zobr > 100) JEDNA = 0; else JEDNA = 1; h1[0] = (hod1_zobr/10)%10; h1[1] = hod1_zobr%10; if (cislice_zmena2 != hod1){ cislice1 = 0b11111111; cislice2 = CISLO(h1[1]); cislice3 = CISLO(h1[0]); posli (); cislice_zmena2 = hod1; } } if (Prepni == 2){ if (Button(&PORTA, 2, 100, 0))hod2++; if (hod2 > 175)hod2 = 0; if (Button(&PORTA, 1, 100, 0))hod2--; if (hod2 == 255)hod2 = 175; hod2_zobr = hod2; if (hod2_zobr < 50){ hod2_zobr = 50 - hod2_zobr; MINUS = 0; } else { hod2_zobr = hod2_zobr - 50; MINUS = 1; } if ( hod2_zobr > 100) JEDNA = 0; else JEDNA = 1; h2[0] = (hod2_zobr/10)%10; h2[1] = hod2_zobr%10; if (cislice_zmena3 != hod2){ cislice1 = 0b11111111; cislice2 = CISLO(h2[1]); cislice3 = CISLO(h2[0]); posli (); cislice_zmena3 = hod2; } } if (Prepni == 3){ if (Button(&PORTA, 2, 100, 0))Hystereze++; if (Hystereze > 30)Hystereze = 0; if (Button(&PORTA, 1, 100, 0))Hystereze--; if (Hystereze == 255)Hystereze = 30; JEDNA = 1; MINUS = 1; h3[0] = (Hystereze/10)%10; h3[1] = Hystereze%10; if (cislice_zmena4 != Hystereze){ cislice1 = 0b10001011; cislice2 = CISLO(h3[1]); cislice3 = CISLO(h3[0]); posli (); cislice_zmena4 = Hystereze; } } if (RA3_BIT == 0)Prepni++; while (RA3_BIT == 0); }while (Prepni != 4); EEPROM_Write(0x00, hod1); EEPROM_Write(0x01, hod2); EEPROM_Write(0x02, Hystereze); Prepni = 0; Alarm = 1; } void porovnej (){ bit pul; unsigned char Teplota_porov, h1, h2, minimum, maximum; pul = Teplota.F0; Teplota_porov = Teplota>>1; if (Znamenko == 0)Teplota_porov = 50 - Teplota_porov; else Teplota_porov = Teplota_porov + 50; if (hod1 == hod2){ maximum = minimum = hod1; } if (hod1 > hod2){ maximum = hod1; minimum = hod2; } if (hod1 < hod2){ maximum = hod2; minimum = hod1; } max = maximum; min = minimum; h1 = Hystereze; if(h1 > max)h1 = max; if(RELE1 == 1) max = max - h1; if (Teplota_porov >= max)RELE1 = 1; else RELE1 = 0; h2 = Hystereze; if(h2 > (175 - min))h2 = 175 - min; if(RELE2 == 1) min = min + h2; if (Teplota_porov < min)RELE2 = 1; else RELE2 = 0; Konec: asm nop; } void zmer (){ ERROR = Ow_Reset(&PORTA, 0); // reset signal Ow_Write(&PORTA, 0, 0xCC); // přeskoč ROM Ow_Write(&PORTA, 0, 0x44); // spus měření Delay_us(300); Ow_Reset(&PORTA, 0); Ow_Write(&PORTA, 0, 0xCC); // přeskoč ROM Ow_Write(&PORTA, 0, 0xBE); // čti scratchpad temp = Ow_Read(&PORTA, 0); temp = (Ow_Read(&PORTA, 0) << 8) + temp; temp = temp >> 3; } void Teplota_odesli (){ unsigned char porov; porov = temp>>5; Teplota = temp; if (porov.B6 != 0){ Teplota = 256 - Teplota; Znamenko = 0; } else Znamenko = 1; MINUS = Znamenko; if ((Teplota>>1) > 100)JEDNA = 0; else JEDNA = 1; if (Teplota.B0 == 1)cislice1 = 5; else cislice1 = 0; cislice2 = (Teplota >> 1) % 10; cislice3 = ((Teplota >> 1) / 10)%10; cislice1 = CISLO (cislice1); cislice2 = CISLO (cislice2); cislice3 = CISLO (cislice3); if (cislice_zmena1 != Teplota){ posli (); cislice_zmena1 = Teplota; } } void err(){ cislice1 = cislice2 = 0b10101111; cislice3 = 0b10000110; MINUS = 1; Prepni = 0; RELE1 = RELE2 = 0; posli(); while (RA1_BIT == 1 && RA2_BIT == 1 && RA3_BIT == 1); zmer (); Delay_ms (100); } void main() { unsigned char citac1 = 0,citac2 = 0 ; RESET: TRISB = 0; TRISA = 0b00001110; INTCON = 0; CLK = 0; CMCON = 0b000000111; cislice1 = 0b11111111; cislice2 = 0b10100111; cislice3 = 0b10101011; JEDNA = 0; MINUS = 1; posli(); zmer(); RELE1 = RELE2 = 0; hod1 = EEPROM_Read(0x00); hod2 = EEPROM_Read(0x01); Hystereze = EEPROM_Read(0x02); stav_zaloha = EEPROM_Read(0x03); if(stav_zaloha == 1)Alarm = 1; else Alarm = 0; LED = 0; Delay_ms(1000); zmer(); cislice_zmena1 = Teplota-1+3; Teplota_odesli (); LED = 1; JEDNA = 1; Prepni = 0; // Hlavní smyčka do { if (Alarm == 1){ if(RELE2 == 0){ if(RELE1 == 0) LED = 0; if (RELE1 == 1){ citac2++; if(citac2 == 4){ if(Invert == 0)Invert=1; else Invert=0; LED = Invert; citac2 = 0; } } } if (RELE2 == 1){ if(RELE1 == 0){ citac1++; if(citac1 == 8){ if(Invert == 0)Invert=1; else Invert=0; LED = Invert; citac1 = 0; } } if (RELE1 == 1){ if(Invert == 0)Invert=1; else Invert=0; LED = Invert; } } } else LED = 1; if (Prepni == 0){ zmer (); Teplota_odesli(); } Tlacitka (); if (Prepni > 0)Termostat (); if (Alarm == 1)porovnej(); else RELE1 = RELE2 = 0; if (ERROR == 1) err(); Delay_ms (20); }while (1); }