📄 main.lst
字号:
186: void InitAll() {
187: TRISA=RACNF;
188: TRISB=RBCNF;
189: TRISC=RCCNF;
190: TRISD=RDCNF;
191: TRISE=0x07;
192: OPTION=0x87;
193: T1CON=0x01;
194: BRGH=1;
195: SPBRG=103;
196: TXSTA=0x24;
197: RCSTA=0x90;
198: TXIF=1;
199: RCIF=0;
200: P_SCLK=0;
201: P_CSn=1;
202: P_SI=0;
203: }
204:
205: void SetLed(unsigned char mode,unsigned char LED) {
206: switch(mode) {
207: case 0x00: if(LED) LED0=1;
208: else LED0=0;
209: break;
210: case 0x01: if(LED) LED1=1;
211: else LED1=0;
212: break;
213: case 0x02:
214: #ifdef DEBUG
215: // Nothing
216: #else
217: PORTD=LED;
218: #endif
219: break;
220: }
221: }
222:
223: void Dly1mS(unsigned int l) {
224: int i;
225: while(l--) {
226: for(i=0;i<54;i++);
227: }
228: }
229:
230: #define S2 RB4
231: #define S3 RB3
232: #define S4 RB2
233: #define S5 RB1
234: // b
235: // ___
236: // a|___| c
237: // f| g | d
238: // ---
239: // e
240:
241: #define SEGF 0x01
242: #define SEGB 0x02
243: #define SEGA 0x04
244: #define SEGD 0x40
245: #define SEGC 0x20
246: #define SEGE 0x10
247: #define SEGG 0x08
248:
249: #define SEG0 SEGA|SEGB|SEGC|SEGD|SEGE|SEGF
250: #define SEG1 SEGC|SEGD
251: #define SEG2 SEGB|SEGC|SEGG|SEGE|SEGF
252: #define SEG3 SEGB|SEGC|SEGD|SEGE|SEGG
253: #define SEG4 SEGA|SEGC|SEGD|SEGG
254: #define SEG5 SEGA|SEGB|SEGD|SEGE|SEGG
255: #define SEG6 SEGA|SEGB|SEGG|SEGD|SEGE|SEGF
256: #define SEG7 SEGB|SEGC|SEGD
257: #define SEG8 SEGA|SEGB|SEGC|SEGD|SEGE|SEGF|SEGG
258: #define SEG9 SEGA|SEGB|SEGC|SEGD|SEGE|SEGG
259:
260: const char SEGTable[]={SEG0,SEG1,SEG2,SEG3,SEG4,
261: SEG5,SEG6,SEG7,SEG8,SEG9};
262:
263: unsigned char Mode=0;
264: // 0 is TX Mode
265: // 1 is RX Mode
266: // 2 is WOR Mode
267:
268: void SendPacket()
269: {
270: halSpiWriteReg(CC1100_TXFIFO, 3);
271: halSpiWriteBurstReg(CC1100_TXFIFO, &txb.Buffer[0], 3);
272: halSpiStrobe(CC1100_STX);
273: while (!P_GD00); // if(TMR1H & T1Mask) break;
274: while (P_GD00);// if(TMR1H & T1Mask) break;
275: halSpiStrobe(CC1100_SFTX);
276: }
277:
278:
279: void Sync8mS()
280: {
281: while(!(TMR1H & T1Mask)) ;
282: TMR1IF=0; TMR1L=0; TMR1H=0;
283: }
284:
285:
286: void myReceiver()
287: {
288: unsigned char length=0;
289: length=16;
290: if (halRfReceivePacket(&rxb.Buffer[0], &length)){
291: SetLed(0,0);
292: PickCnt++;
293: if(PickCnt==10) SetLed(1,0);
294: TimeOut=0;
295: if(rxb.myPacket.DataQ < 10) {
296: SetLed(2,~(SEGTable[rxb.myPacket.DataQ]));
297: txb.myPacket.DataQ=rxb.myPacket.DataQ;
298: } else txb.myPacket.DataQ=0;
299:
300: }
301: }
302:
303: void InitCC1100()
304: {
305: POWER_UP_RESET_CC1100();
306: // if(!SW1)
307: halRfWriteRfSettings1();
308: // else
309: // halRfWriteRfSettings2();
310: halSpiWriteBurstReg(CC1100_PATABLE, paTable, sizeof(paTable));
311:
312: SetLed(0,1);
313: SetLed(1,1);
314: SetLed(2,(SEGTable[8]));
315:
316: txb.myPacket.DataQ=0;
317: Sync8mS();
318: }
319:
320: void main()
321: {
322: unsigned char length=0;
323: unsigned int ch=0;
324: unsigned char Flag=0;
325: unsigned char count, div;
326:
327:
328: InitAll();
329: Mode=2;
330: InitCC1100();
331:
332: // if(!SW1)
333: {count=100; div=10;}
334: // else
335: // {count=200; div=20;}
336: while(1)
337: {
338: switch(Mode)
339: {
340: case 2:
341: txb.myPacket.DevAddr=0xAA55;
342: txb.myPacket.DataQ++;
343: if(txb.myPacket.DataQ==count) txb.myPacket.DataQ=0;
344: if((txb.myPacket.DataQ/div) < 10)
345: SetLed(2,~(SEGTable[txb.myPacket.DataQ/div]));
346: SendPacket();
347: Sync8mS();
348: break;
349: case 3: length=3;
350: if (halRfReceivePacket(&rxb.Buffer[0], &length))
351: {
352: if(rxb.myPacket.DevAddr==0xAA55)
353: {
354: if((rxb.myPacket.DataQ/div) < 10)
355: SetLed(2,~(SEGTable[rxb.myPacket.DataQ/div]));
356: SetLed(1,0);
357: }
358: } else
359: {
360: halSpiStrobe(CC1100_SFRX);
361: }
362: TMR1IF=0; TMR1L=0; TMR1H=0;
363: break;
364:
365: }
366: }
367: }
368:
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -