Code C - [expand] |
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
| unsigned char sms_in[90];
bit flag;
unsigned int i=0;
void interrupt()
{
if (PIR1.RCIF==1)
{
if (UART1_Data_Ready())
{
sms_in[i] = UART1_Read();
if(sms_in[i]=='K')
{
flag=1;
}
i++;
}
}
}
void main()
{
INTCON.GIE = 1;
INTCON.PEIE = 1;
PIE1.RCIE=1;
TRISC5_bit = 0;
UART1_Init(9600);
Delay_ms(500);
while(1)
{
if(flag==1)
{
char q=5;
if(sms_in[q]=='O'&& sms_in[q+1]=='N'&& sms_in[q+2]=='1')
{
RC5_bit=1;
UART1_Write(0X0D);
UART1_Write(0X0A);
flag=0;
i=0;
}
else if(sms_in[q]=='O'&& sms_in[q+1]=='F'&& sms_in[q+2]=='F')
{
RC5_bit=0;
UART1_Write(0X0D);
UART1_Write(0X0A);
flag=0;
i=0;
}
}
}
} |
Last edited by a moderator: