239 |
kaklik |
1 |
#include ".\main.h" |
223 |
kapl |
2 |
|
239 |
kaklik |
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 |
#define zar1 PIN_A3 |
223 |
kapl |
7 |
|
239 |
kaklik |
8 |
#bit SPEN=0x18.7 |
|
|
9 |
#bit RCIF=0x0C.5 |
223 |
kapl |
10 |
|
239 |
kaklik |
11 |
#include "mylcd.c" |
|
|
12 |
|
|
|
13 |
void main() |
|
|
14 |
{ |
|
|
15 |
char odp[40]; |
|
|
16 |
int pom,pom2,pom3,odkl,odkl2,maskovadlo,status; |
|
|
17 |
|
|
|
18 |
setup_adc_ports(NO_ANALOGS); |
|
|
19 |
setup_adc(ADC_OFF); |
|
|
20 |
setup_spi(SPI_SS_DISABLED); |
|
|
21 |
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1); |
|
|
22 |
setup_timer_1(T1_DISABLED); |
|
|
23 |
setup_timer_2(T2_DISABLED,0,1); |
|
|
24 |
setup_comparator(NC_NC_NC_NC); |
|
|
25 |
setup_vref(FALSE); |
|
|
26 |
setup_wdt(WDT_2304MS); |
|
|
27 |
lcd_init(); |
|
|
28 |
|
|
|
29 |
/* |
|
|
30 |
delay_us(10); |
|
|
31 |
lcd_gotoxy(1,1); |
|
|
32 |
printf(lcd_putc," Ovladani mobilem"); |
|
|
33 |
lcd_gotoxy(1,2); |
|
|
34 |
printf(lcd_putc,""); |
|
|
35 |
lcd_gotoxy(1,3); |
|
|
36 |
printf(lcd_putc," autor: Tomas Kapl"); |
|
|
37 |
lcd_gotoxy(1,4); |
|
|
38 |
printf(lcd_putc," www.kapl.cz"); |
|
|
39 |
delay_ms(5000); |
|
|
40 |
*/ |
|
|
41 |
|
|
|
42 |
while(TRUE) |
|
|
43 |
{ |
|
|
44 |
restart_wdt(); |
|
|
45 |
|
|
|
46 |
output_low(PIN_A4) ; |
|
|
47 |
delay_ms(150); |
|
|
48 |
output_high(PIN_A4); |
|
|
49 |
delay_ms(150); |
|
|
50 |
output_low(PIN_A4) ; |
|
|
51 |
delay_ms(150); |
|
|
52 |
output_high(PIN_A4); |
|
|
53 |
delay_ms(150); |
|
|
54 |
|
|
|
55 |
/* |
|
|
56 |
while(kbhit(MOBIL)) {fgetc(MOBIL); delay_ms(100);} // Preskoc zbytek radku |
|
|
57 |
fprintf(MOBIL,"AT\r"); //vycti prijate SMS |
|
|
58 |
while(fgetc(MOBIL)!=0x0A); // predkoc prvni radek odpovedi |
|
|
59 |
|
|
|
60 |
delay_ms(500); |
|
|
61 |
for(pom=0;pom<80;pom++) odp[pom]=0; |
|
|
62 |
fprintf(MOBIL,"AT\r"); //vycti prijate SMS |
|
|
63 |
odp[0]=fgetc(MOBIL); |
|
|
64 |
odp[1]=fgetc(MOBIL); |
|
|
65 |
odp[2]=fgetc(MOBIL); |
|
|
66 |
|
|
|
67 |
fprintf(VRTULE,"*%s*\n\r",odp); |
|
|
68 |
fgetc(MOBIL); |
|
|
69 |
output_low(PIN_A4); |
|
|
70 |
fgetc(MOBIL); |
|
|
71 |
fgetc(MOBIL); |
|
|
72 |
|
|
|
73 |
delay_ms(1000); |
|
|
74 |
continue; |
|
|
75 |
*/ |
|
|
76 |
fprintf(MOBIL,"AT+CMGL=1\r"); //vycti prijate SMS (0=nove;1=vsechny) |
|
|
77 |
//SPEN=1; |
|
|
78 |
|
|
|
79 |
|
|
|
80 |
while(fgetc(MOBIL)!=0x0A); // predkoc prvni radek odpovedi |
|
|
81 |
|
|
|
82 |
odp[0]=fgetc(MOBIL); // Nacti prvni dva znaky druheho radku odpovedi |
|
|
83 |
odp[1]=fgetc(MOBIL); |
|
|
84 |
while(fgetc(MOBIL)!=0x0A); // Preskoc zbytek radku |
|
|
85 |
|
|
|
86 |
// while(kbhit(MOBIL)) {fgetc(MOBIL); delay_ms(100);} // Preskoc zbytek radku |
|
|
87 |
output_high(PIN_A4); |
|
|
88 |
|
|
|
89 |
|
|
|
90 |
if(odp[0] == 79 && odp[1] ==75) // Je odpoved "OK"? |
|
|
91 |
{ |
|
|
92 |
lcd_gotoxy(1,1); |
|
|
93 |
printf(lcd_putc,"\fNeni nova SMS zprava"); |
|
|
94 |
lcd_gotoxy(1,2); |
|
|
95 |
printf(lcd_putc,""); |
|
|
96 |
lcd_gotoxy(1,3); |
|
|
97 |
printf(lcd_putc,"Zaslete SMS na cislo"); |
|
|
98 |
lcd_gotoxy(1,4); |
|
|
99 |
printf(lcd_putc," 736 655 250"); |
|
|
100 |
delay_ms(5000); |
|
|
101 |
} |
|
|
102 |
else |
|
|
103 |
{ |
|
|
104 |
//!!!KAKL for(pom=0;pom<55;pom++) //preskoc nedulezite informace |
|
|
105 |
for(pom=0;pom<54;pom++) //preskoc nedulezite informace |
|
|
106 |
{ |
|
|
107 |
fgetc(MOBIL); |
|
|
108 |
} |
|
|
109 |
|
|
|
110 |
//gets(odp); //uloz zakodovany text SMS |
|
|
111 |
|
|
|
112 |
odp[0]=fgetc(MOBIL); |
|
|
113 |
odp[1]=fgetc(MOBIL); |
|
|
114 |
odp[2]=fgetc(MOBIL); |
|
|
115 |
odp[3]=fgetc(MOBIL); |
|
|
116 |
odp[4]=fgetc(MOBIL); |
|
|
117 |
odp[5]=fgetc(MOBIL); |
|
|
118 |
odp[6]=fgetc(MOBIL); |
|
|
119 |
odp[7]=fgetc(MOBIL); |
|
|
120 |
|
|
|
121 |
/*lcd_gotoxy(1,1); |
|
|
122 |
printf(lcd_putc,"\f%s\n",odp);*/ |
|
|
123 |
|
|
|
124 |
if(odp[0]==0) odp[1]='0'; // Prevod z ASCII do BIN |
|
|
125 |
odp[0]=odp[0] - '0'; |
|
|
126 |
odp[1]=odp[1] - '0'; |
|
|
127 |
if(odp[0]>9) odp[0]=odp[0]-7; |
|
|
128 |
if(odp[1]>9) odp[1]=odp[1]-7; |
|
|
129 |
odp[0]=odp[0] << 4; |
|
|
130 |
odp[0] |= odp[1]; |
|
|
131 |
|
|
|
132 |
if(odp[2]==0) odp[3]='0'; |
|
|
133 |
odp[2]=odp[2] - '0'; |
|
|
134 |
odp[3]=odp[3] - '0'; |
|
|
135 |
if(odp[2]>9) odp[2]=odp[2]-7; |
|
|
136 |
if(odp[3]>9) odp[3]=odp[3]-7; |
|
|
137 |
odp[2]=odp[2] << 4; |
|
|
138 |
odp[2] |= odp[3]; |
|
|
139 |
|
|
|
140 |
if(odp[4]==0) odp[5]='0'; |
|
|
141 |
odp[4]=odp[4] - '0'; |
|
|
142 |
odp[5]=odp[5] - '0'; |
|
|
143 |
if(odp[4]>9) odp[4]=odp[4]-7; |
|
|
144 |
if(odp[5]>9) odp[5]=odp[5]-7; |
|
|
145 |
odp[4]=odp[4] << 4; |
|
|
146 |
odp[4] |= odp[5]; |
|
|
147 |
|
|
|
148 |
if(odp[6]==0) odp[7]='0'; |
|
|
149 |
odp[6]=odp[6] - '0'; |
|
|
150 |
odp[7]=odp[7] - '0'; |
|
|
151 |
if(odp[6]>9) odp[6]=odp[6]-7; |
|
|
152 |
if(odp[7]>9) odp[7]=odp[7]-7; |
|
|
153 |
odp[6]=odp[6] << 4; |
|
|
154 |
odp[6] |= odp[7]; |
|
|
155 |
|
|
|
156 |
odp[1]=odp[2]; |
|
|
157 |
odp[2]=odp[4]; |
|
|
158 |
odp[3]=odp[6]; |
|
|
159 |
odp[4]=odp[5]=odp[6]=0; |
|
|
160 |
|
|
|
161 |
/*lcd_gotoxy(1,2); |
|
|
162 |
printf(lcd_putc,"%u %u %u %u",odp[0],odp[1],odp[2]odp[3]); */ |
|
|
163 |
|
|
|
164 |
pom3=0; |
|
|
165 |
for (pom = 0; pom < 4;pom++) |
|
|
166 |
{ |
|
|
167 |
maskovadlo = maskovadlo >> 1; //rotace promene urcene pro maskovani |
|
|
168 |
maskovadlo = maskovadlo | 0x80; |
|
|
169 |
odkl = odp[pom] & maskovadlo; //odlozeni "prenosu" do odkl pomoci maskovadla |
|
|
170 |
odp[pom] = odp[pom] << pom3; //rotace znaku |
|
|
171 |
for (pom2 = 0; pom2 < (8-pom3);pom2++) //rotace odkl2 |
|
|
172 |
{ |
|
|
173 |
odkl2 = odkl2 >> 1; |
|
|
174 |
odkl2 = odkl2 & 127; |
|
|
175 |
} |
|
|
176 |
odp[pom] = odp[pom] | odkl2; //pridani odkl2 ke znaku |
|
|
177 |
odp[pom] = odp[pom] & 127; //smazani nejvysiho bitu |
|
|
178 |
odkl2 = odkl; //ulozeni odlk na dalsi pruchod |
|
|
179 |
pom3++; //inkrementace citace rotace |
|
|
180 |
if (pom3 == 8) //kazdy 8my znak |
|
|
181 |
{ |
|
|
182 |
pom3 = 0; //smaz citac |
|
|
183 |
odp[pom+1] = odkl2; //uloz 8my znak vznikly z "prenosu" |
|
|
184 |
maskovadlo = 0; //smaz maskovadlo |
|
|
185 |
} |
|
|
186 |
} |
|
|
187 |
odp[pom]='\0'; |
|
|
188 |
|
|
|
189 |
/*lcd_gotoxy(1,3); |
|
|
190 |
printf(lcd_putc,"%u %u %u %u",odp[0],odp[1],odp[2],odp[3]); */ |
|
|
191 |
lcd_init(); |
|
|
192 |
lcd_gotoxy(1,1); |
|
|
193 |
printf(lcd_putc,"\fPrijata SMS s textem"); |
|
|
194 |
lcd_gotoxy(9,3); |
|
|
195 |
printf(lcd_putc,"%s",odp); |
|
|
196 |
output_low(PIN_A4) ; |
|
|
197 |
delay_ms(1000); |
|
|
198 |
output_high(PIN_A4); |
|
|
199 |
|
|
|
200 |
//!!! fprintf(MOBIL,"AT+CMGD=1\r"); //smaz prijatou SMSku |
|
|
201 |
|
|
|
202 |
if (odp[0] > 64 && odp[0] < 91 ) |
|
|
203 |
{ |
|
|
204 |
odp[0] += 32; |
|
|
205 |
} |
|
|
206 |
|
|
|
207 |
if (odp[1] > 64 && odp[1] < 91 ) |
|
|
208 |
{ |
|
|
209 |
odp[1] += 32; |
|
|
210 |
} |
|
|
211 |
|
|
|
212 |
if (odp[2] > 64 && odp[2] < 91 ) |
|
|
213 |
{ |
|
|
214 |
odp[2] += 32; |
|
|
215 |
} |
|
|
216 |
|
|
|
217 |
if (odp[3] > 64 && odp[3] < 91 ) |
|
|
218 |
{ |
|
|
219 |
odp[3] += 32; |
|
|
220 |
} |
|
|
221 |
|
|
|
222 |
lcd_gotoxy(1,1); |
|
|
223 |
printf(lcd_putc,"\f Odstraneni velkych"); |
|
|
224 |
lcd_gotoxy(1,2); |
|
|
225 |
printf(lcd_putc," pismen"); |
|
|
226 |
lcd_gotoxy(9,4); |
|
|
227 |
printf(lcd_putc,"%s",odp); |
|
|
228 |
output_low(PIN_A4) ; |
|
|
229 |
delay_ms(1000); |
|
|
230 |
output_high(PIN_A4); |
|
|
231 |
|
|
|
232 |
|
|
|
233 |
//!!!KAKL |
|
|
234 |
fprintf(VRTULE,"%s",odp); |
|
|
235 |
|
|
|
236 |
|
|
|
237 |
if (odp[0] == 122 && odp[1] == 97 && odp[2] == 112 && odp[3] == 49) //odp=="zap1" |
|
|
238 |
{ |
|
|
239 |
status=1; |
|
|
240 |
} |
|
|
241 |
|
|
|
242 |
if (odp[0] == 118 && odp[1] == 121 && odp[2] == 112 && odp[3]== 49) //odp=="vyp1" |
|
|
243 |
{ |
|
|
244 |
status=2; |
|
|
245 |
} |
|
|
246 |
|
|
|
247 |
if (odp[0] == 97 && odp[1] == 104 && odp[2] == 111 && odp[3]== 106) //odp=="ahoj" |
|
|
248 |
{ |
|
|
249 |
status=3; |
|
|
250 |
} |
|
|
251 |
|
|
|
252 |
switch (status) |
|
|
253 |
{ |
|
|
254 |
|
|
|
255 |
case 1: output_low(zar1); |
|
|
256 |
printf(lcd_putc,"\f"); |
|
|
257 |
lcd_gotoxy(1,2); |
|
|
258 |
printf(lcd_putc," Zapnuto zarizeni 1"); |
|
|
259 |
break; |
|
|
260 |
|
|
|
261 |
case 2: output_high(zar1); |
|
|
262 |
printf(lcd_putc,"\f"); |
|
|
263 |
lcd_gotoxy(1,2); |
|
|
264 |
printf(lcd_putc," Vypnuto zarizeni 1"); |
|
|
265 |
break; |
|
|
266 |
|
|
|
267 |
case 3: printf(lcd_putc,"\f"); |
|
|
268 |
lcd_gotoxy(1,2); |
|
|
269 |
printf(lcd_putc," Preji hezky den!"); |
|
|
270 |
break; |
|
|
271 |
|
|
|
272 |
default: printf(lcd_putc,"\f"); |
|
|
273 |
lcd_gotoxy(1,2); |
|
|
274 |
printf(lcd_putc," Prikaz nebyl"); |
|
|
275 |
lcd_gotoxy(1,3); |
|
|
276 |
printf(lcd_putc," rozeznan"); |
|
|
277 |
break; |
|
|
278 |
} |
|
|
279 |
delay_ms(1000); |
|
|
280 |
} |
|
|
281 |
|
|
|
282 |
} |
|
|
283 |
} |