📄 ptr8000.lst
字号:
C51 COMPILER V7.06 PTR8000 03/28/2008 15:03:59 PAGE 1
C51 COMPILER V7.06, COMPILATION OF MODULE PTR8000
OBJECT MODULE PLACED IN PTR8000.OBJ
COMPILER INVOKED BY: C:\Keil\C51\BIN\C51.EXE PTR8000.C BROWSE DEBUG OBJECTEXTEND
stmt level source
1 //ICC-AVR application builder : 2006-4-4 11:28:26
2 // Target : M16 PTR8000模块简单测试
3 // Crystal: 11.059Mhz
4
5 //最关键的是SPI的初始化,MSB首位和极性方式00,极性方式错误,数据则不正确
6
7 #include <iom16v.h>
*** WARNING C318 IN LINE 7 OF PTR8000.C: can't open file 'iom16v.h'
8 #include <macros.h>
*** WARNING C318 IN LINE 8 OF PTR8000.C: can't open file 'macros.h'
9
10 #include "config.h"
*** WARNING C318 IN LINE 1 OF config.h: can't open file 'iom16v.h'
*** WARNING C318 IN LINE 2 OF config.h: can't open file 'macros.h'
11 #include "nrf905.h"
12
13 #define MASTER //编译控制是主机还是从机
14
15 #define T0N 25
16
17 //32字节数据包发送时间
18 //=650us_StartUp+200us_Preamble+(4+32+2)Byts*8Bit/50000bps*1000000us=6.6ms
19 #define RFTN 10 //发送测试间隔 10*20ms
20
21 bit bTimer,bRfSend;
22 uchar T0Cnt,RfCnt;
23
24 void port_init(void)
25 {
26 1 PORTA = 0x08;
*** ERROR C202 IN LINE 26 OF PTR8000.C: 'PORTA': undefined identifier
27 1 DDRA = 0x37;
*** ERROR C202 IN LINE 27 OF PTR8000.C: 'DDRA': undefined identifier
28 1 PORTB = 0x50;
*** ERROR C202 IN LINE 28 OF PTR8000.C: 'PORTB': undefined identifier
29 1 DDRB = 0xBF;
*** ERROR C202 IN LINE 29 OF PTR8000.C: 'DDRB': undefined identifier
30 1 PORTC = 0x00; //m103 output only
*** ERROR C202 IN LINE 30 OF PTR8000.C: 'PORTC': undefined identifier
31 1 DDRC = 0x00;
*** ERROR C202 IN LINE 31 OF PTR8000.C: 'DDRC': undefined identifier
32 1 PORTD = 0x1C;
*** ERROR C202 IN LINE 32 OF PTR8000.C: 'PORTD': undefined identifier
33 1 DDRD = 0x80;
*** ERROR C202 IN LINE 33 OF PTR8000.C: 'DDRD': undefined identifier
34 1 }
35
36 //TIMER0 initialize - prescale:1024
37 // WGM: Normal
38 // desired value: 20mSec
39 // actual value: 19.908mSec (0.5%)
40 void timer0_init(void)
41 {
42 1 TCCR0 = 0x00; //stop
*** ERROR C202 IN LINE 42 OF PTR8000.C: 'TCCR0': undefined identifier
C51 COMPILER V7.06 PTR8000 03/28/2008 15:03:59 PAGE 2
43 1 TCNT0 = 0x29; //set count
*** ERROR C202 IN LINE 43 OF PTR8000.C: 'TCNT0': undefined identifier
44 1 OCR0 = 0xD7; //set compare
*** ERROR C202 IN LINE 44 OF PTR8000.C: 'OCR0': undefined identifier
45 1 TCCR0 = 0x05; //start timer
*** ERROR C202 IN LINE 45 OF PTR8000.C: 'TCCR0': undefined identifier
46 1 }
47
48 #pragma interrupt_handler timer0_ovf_isr:10
49 void timer0_ovf_isr(void)
50 {
51 1 TCNT0 = 0x29; //reload counter value
52 1
53 1 if (--T0Cnt==0)
54 1 {T0Cnt=T0N;
55 2 bTimer=1;
56 2 }
57 1 if (--RfCnt==0)
58 1 {RfCnt=RFTN;
59 2 bRfSend=1;
60 2 }
61 1 }
62
63 //TIMER1 initialize - prescale:8
64 // WGM: 0) Normal, TOP=0xFFFF
65 // desired value: 10mSec
66 // actual value: 9.999mSec (0.0%)
67 void timer1_init(void)
68 {
69 1 TCCR1B = 0x00; //stop
70 1 TCNT1H = 0xCA; //setup
71 1 TCNT1L = 0x01;
72 1 OCR1AH = 0x35;
73 1 OCR1AL = 0xFF;
74 1 OCR1BH = 0x35;
75 1 OCR1BL = 0xFF;
76 1 ICR1H = 0x35;
77 1 ICR1L = 0xFF;
78 1 TCCR1A = 0x00;
79 1 TCCR1B = 0x02; //start Timer
80 1 }
81
82 #pragma interrupt_handler timer1_ovf_isr:9
83 void timer1_ovf_isr(void)
84 {
85 1 //TIMER1 has overflowed
86 1 TCNT1H = 0xCA; //reload counter high value
87 1 TCNT1L = 0x01; //reload counter low value
88 1 }
89
90 //SPI initialize
91 void spi_init(void)
92 {uchar temp;
93 1
94 1 //SPCR = 0xD1; //SPI中断允许,SPI允许,主机模式,MSB,极性方式00,1/16系统时钟速率
95 1 SPCR = 0x51; //不使用SPI中断,其它同上
96 1 SPSR = 0x00; //setup SPI
97 1
98 1 temp = SPSR; //!!!
99 1 temp = SPDR; //清空SPI,和中断标志,使SPI空闲
100 1 }
101
C51 COMPILER V7.06 PTR8000 03/28/2008 15:03:59 PAGE 3
102 #pragma interrupt_handler spi_stc_isr:11
103 void spi_stc_isr(void)
104 {uchar data;
105 1 //byte in SPDR has been sent/received
106 1 //data=SPDR;
107 1 //SPDR=0x66;
108 1 }
109
110 //UART0 initialize
111 // desired baud rate: 19200
112 // actual: baud rate:19200 (0.0%)
113 // char size: 5 bits
114 // parity: Disabled
115 void uart0_init(void)
116 {
117 1 UCSRB = 0x00; //disable while setting baud rate
118 1 UCSRA = 0x00;
119 1 UCSRC = BIT(URSEL) | 0x00;
120 1 UBRRL = 0x23; //set baud rate lo
121 1 UBRRH = 0x00; //set baud rate hi
122 1 UCSRB = 0x18;
123 1 }
124
125 //call this routine to initialize all peripherals
126 void init_devices(void)
127 {
128 1 //stop errant interrupts until set up
129 1 CLI(); //disable all interrupts
130 1 port_init();
131 1 timer0_init();
132 1 timer1_init();
133 1 spi_init();
134 1 uart0_init();
135 1
136 1 MCUCR = 0x00;
137 1 GICR = 0x00;
138 1 TIMSK = 0x05; //timer interrupt sources
139 1 SEI(); //re-enable interrupts
140 1 //all peripherals are now initialized
141 1 }
142
143 void main()
144 {
145 1 init_devices();
146 1 SystemIni();
147 1 nrf905_Init();
148 1
149 1 while (1)
150 1 {
151 2 if (bTimer) TimerFunc();
152 2 #ifdef MASTER
153 2 if (bRfSend)
154 2 { bRfSend=0;
155 3 RfSendProc();//发送测试
156 3 }
157 2 #endif
158 2
159 2 RfRecvProc();//接收处理
160 2 };
161 1 }
162
163 //接收处理
C51 COMPILER V7.06 PTR8000 03/28/2008 15:03:59 PAGE 4
164 void RfRecvProc()
165 {uchar i;
166 1
167 1 //if ((PIND&(1<<AM))==0) return;//一般先AM=1指示地址匹配对
168 1
169 1 if ((PIND&(1<<DR))==0) return;//DR=1时表示数据接收对而且Crc正确
170 1
171 1 //已经接收到数据
172 1 nrf905_ReadData();//读出...
173 1 for (i=0;i<32;i++)
174 1 { if (RxBuf[i]!=(i+i))
175 2 return;
176 2 }
177 1
178 1 //数据接收正确...灯指示
179 1 CPL(PORTD,LED);
180 1
181 1 //从机回送数据包,这样双方都能指示是否收到有效数据包
182 1 #ifndef MASTER
RfSendProc();
#endif
185 1 }
186
187 //发送测试
188 void RfSendProc()
189 {uchar i;
190 1 for (i=0;i<32;i++) TxBuf[i]=i+i;
191 1 nrf905_SendData();//发送测试数据
192 1 nrf905_RxOn();//重新回到接收状态
193 1 }
194
195 void TimerFunc()
196 {
197 1 bTimer=0;
198 1 //WDR();//clear WDT
199 1
200 1 CPL(PORTD,LED);
201 1 //SPDR=66;
202 1 }
203
204 void SystemIni()
205 {
206 1 T0Cnt=T0N;
207 1 RfCnt=RFTN;
208 1 }
209
210 void DelayMs(uchar ms)
211 {char i;
212 1 for (i=0;i<ms;i++)
213 1 {DelayUs(1000);
214 2 }
215 1 return;
216 1 }
217
218 void DelayUs(uint us)
219 {uint i;
220 1 for (i=0;i<us;i++)
221 1 {NOP();NOP();NOP();NOP();NOP();NOP();
222 2 }
223 1 }
224
C51 COMPILATION COMPLETE. 4 WARNING(S), 12 ERROR(S)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -