-
Notifications
You must be signed in to change notification settings - Fork 0
/
IR-Remote.c
107 lines (107 loc) · 1.58 KB
/
IR-Remote.c
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
/*
UP --- P1^2
DOWN --- P3^5
RIGHT --- P1^1
LEFT --- P0^6
*/
#include <STC12C5A60S2.H>
#include <intrins.h>
#define FULL 65535
sbit IR = P1^3;
sbit UP = P1^2;
sbit DOWN = P3^5;
sbit RIGHT = P1^1;
sbit LEFT = P0^6;
unsigned char lastDirection;
void IR_TR(unsigned char direction);
void delay(unsigned int time);
void steup(){
CMOD = 0x08;
CR = 0;
CCAP0L = 0;
CCAP0H = 0;
CCAPM0 = 0x42;
TMOD = 0x01;
TL0 = 0;
TH0 = 0;
TR0 = 0;
TF0 = 0;
}
void main(){
unsigned char direction = 0;//using 8bit to be a arrary and save direction
steup();
while(1){
/*
direction:
0x01: //UP
0x05: //UP+LEFT
0x09: //UP+RIGHT
0x02: //DOWN
0x06: //DOWN+RIGHT
0x0A: //DOWN+RIGHT
0x04: //LEFT
0x08: //RIGHT
*/
direction = 0;
if(UP == 0){
direction = 0x01;
}
delay(10000);
if(DOWN == 0){
direction = direction | 0x02;
}
delay(10000);
if(LEFT == 0){
direction = direction | 0x04;
}
delay(10000);
if(RIGHT == 0){
direction = direction | 0x08;
}
delay(10000);
if(!UP || !DOWN || !LEFT || !RIGHT){
IR_TR(direction);
direction = 0;
}
delay(10000);
}
}
void IR_TR(unsigned char direction){
unsigned char i=0;
bit j;
CCAP0L = 128;
CCAP0H = 128;
CR = 1;
delay(16800);
CR = 0;
delay(8400);
for(i=0;i<8;i++){
j = (_cror_(direction,i)&0x01);
if(j == 1){
CR = 1;
delay(1844);
CR = 0;
delay(500);
}
if(j == 0){
CR = 1;
delay(524);
CR = 0;
delay(500);
}
}
CR = 1;
delay(526);
CR = 0;
delay(20000);
CCAP0L = 0;
CCAP0H = 0;
}
void delay(unsigned int time){
TL0 = (FULL - time) %256;
TH0 = (FULL - time) /256;
TR0 = 1;
while(!TF0);
TR0 = 0;
TF0 = 0;
}