223 |
kapl |
1 |
#include ".\main.h" |
|
|
2 |
|
|
|
3 |
#define LCD_RS PIN_B1 // rizeni registru LCD displeje |
|
|
4 |
#define LCD_E PIN_B0 // enable LCD displeje |
|
|
5 |
#define LCD_DATA_LSB PIN_C0 // pripojeni LSB bitu datoveho portu LCD displeje (celkem 4 bity vzestupne za sebou) |
|
|
6 |
|
240 |
kaklik |
7 |
|
238 |
kaklik |
8 |
#bit SPEN=0x18.7 |
|
|
9 |
#bit RCIF=0x0C.5 |
|
|
10 |
|
240 |
kaklik |
11 |
#include <stdio.h> |
|
|
12 |
#include <string.h> |
|
|
13 |
#include <stdlib.h> |
223 |
kapl |
14 |
|
240 |
kaklik |
15 |
#define DELKA 40 |
223 |
kapl |
16 |
|
240 |
kaklik |
17 |
char odp[DELKA]; |
239 |
kaklik |
18 |
|
240 |
kaklik |
19 |
int1 check_new_sms() |
|
|
20 |
{ |
239 |
kaklik |
21 |
fprintf(MOBIL,"AT+CMGL=1\r"); //vycti prijate SMS (0=nove;1=vsechny) |
238 |
kaklik |
22 |
while(fgetc(MOBIL)!=0x0A); // predkoc prvni radek odpovedi |
|
|
23 |
odp[0]=fgetc(MOBIL); // Nacti prvni dva znaky druheho radku odpovedi |
|
|
24 |
odp[1]=fgetc(MOBIL); |
|
|
25 |
while(fgetc(MOBIL)!=0x0A); // Preskoc zbytek radku |
|
|
26 |
|
240 |
kaklik |
27 |
if(odp[0] == 'O' && odp[1] == 'K') return 1; |
|
|
28 |
else return 0; |
|
|
29 |
} |
238 |
kaklik |
30 |
|
240 |
kaklik |
31 |
read_sms() |
|
|
32 |
{ |
|
|
33 |
int pom,pom2,pom3,odkl,odkl2,maskovadlo; |
238 |
kaklik |
34 |
for(pom=0;pom<54;pom++) //preskoc nedulezite informace |
223 |
kapl |
35 |
{ |
238 |
kaklik |
36 |
fgetc(MOBIL); |
239 |
kaklik |
37 |
} |
|
|
38 |
|
223 |
kapl |
39 |
//gets(odp); //uloz zakodovany text SMS |
239 |
kaklik |
40 |
|
238 |
kaklik |
41 |
odp[0]=fgetc(MOBIL); |
|
|
42 |
odp[1]=fgetc(MOBIL); |
|
|
43 |
odp[2]=fgetc(MOBIL); |
|
|
44 |
odp[3]=fgetc(MOBIL); |
|
|
45 |
odp[4]=fgetc(MOBIL); |
|
|
46 |
odp[5]=fgetc(MOBIL); |
|
|
47 |
odp[6]=fgetc(MOBIL); |
|
|
48 |
odp[7]=fgetc(MOBIL); |
|
|
49 |
|
223 |
kapl |
50 |
/*lcd_gotoxy(1,1); |
|
|
51 |
printf(lcd_putc,"\f%s\n",odp);*/ |
239 |
kaklik |
52 |
|
|
|
53 |
if(odp[0]==0) odp[1]='0'; // Prevod z ASCII do BIN |
223 |
kapl |
54 |
odp[0]=odp[0] - '0'; |
|
|
55 |
odp[1]=odp[1] - '0'; |
|
|
56 |
if(odp[0]>9) odp[0]=odp[0]-7; |
|
|
57 |
if(odp[1]>9) odp[1]=odp[1]-7; |
|
|
58 |
odp[0]=odp[0] << 4; |
|
|
59 |
odp[0] |= odp[1]; |
239 |
kaklik |
60 |
|
223 |
kapl |
61 |
if(odp[2]==0) odp[3]='0'; |
|
|
62 |
odp[2]=odp[2] - '0'; |
|
|
63 |
odp[3]=odp[3] - '0'; |
|
|
64 |
if(odp[2]>9) odp[2]=odp[2]-7; |
|
|
65 |
if(odp[3]>9) odp[3]=odp[3]-7; |
|
|
66 |
odp[2]=odp[2] << 4; |
|
|
67 |
odp[2] |= odp[3]; |
239 |
kaklik |
68 |
|
223 |
kapl |
69 |
if(odp[4]==0) odp[5]='0'; |
|
|
70 |
odp[4]=odp[4] - '0'; |
|
|
71 |
odp[5]=odp[5] - '0'; |
|
|
72 |
if(odp[4]>9) odp[4]=odp[4]-7; |
|
|
73 |
if(odp[5]>9) odp[5]=odp[5]-7; |
|
|
74 |
odp[4]=odp[4] << 4; |
|
|
75 |
odp[4] |= odp[5]; |
239 |
kaklik |
76 |
|
223 |
kapl |
77 |
if(odp[6]==0) odp[7]='0'; |
|
|
78 |
odp[6]=odp[6] - '0'; |
|
|
79 |
odp[7]=odp[7] - '0'; |
|
|
80 |
if(odp[6]>9) odp[6]=odp[6]-7; |
|
|
81 |
if(odp[7]>9) odp[7]=odp[7]-7; |
|
|
82 |
odp[6]=odp[6] << 4; |
|
|
83 |
odp[6] |= odp[7]; |
|
|
84 |
|
|
|
85 |
odp[1]=odp[2]; |
|
|
86 |
odp[2]=odp[4]; |
|
|
87 |
odp[3]=odp[6]; |
239 |
kaklik |
88 |
odp[4]=odp[5]=odp[6]=0; |
|
|
89 |
|
|
|
90 |
/*lcd_gotoxy(1,2); |
223 |
kapl |
91 |
printf(lcd_putc,"%u %u %u %u",odp[0],odp[1],odp[2]odp[3]); */ |
239 |
kaklik |
92 |
|
223 |
kapl |
93 |
pom3=0; |
239 |
kaklik |
94 |
for (pom = 0; pom < 4;pom++) |
223 |
kapl |
95 |
{ |
|
|
96 |
maskovadlo = maskovadlo >> 1; //rotace promene urcene pro maskovani |
|
|
97 |
maskovadlo = maskovadlo | 0x80; |
|
|
98 |
odkl = odp[pom] & maskovadlo; //odlozeni "prenosu" do odkl pomoci maskovadla |
|
|
99 |
odp[pom] = odp[pom] << pom3; //rotace znaku |
|
|
100 |
for (pom2 = 0; pom2 < (8-pom3);pom2++) //rotace odkl2 |
|
|
101 |
{ |
|
|
102 |
odkl2 = odkl2 >> 1; |
239 |
kaklik |
103 |
odkl2 = odkl2 & 127; |
223 |
kapl |
104 |
} |
|
|
105 |
odp[pom] = odp[pom] | odkl2; //pridani odkl2 ke znaku |
|
|
106 |
odp[pom] = odp[pom] & 127; //smazani nejvysiho bitu |
|
|
107 |
odkl2 = odkl; //ulozeni odlk na dalsi pruchod |
|
|
108 |
pom3++; //inkrementace citace rotace |
|
|
109 |
if (pom3 == 8) //kazdy 8my znak |
|
|
110 |
{ |
|
|
111 |
pom3 = 0; //smaz citac |
|
|
112 |
odp[pom+1] = odkl2; //uloz 8my znak vznikly z "prenosu" |
|
|
113 |
maskovadlo = 0; //smaz maskovadlo |
|
|
114 |
} |
|
|
115 |
} |
239 |
kaklik |
116 |
odp[pom]='\0'; |
240 |
kaklik |
117 |
} |
239 |
kaklik |
118 |
|
240 |
kaklik |
119 |
void read_time() |
|
|
120 |
{ |
|
|
121 |
unsigned int8 n; |
238 |
kaklik |
122 |
|
239 |
kaklik |
123 |
|
240 |
kaklik |
124 |
fprintf(MOBIL,"AT+CCLK?\r"); |
|
|
125 |
while(fgetc(MOBIL)!='"'); |
|
|
126 |
for(n=0;n<12;n++) //preskoc nedulezite informace |
|
|
127 |
{ |
|
|
128 |
fgetc(MOBIL); |
|
|
129 |
} |
|
|
130 |
odp[0]=fgetc(MOBIL); |
|
|
131 |
odp[1]=fgetc(MOBIL); |
|
|
132 |
odp[2]=0; |
|
|
133 |
} |
239 |
kaklik |
134 |
|
240 |
kaklik |
135 |
void del_sms() |
|
|
136 |
{ |
|
|
137 |
fprintf(MOBIL,"AT+CMGD=1\r"); //smaz prijatou SMSku |
|
|
138 |
} |
239 |
kaklik |
139 |
|
240 |
kaklik |
140 |
void main() |
|
|
141 |
{ |
|
|
142 |
setup_adc_ports(NO_ANALOGS); |
|
|
143 |
setup_adc(ADC_OFF); |
|
|
144 |
setup_spi(SPI_SS_DISABLED); |
|
|
145 |
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1); |
|
|
146 |
setup_timer_1(T1_DISABLED); |
|
|
147 |
setup_timer_2(T2_DIV_BY_4,255,1); |
|
|
148 |
setup_ccp1(CCP_PWM); |
|
|
149 |
setup_ccp2(CCP_PWM); |
|
|
150 |
setup_comparator(NC_NC_NC_NC); |
|
|
151 |
setup_vref(FALSE); |
|
|
152 |
setup_wdt(WDT_2304MS); |
239 |
kaklik |
153 |
|
240 |
kaklik |
154 |
set_pwm1_duty(0); |
|
|
155 |
set_pwm2_duty(0); |
239 |
kaklik |
156 |
|
240 |
kaklik |
157 |
while(TRUE) |
|
|
158 |
{ |
|
|
159 |
int status; |
|
|
160 |
char *ptr; |
|
|
161 |
int time; |
238 |
kaklik |
162 |
|
240 |
kaklik |
163 |
restart_wdt(); |
239 |
kaklik |
164 |
|
240 |
kaklik |
165 |
output_low(PIN_A4) ; |
|
|
166 |
delay_ms(150); |
|
|
167 |
output_high(PIN_A4); |
|
|
168 |
delay_ms(150); |
|
|
169 |
output_low(PIN_A4) ; |
|
|
170 |
delay_ms(150); |
|
|
171 |
output_high(PIN_A4); |
|
|
172 |
delay_ms(150); |
238 |
kaklik |
173 |
|
|
|
174 |
|
245 |
kaklik |
175 |
if(check_new_sms()) // Je odpoved "OK"? |
240 |
kaklik |
176 |
{ |
|
|
177 |
// printf(lcd_putc,"736 655 250"); |
|
|
178 |
delay_ms(1000); |
|
|
179 |
} |
|
|
180 |
else |
|
|
181 |
{ |
|
|
182 |
read_sms(); |
|
|
183 |
|
245 |
kaklik |
184 |
/* if (odp[0] == 'A' || odp[0] == 'a') |
240 |
kaklik |
185 |
{ |
|
|
186 |
set_pwm1_duty(500); |
|
|
187 |
set_pwm2_duty(500); |
245 |
kaklik |
188 |
Delay_ms(10000); |
|
|
189 |
fprintf(VRTULE,"JACK[BARmk"); // "JACK BAR :)" |
|
|
190 |
Delay_ms(2000); |
|
|
191 |
fprintf(VRTULE,"JACK[BARmk"); // "JACK BAR :)" |
240 |
kaklik |
192 |
Delay_ms(5000); |
|
|
193 |
set_pwm1_duty(0); |
|
|
194 |
set_pwm2_duty(0); |
245 |
kaklik |
195 |
}*/ |
240 |
kaklik |
196 |
|
245 |
kaklik |
197 |
/* if (odp[1] == 'h') |
|
|
198 |
{ |
|
|
199 |
set_pwm1_duty(500); |
|
|
200 |
set_pwm2_duty(500); |
|
|
201 |
Delay_ms(10000); |
|
|
202 |
fprintf(VRTULE,"[ERROR[d[["); // " ERROR 3 " |
|
|
203 |
Delay_ms(2000); |
|
|
204 |
fprintf(VRTULE,"[ERROR[d[["); // " ERROR 3 " |
|
|
205 |
Delay_ms(2000); |
|
|
206 |
fprintf(VRTULE,"[OVERFLOW["); // " OVERFLOW " |
|
|
207 |
Delay_ms(2000); |
|
|
208 |
fprintf(VRTULE,"[OVERFLOW["); |
|
|
209 |
Delay_ms(5000); |
|
|
210 |
set_pwm1_duty(0); |
|
|
211 |
set_pwm2_duty(0); |
|
|
212 |
}*/ |
239 |
kaklik |
213 |
|
245 |
kaklik |
214 |
if (odp[2] == 'o') |
|
|
215 |
{ |
|
|
216 |
set_pwm1_duty(500); |
|
|
217 |
set_pwm2_duty(500); |
|
|
218 |
Delay_ms(10000); |
|
|
219 |
fprintf(VRTULE,"[ERROR[e[["); // " ERROR 4 " |
|
|
220 |
Delay_ms(2000); |
|
|
221 |
fprintf(VRTULE,"[ERROR[e[["); // " ERROR 4 " |
|
|
222 |
Delay_ms(2000); |
|
|
223 |
fprintf(VRTULE,"[OPAKUJTE["); // " OPAKUJTE " |
|
|
224 |
Delay_ms(2000); |
|
|
225 |
fprintf(VRTULE,"[OPAKUJTE["); |
|
|
226 |
Delay_ms(2000); |
|
|
227 |
fprintf(VRTULE,"[[VOLBU[[["); // " VOLBU " |
|
|
228 |
Delay_ms(2000); |
|
|
229 |
fprintf(VRTULE,"[[VOLBU[[["); |
|
|
230 |
Delay_ms(3000); |
|
|
231 |
set_pwm1_duty(0); |
|
|
232 |
set_pwm2_duty(0); |
|
|
233 |
} |
240 |
kaklik |
234 |
} |
245 |
kaklik |
235 |
read_time(); |
240 |
kaklik |
236 |
time=strtoul(odp,&ptr,10); |
|
|
237 |
if((time >= 30 && time <= 35) || (time >= 0 && time <= 5)) |
238 |
kaklik |
238 |
{ |
240 |
kaklik |
239 |
set_pwm1_duty(500); |
|
|
240 |
set_pwm2_duty(500); |
|
|
241 |
} |
|
|
242 |
else |
|
|
243 |
{ |
|
|
244 |
set_pwm1_duty(0); |
|
|
245 |
set_pwm2_duty(0); |
245 |
kaklik |
246 |
} |
223 |
kapl |
247 |
|
238 |
kaklik |
248 |
delay_ms(1000); |
223 |
kapl |
249 |
} |
|
|
250 |
} |