📄 contrler.lst
字号:
38 1 bit i=0;
39 1 bit n=0;
40 1 char *s ="abcdefghijkl";
41 1 char str[10]={0};
42 1
43 1 i=WriteStr(0xa0,0,s,2, I2C0) ;
44 1 n=ReadStr(0xa1,0,str,2, I2C0);
45 1 _Nop();
46 1 }
47 void main1()
48 {
49 1 unsigned char sla, suba, *s, uc_data[16], j, k;
50 1 // unsigned int i;
C51 COMPILER V7.07 CONTRLER 07/08/2005 10:08:22 PAGE 5
51 1 bit breturn;
52 1 TMOD=0x10;//Set the timer1 works at model 1(16 bit counter)
53 1 TR1=0;
54 1 IT0=1; // Triggered by the rising edge
55 1 bKeyUP=True;
56 1 bNewCodeFlag=False;
57 1 ucCnt=0;
58 1 ucCount=0;
59 1 LightFlash(5); //Flash the LED five times to make sure that the LED is OK
60 1 EX0=1;
61 1 TR1=1;
62 1 EA=1; //Turn on the interrupt.
63 1
64 1 for(;;)
65 1 {
66 2 k = 1;
67 2 s=uc_data;
68 2 sla=0xa0+0x02*k;
69 2 suba=j*16; /*子地址*/
70 2 ReadStr(sla,suba,s,16, I2C0);
71 2 WriteStr(sla,suba,s,16, I2C1) ;
72 2 if(bNewKey) //If there is a new key code,turn off the external interrupt and then light the LED
73 2 {
74 3 EX0=0;
75 3 bNewKey=False;
76 3 if((ucSysCode&0x82)==0x82)
77 3 {
78 4 //LightFlash(ucData&0x7f);
79 4 if((ucData&0x7f)==1)
80 4 {
81 5 s=uc_data;
82 5 breturn=1;
83 5 for(k=0;k<4;k++) /*AT24C16有4个bank,每个bank有各自的器件地址*/
84 5 {
85 6 sla=0xa0+0x02*k; /*bank地址*/
86 6 for(j=0;j<16;j++) /*每个bank有16 page,子地址不同*/
87 6 {
88 7 suba=j*16; /*子地址*/
89 7 if((ReadStr(sla,suba,s,16, I2C0))==0) {breturn=0;break;} /*从EEPROM0读出一页数据*/
90 7 if((WriteStr(sla,suba,s,16, I2C1))==0) {breturn=0;break;} /*把该页数据写入到EEPROM1*/
91 7 Wait(sla, I2C1); /*等待写操作完成*/
92 7 }
93 6 }
94 5 if(breturn==1)
95 5 LightFlash(3);
96 5 else
97 5 LightFlash(1);
98 5
99 5 }
100 4 }
101 3
102 3 EX0=1;
103 3 }
104 2 _Nop();
105 2 }
106 1 }
107 /*=====================================================
108 Function name: INT1_int()
109 Funciton:
110 Used to decode the signal carried by the infrared light,
111 and then stores the codes.
112 ---Founded by Wang Feng on Oct 19,2004
C51 COMPILER V7.07 CONTRLER 07/08/2005 10:08:22 PAGE 6
113 ---Modified by Wang Feng on Ocr 20,2004
114 =====================================================*/
115 void INT1_int() interrupt 0 using 1
116 {
117 1 static bit bHeadSignFlag; //Flag of the synchro pulse
118 1 unsigned int uiPulseWidth; //The space time between two pulses
119 1 bit bData; //Stores the bit just received.
120 1 static unsigned char ucSysTmp,ucDataTmp;
121 1 //Two temporary variables used to store the system code and data code
122 1 uiPulseWidth=TH1;
123 1 uiPulseWidth<<=8;
124 1 uiPulseWidth+=TL1; //Load the value of timer1 down to uiPulseWidth.
125 1 //Now the value of uiPulseWidth is the width of pulse.
126 1 TH1=0;
127 1 TL1=0; //Clear the Timer1 to count width of the next pulse.
128 1 ucCount++;
129 1 if(!bHeadSignFlag)
130 1 {
131 2 if((uiPulseWidth>=SYNL)&&(uiPulseWidth<=SYNU))
132 2 {
133 3 bHeadSignFlag=True; //If find the synchro pulse ,set it.
134 3 if(bKeyUP)
135 3 bNewCodeFlag=True;
136 3 else
137 3 bNewCodeFlag=False; //Judge if it a repeat code,and then set it.
138 3 bKeyUP=False;
139 3 ucCount=2;
140 3 }
141 2 else
142 2 ucCount=0;
143 2 return;
144 2 }
145 1 if(bHeadSignFlag)
146 1 {
147 2 /*=====================*/ //Added by Wang Feng on Oct.20,2004
148 2 if((uiPulseWidth>=SYNL)&&(uiPulseWidth<=SYNU))
149 2 {
150 3 ucCount=2;
151 3 return;
152 3 }
153 2 /*=====================*/
154 2 if(ucCount==19)
155 2 {
156 3 if((uiPulseWidth>=ENDL)&&(uiPulseWidth<=ENDU))
157 3 {
158 4 ucSysCode=ucSysTmp|0x80; //If the synchro pulse have been found,then judge
159 4 if(bNewCodeFlag) //whether the pulse an end pulse.It that is true,
160 4 { //store the code.Clear the flag of synchro pulse.
161 5 ucData=ucDataTmp&0x7f;
162 5 bNewCodeFlag=False;
163 5 }
164 4 else
165 4 ucData=ucDataTmp|0x80;
166 4 bNewKey=True;
167 4 }
168 3 bHeadSignFlag=False;
169 3 ucCount=0;
170 3 return;
171 3 }
172 2 if((uiPulseWidth>=BIT1L)&&(uiPulseWidth<=BIT1U)) bData=1;
173 2 else if((uiPulseWidth>=BIT0L)&&(uiPulseWidth<=BIT1U)) bData=0;
174 2 else //Judge the pulse is 0 or 1,and stored it to bData.
C51 COMPILER V7.07 CONTRLER 07/08/2005 10:08:22 PAGE 7
175 2 {
176 3 bHeadSignFlag=False;
177 3 ucCount=0;
178 3 return;
179 3 }
180 2 if(bHeadSignFlag)
181 2 switch(ucCount)
182 2 {
183 3 case 3:D_7=bData;break;
184 3 case 4:D_6=bData;break; //Load the bit Value from bData to
185 3 case 5:D_5=bData;break; //the uc_tmpKeyCode,a BData type variable.
186 3 case 6:D_4=bData;break;
187 3 case 7:D_3=bData;break;
188 3 case 8:D_2=bData;break;
189 3 case 9:D_1=bData;break;
190 3 case 10:D_0=bData;
191 3 ucSysTmp=uc_tmpKeyCode;break;
192 3 case 11:D_7=bData;break;
193 3 case 12:D_6=bData;break;
194 3 case 13:D_5=bData;break;
195 3 case 14:D_4=bData;break;
196 3 case 15:D_3=bData;break;
197 3 case 16:D_2=bData;break;
198 3 case 17:D_1=bData;break;
199 3 case 18:D_0=bData;
200 3 ucDataTmp=uc_tmpKeyCode;break;
201 3 default:
202 3 break;
203 3 }
204 2 }
205 1 }
206 /*=====================================================
207 Function name: void T1_INT()
208 Funciton:
209 Used to decode the signal carried by the infrared light,
210 and light the LED according to the data code decoded.
211 ---Founded by Wang Feng on Oct 19,2004
212 ---Modified by Wang Feng on Ocr 20,2004
213 =====================================================*/
214 void T1_INT() interrupt 3 using 2
215 {
216 1 ucCnt++;
217 1 if(ucCnt>=2)
218 1 {
219 2 bKeyUP=True;
220 2 ucCnt=0;
221 2 }
222 1
223 1 }
224 /*=====================================================
225 Function name: void LightFlash(unsigned char Times)
226 Funciton:
227 Light the LED accord the Times.
228 Parameter:
229 Times: times that LED needed to ON and OFF.
230 ---Founded by Wang Feng on Oct 19,2004
231 ---Modified by Wang Feng on Ocr 20,2004
232 =====================================================*/
233
234 void LightFlash(unsigned char Times)
235 {
236 1 unsigned char i;
C51 COMPILER V7.07 CONTRLER 07/08/2005 10:08:22 PAGE 8
237 1 for(i=0;i<Times;i++)
238 1 {
239 2 LED1=0;
240 2 Delay();
241 2 LED1=1;
242 2 Delay();
243 2 }
244 1 }
245 /*=====================================================
246 Function name: void Delay()
247 Funciton:
248 Delay the time by a limited circle.
249 ---Founded by Wang Feng on Oct 19,2004
250 ---Modified by Wang Feng on Ocr 20,2004
251 =====================================================*/
252 void Delay()
253 {
254 1 unsigned int i;
255 1 for(i=0;i<32000;i++);
256 1 }
MODULE INFORMATION: STATIC OVERLAYABLE
CODE SIZE = 751 ----
CONSTANT SIZE = 23 ----
XDATA SIZE = ---- ----
PDATA SIZE = ---- ----
DATA SIZE = 7 38
IDATA SIZE = ---- ----
BIT SIZE = 4 4
END OF MODULE INFORMATION.
C51 COMPILATION COMPLETE. 0 WARNING(S), 0 ERROR(S)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -