Line 1... |
Line 1... |
1 |
#include ".\main.h" |
1 |
#include ".\main.h" |
2 |
|
2 |
|
3 |
#define LCD_RS PIN_B1 // rizeni registru LCD displeje |
3 |
#define LCD_RS PIN_B1 // rizeni registru LCD displeje |
4 |
#define LCD_E PIN_B0 // enable 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) |
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 |
- |
|
- |
|
6 |
|
7 |
|
7 |
|
8 |
#bit SPEN=0x18.7 |
8 |
#bit SPEN=0x18.7 |
9 |
#bit RCIF=0x0C.5 |
9 |
#bit RCIF=0x0C.5 |
10 |
|
10 |
|
11 |
#include "mylcd.c" |
11 |
#include <stdio.h> |
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); |
12 |
#include <string.h> |
36 |
printf(lcd_putc," autor: Tomas Kapl"); |
- |
|
37 |
lcd_gotoxy(1,4); |
13 |
#include <stdlib.h> |
38 |
printf(lcd_putc," www.kapl.cz"); |
- |
|
39 |
delay_ms(5000); |
- |
|
40 |
*/ |
- |
|
41 |
|
14 |
|
42 |
while(TRUE) |
15 |
#define DELKA 40 |
43 |
{ |
- |
|
44 |
restart_wdt(); |
- |
|
45 |
|
16 |
|
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); |
17 |
char odp[DELKA]; |
52 |
output_high(PIN_A4); |
- |
|
53 |
delay_ms(150); |
- |
|
54 |
|
18 |
|
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); |
19 |
int1 check_new_sms() |
70 |
fgetc(MOBIL); |
- |
|
71 |
fgetc(MOBIL); |
- |
|
72 |
|
20 |
{ |
73 |
delay_ms(1000); |
- |
|
74 |
continue; |
- |
|
75 |
*/ |
- |
|
76 |
fprintf(MOBIL,"AT+CMGL=1\r"); //vycti prijate SMS (0=nove;1=vsechny) |
21 |
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 |
22 |
while(fgetc(MOBIL)!=0x0A); // predkoc prvni radek odpovedi |
81 |
|
- |
|
82 |
odp[0]=fgetc(MOBIL); // Nacti prvni dva znaky druheho radku odpovedi |
23 |
odp[0]=fgetc(MOBIL); // Nacti prvni dva znaky druheho radku odpovedi |
83 |
odp[1]=fgetc(MOBIL); |
24 |
odp[1]=fgetc(MOBIL); |
84 |
while(fgetc(MOBIL)!=0x0A); // Preskoc zbytek radku |
25 |
while(fgetc(MOBIL)!=0x0A); // Preskoc zbytek radku |
85 |
|
26 |
|
86 |
// while(kbhit(MOBIL)) {fgetc(MOBIL); delay_ms(100);} // Preskoc zbytek radku |
27 |
if(odp[0] == 'O' && odp[1] == 'K') return 1; |
87 |
output_high(PIN_A4); |
28 |
else return 0; |
88 |
|
29 |
} |
89 |
|
30 |
|
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 |
31 |
read_sms() |
103 |
{ |
32 |
{ |
104 |
//!!!KAKL for(pom=0;pom<55;pom++) //preskoc nedulezite informace |
33 |
int pom,pom2,pom3,odkl,odkl2,maskovadlo; |
105 |
for(pom=0;pom<54;pom++) //preskoc nedulezite informace |
34 |
for(pom=0;pom<54;pom++) //preskoc nedulezite informace |
106 |
{ |
35 |
{ |
107 |
fgetc(MOBIL); |
36 |
fgetc(MOBIL); |
108 |
} |
37 |
} |
109 |
|
38 |
|
Line 183... |
Line 112... |
183 |
odp[pom+1] = odkl2; //uloz 8my znak vznikly z "prenosu" |
112 |
odp[pom+1] = odkl2; //uloz 8my znak vznikly z "prenosu" |
184 |
maskovadlo = 0; //smaz maskovadlo |
113 |
maskovadlo = 0; //smaz maskovadlo |
185 |
} |
114 |
} |
186 |
} |
115 |
} |
187 |
odp[pom]='\0'; |
116 |
odp[pom]='\0'; |
- |
|
117 |
} |
188 |
|
118 |
|
189 |
/*lcd_gotoxy(1,3); |
119 |
void read_time() |
190 |
printf(lcd_putc,"%u %u %u %u",odp[0],odp[1],odp[2],odp[3]); */ |
- |
|
- |
|
120 |
{ |
191 |
lcd_init(); |
121 |
unsigned int8 n; |
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 |
|
122 |
|
200 |
//!!! fprintf(MOBIL,"AT+CMGD=1\r"); //smaz prijatou SMSku |
- |
|
201 |
|
123 |
|
202 |
if (odp[0] > 64 && odp[0] < 91 ) |
124 |
fprintf(MOBIL,"AT+CCLK?\r"); |
- |
|
125 |
while(fgetc(MOBIL)!='"'); |
- |
|
126 |
for(n=0;n<12;n++) //preskoc nedulezite informace |
203 |
{ |
127 |
{ |
204 |
odp[0] += 32; |
128 |
fgetc(MOBIL); |
205 |
} |
129 |
} |
- |
|
130 |
odp[0]=fgetc(MOBIL); |
- |
|
131 |
odp[1]=fgetc(MOBIL); |
- |
|
132 |
odp[2]=0; |
- |
|
133 |
} |
206 |
|
134 |
|
207 |
if (odp[1] > 64 && odp[1] < 91 ) |
135 |
void del_sms() |
208 |
{ |
136 |
{ |
209 |
odp[1] += 32; |
137 |
fprintf(MOBIL,"AT+CMGD=1\r"); //smaz prijatou SMSku |
210 |
} |
138 |
} |
211 |
|
139 |
|
- |
|
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); |
212 |
if (odp[2] > 64 && odp[2] < 91 ) |
147 |
setup_timer_2(T2_DIV_BY_4,255,1); |
213 |
{ |
148 |
setup_ccp1(CCP_PWM); |
214 |
odp[2] += 32; |
149 |
setup_ccp2(CCP_PWM); |
- |
|
150 |
setup_comparator(NC_NC_NC_NC); |
215 |
} |
151 |
setup_vref(FALSE); |
- |
|
152 |
setup_wdt(WDT_2304MS); |
216 |
|
153 |
|
217 |
if (odp[3] > 64 && odp[3] < 91 ) |
- |
|
218 |
{ |
154 |
set_pwm1_duty(0); |
219 |
odp[3] += 32; |
155 |
set_pwm2_duty(0); |
220 |
} |
- |
|
221 |
|
156 |
|
222 |
lcd_gotoxy(1,1); |
157 |
while(TRUE) |
223 |
printf(lcd_putc,"\f Odstraneni velkych"); |
- |
|
224 |
lcd_gotoxy(1,2); |
158 |
{ |
225 |
printf(lcd_putc," pismen"); |
- |
|
226 |
lcd_gotoxy(9,4); |
159 |
int status; |
227 |
printf(lcd_putc,"%s",odp); |
- |
|
228 |
output_low(PIN_A4) ; |
160 |
char *ptr; |
229 |
delay_ms(1000); |
161 |
int time; |
230 |
output_high(PIN_A4); |
- |
|
231 |
|
162 |
|
- |
|
163 |
restart_wdt(); |
232 |
|
164 |
|
- |
|
165 |
output_low(PIN_A4) ; |
233 |
//!!!KAKL |
166 |
delay_ms(150); |
234 |
fprintf(VRTULE,"%s",odp); |
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); |
235 |
|
173 |
|
236 |
|
174 |
|
237 |
if (odp[0] == 122 && odp[1] == 97 && odp[2] == 112 && odp[3] == 49) //odp=="zap1" |
- |
|
238 |
{ |
- |
|
239 |
status=1; |
175 |
set_pwm1_duty(500); |
240 |
} |
176 |
set_pwm2_duty(500); |
241 |
|
177 |
|
- |
|
178 |
fprintf(VRTULE,"ABABABABAB"); |
- |
|
179 |
|
- |
|
180 |
|
- |
|
181 |
/* if(check_new_sms()) // Je odpoved "OK"? |
- |
|
182 |
{ |
- |
|
183 |
// printf(lcd_putc,"736 655 250"); |
- |
|
184 |
delay_ms(1000); |
- |
|
185 |
} |
- |
|
186 |
else |
- |
|
187 |
{ |
- |
|
188 |
read_sms(); |
- |
|
189 |
|
- |
|
190 |
if (odp[0] == 'A' || odp[0] == 'a') |
- |
|
191 |
{ |
- |
|
192 |
set_pwm1_duty(500); |
- |
|
193 |
set_pwm2_duty(500); |
- |
|
194 |
Delay_ms(5000); |
- |
|
195 |
fprintf(VRTULE,"ABABABABAB"); |
- |
|
196 |
Delay_ms(20000); |
- |
|
197 |
set_pwm1_duty(0); |
- |
|
198 |
set_pwm2_duty(0); |
- |
|
199 |
} |
- |
|
200 |
|
242 |
if (odp[0] == 118 && odp[1] == 121 && odp[2] == 112 && odp[3]== 49) //odp=="vyp1" |
201 |
if (odp[0] == 118 && odp[1] == 121 && odp[2] == 112 && odp[3]== 49) |
243 |
{ |
202 |
{ |
244 |
status=2; |
203 |
fprintf(VRTULE,""); |
245 |
} |
204 |
} |
246 |
|
205 |
|
247 |
if (odp[0] == 97 && odp[1] == 104 && odp[2] == 111 && odp[3]== 106) //odp=="ahoj" |
206 |
if (odp[0] == 97 && odp[1] == 104 && odp[2] == 111 && odp[3]== 106) |
248 |
{ |
207 |
{ |
249 |
status=3; |
208 |
fprintf(VRTULE,""); |
250 |
} |
209 |
} |
251 |
|
210 |
} |
252 |
switch (status) |
211 |
/* read_time(); |
- |
|
212 |
time=strtoul(odp,&ptr,10); |
- |
|
213 |
if((time >= 30 && time <= 35) || (time >= 0 && time <= 5)) |
253 |
{ |
214 |
{ |
254 |
|
- |
|
255 |
case 1: output_low(zar1); |
215 |
set_pwm1_duty(500); |
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); |
216 |
set_pwm2_duty(500); |
276 |
printf(lcd_putc," rozeznan"); |
- |
|
277 |
break; |
- |
|
278 |
} |
217 |
} |
- |
|
218 |
else |
- |
|
219 |
{ |
- |
|
220 |
set_pwm1_duty(0); |
279 |
delay_ms(1000); |
221 |
set_pwm2_duty(0); |
280 |
} |
222 |
}*/ |
281 |
|
223 |
|
- |
|
224 |
delay_ms(1000); |
282 |
} |
225 |
} |
283 |
} |
226 |
} |