Rev Author Line No. Line
1861 kaklik 1 #include "reflow.h"
2 #include <math.h>
3  
4 // nastaveni teplot a casu
5 #define TEPLOTA_PREDEHREVU 120
6 #define DOBA_PREDEHREVU 60
7  
8 #define TEPLOTA_VRCHOLU 210
9 #define DOBA_VRCHOLU 5
10  
11 // CPU IO rozhrani
12 #define LCD_RS PIN_C1 // rizeni registru LCD displeje
13 #define LCD_E PIN_C2 // enable LCD displeje
14 #define LCD_DATA_LSB PIN_D0 // data LCD
15 #include "lcd.c"
16  
17 #define TL1 PIN_B3 // tlacitko S1
18 #define TL2 PIN_B2 // tlacitko S2
19 #define TL3 PIN_B1 // tlacitko S3
20 #define TL4 PIN_B0 // tlacitko S4
21  
1957 kaklik 22 #define POWER_T3 PIN_A6 // ovladani optotriaku T3
1861 kaklik 23 #define POWER_T4 PIN_A5 // ovladani optotriaku T4
24 #define POWER_T5 PIN_A4 // ovladani optotriaku T5
25  
26 #define ADC_PIN PIN_A0 //info, nelze menit - pin pouzit jako input analog
27 #define ADC_PIN_NC PIN_A1 //info, nelze menit - pin pouzit jako input analog
28 #define REF_PIN PIN_A3 //info, nelze menit - pin pouzit jako input reference 2.5V
29  
30 // interni
31 #define PowerOn() output_low(POWER_T4);output_low(POWER_T5)
32 #define PowerOff() output_high(POWER_T4);output_high(POWER_T5)
33  
34 // globalni promenne
35 struct time
36 {
37 volatile unsigned int8 hod;
38 volatile unsigned int8 min;
39 volatile unsigned int8 sec;
40 }cas;
41  
42 // funkce
43 void GeneralCpuInit()
44 {
45 output_high(POWER_T4);
46 output_high(POWER_T5);
47 port_b_pullups(true);
48  
49 setup_psp(PSP_DISABLED);
50 setup_spi(SPI_SS_DISABLED);
51  
52 setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1); //nepouzit
53 setup_timer_1(T1_DISABLED); //nepouzit
54 setup_timer_2(T2_DIV_BY_16,249,10); //rtc 40ms
55  
56 setup_comparator(NC_NC_NC_NC);
57 setup_vref(FALSE);
58  
59 enable_interrupts(GLOBAL);
60 enable_interrupts(INT_TIMER2);
61  
62 setup_adc_ports(AN0_AN1_VSS_VREF); //A0 vstup cidla, A1 nepozit, A3 - ref. 2.5V
63 setup_adc(ADC_CLOCK_DIV_8);
64 SET_ADC_CHANNEL(0); //AN0, PIN_A0
65 }
66  
67 unsigned int16 adc(void)
68 {
69 unsigned int16 analog;
70 unsigned int8 a;
71  
72 analog = 0;
73 for (a=0;a<32;a++)
74 {
75 analog += read_adc();
76 delay_us(50);
77 }
78 return (analog >> 5 ); // prumer = analog/32
79 }
80  
1957 kaklik 81 float teplota(void)
1861 kaklik 82 {
1957 kaklik 83 return (0.674201*adc() - 294.35);
1861 kaklik 84 }
85  
1942 kaklik 86  
1861 kaklik 87 #int_TIMER2
88 void Rtc(void) //40ms
89 {
90 static unsigned int8 ms40=0;
91 struct time* time;
92  
93 time=&cas;
94 if ( ++ms40 < 25) return;
95  
96 ms40=0;
97 if (++(time->sec) >= 60)
98 {
99 time->sec=0; //1min
100 if (++(time->min) >= 60)
101 {
102 time->min = 0; //1hod
103 (time->hod)++;
104 }
105 }
106 }
107  
108 void nullcas(struct time* time)
109 {
110 disable_interrupts(INT_TIMER2);
111  
112 time->sec=0;
113 time->hod=0;
114 time->min=0;
115  
116 enable_interrupts(INT_TIMER2);
117 }
118  
119 // start
120 void main()
121 {
122 int8 tmp;
123 GeneralCpuInit();
124 PowerOff();
125  
126 lcd_init();
127 lcd_define_char(1,LCD_CHAR_STUPEN);
1942 kaklik 128  
1861 kaklik 129 nullcas(&cas);
130  
1942 kaklik 131 while(true)
132 {
1861 kaklik 133 delay_ms(300);
134  
135 if (cas.sec != tmp){
136 tmp=cas.sec;
137 lcd_gotoxy(9,1);
138 printf(lcd_putc,"%2u:%02u:%02u",cas.hod,cas.min,cas.sec);
139 }
140  
141 lcd_gotoxy(1,2);
1957 kaklik 142 printf(lcd_putc,"teplota: %3.1f\21C ",teplota());
1942 kaklik 143 }
1861 kaklik 144 }