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