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