📄 per.lst
字号:
C51 COMPILER V7.06 PER 10/23/2004 16:55:19 PAGE 1
C51 COMPILER V7.06, COMPILATION OF MODULE PER
OBJECT MODULE PLACED IN per.OBJ
COMPILER INVOKED BY: C:\Keil\C51\BIN\C51.EXE per.c OPTIMIZE(4,SPEED) BROWSE MOD517(NOAU) DEBUG OBJECTEXTEND
stmt level source
1 #include "MAIN.H"
2 #include "PER.H"
3
4 /*////////////////////////////functions for A/D convert//////////////////*/
5 //for c505c
6 void ad_init(unsigned char ChSelect)
7 {
8 1 SYSCON |= 0x10;
9 1 P1ANA=ChSelect; //P1.0~P1.2 used as analog input port
10 1 SYSCON &= 0xef;
11 1 ADM=0;
12 1 ADCON1|=0xb0;
13 1 }
14
15 unsigned int ad_single(unsigned char ch)
16 {
17 1 unsigned int ad_value,ad_value1;
18 1 unsigned char i=100;
19 1 ADCON0=ADCON0 & 0xf8 | ch;
20 1 ADDATL=0x00; //start AD
21 1 while(i!=0)
22 1 {
23 2 if(!BSY)
24 2 {
25 3 ad_value =ADDATH;
26 3 ad_value1 =ADDATL;
27 3 ad_value = (ad_value<<2) | (ad_value1>>6);
28 3 i=0; //if convertion over read the value,end loop
29 3 }
30 2 else
31 2 {
32 3 i--; //if converting polling several times
33 3 }
34 2 }
35 1 return ad_value;
36 1 }
37
38 //******************************************************************************************
39 //function: float sensor_value(unsigned int Rs1,unsigned int ad);
40 //description: calculate the sensor's resistance by given parameter.
41 //parameter: Rs1---resistance of the sensor bridge;
42 // ad---the A/D result
43 //return: the sensor's resistance.
44 //******************************************************************************************
45 float sensor_value(float Rs1,float ad)
46 {
47 1 float r;
48 1 r=Rs1*ad*VREF*8.6/3;
49 1 r=r/(VCC*AD_FULL_VALUE-ad*VREF*8.6/3);
50 1 if(r<0) r=0;
51 1 if(r>1000) r=1000;
52 1 return(r);
53 1 }
54
55 ///////////////////////operations about X5045///////////////////////////////
C51 COMPILER V7.06 PER 10/23/2004 16:55:19 PAGE 2
56 //*****************************************************************************************
57 //function: unsigned char read_8bit(void);
58 //description: this function read 8 bit from x5045
59 //parameter: none
60 //return: the read byte
61 //*****************************************************************************************
62 unsigned char read_8bit(void)
63 {
64 1 unsigned char ReadTemp=0;
65 1 unsigned char i;
66 1 for(i=0;i<8;i++)//read 8 bit
67 1 {
68 2 sck5045=1;
69 2 _nop_();
70 2 sck5045=0;
71 2 ReadTemp=(ReadTemp<<1) | (unsigned char)so5045;
72 2 _nop_();
73 2 }
74 1 return(ReadTemp);
75 1 }
76 //*****************************************************************************************
77 //function: void write_8bit(unsigned char WriteValue);
78 //description: this function write 8 bit to x5045
79 //parameter: the value need to be write
80 //return: none
81 //*****************************************************************************************
82 void write_8bit(unsigned char WriteValue)
83 {
84 1 unsigned char TempValue;
85 1 unsigned char i;
86 1 for(i=0;i<8;i++)//
87 1 {
88 2 sck5045=0; //
89 2 TempValue=(WriteValue<<i) & 0x80;
90 2 if(TempValue>=0x80)
91 2 {
92 3 si5045=1;
93 3 }
94 2 else
95 2 {
96 3 si5045=0;
97 3 }
98 2 _nop_();
99 2 sck5045=1;
100 2 _nop_();
101 2 }
102 1
103 1 }
104 //*****************************************************************************************
105 //function: void write_8bit1(unsigned char WriteValue);
106 //description: this function write 8 bit to x5045
107 //parameter: the value need to be write
108 //return: none
109 //*****************************************************************************************
110 void write_8bit1(unsigned char WriteValue)
111 {
112 1 unsigned char TempValue;
113 1 unsigned char i;
114 1 for(i=0;i<8;i++)//
115 1 {
116 2 sck5045=0; //
117 2 TempValue=(WriteValue<<i) & 0x80;
C51 COMPILER V7.06 PER 10/23/2004 16:55:19 PAGE 3
118 2 if(TempValue>=0x80)
119 2 {
120 3 si5045=1;
121 3 }
122 2 else
123 2 {
124 3 si5045=0;
125 3 }
126 2 _nop_();
127 2 sck5045=1;
128 2 _nop_();
129 2 }
130 1
131 1 }
132
133 //*****************************************************************************************
134 //function: void init_5045wdt(unsigned char WatchDogTime);
135 //description: this function initialize the x5045 watch dog timer
136 //parameter: watch dog time
137 //return: none
138 //*****************************************************************************************
139 void init_5045wdt(unsigned char WatchDogTime)
140 {
141 1 unsigned int nopp;
142 1 ////write watch dog time
143 1 cs5045=0;
144 1 write_8bit(WREN);//send write enable command
145 1 cs5045=1;
146 1 _nop_();
147 1 cs5045=0;
148 1 _nop_();
149 1 write_8bit(WRSR);//send write status register command
150 1 write_8bit(WatchDogTime);//write watch dog time
151 1 _nop_();
152 1 cs5045=1;
153 1 for(nopp=0;nopp<4000;nopp++)
154 1 {
155 2 ;
156 2 }
157 1 write_8bit(WRDI);//send write disable command
158 1 }
159 //*****************************************************************************************
160 //function: void write_byte(unsigned char address,unsigned char content);
161 //description: this function write one byte to x5045
162 //parameter: address---address of memory need to be write ;content---content need to be write
163 //return: none
164 //*****************************************************************************************
165 void write_byte(unsigned char address,unsigned char content)
166 {
167 1 unsigned int nopp;
168 1 ////write one byte to 00-ffh address
169 1 cs5045=0;
170 1 _nop_();
171 1 write_8bit(WREN);//send write enable command
172 1 _nop_();
173 1 cs5045=1;
174 1 _nop_();
175 1 cs5045=0;
176 1 _nop_();
177 1 write_8bit(WRITE0);//send write command
178 1 write_8bit(address);//send write address
179 1 write_8bit(content);//write content
C51 COMPILER V7.06 PER 10/23/2004 16:55:19 PAGE 4
180 1 _nop_();
181 1 cs5045=1;
182 1 for(nopp=0;nopp<4000;nopp++)
183 1 {
184 2 ;
185 2 }
186 1 cs5045=0;
187 1 _nop_();
188 1 write_8bit(WRDI);//send write disable command
189 1 cs5045=0;
190 1 _nop_();
191 1 }
192 //*****************************************************************************************
193 //function: unsigned char read_byte(unsigned char address);
194 //description: this function read one byte from x5045
195 //parameter: address---address of memory need to be read
196 //return: the read content.
197 //*****************************************************************************************
198 unsigned char read_byte(unsigned char address)
199 {
200 1 unsigned char content;
201 1 cs5045=0;
202 1 write_8bit(READ0);//send read command
203 1 write_8bit(address);//send address
204 1 content=read_8bit();//read one byte
205 1 _nop_();
206 1 cs5045=1;
207 1 return(content);
208 1 }
209
210 //*****************************************************************************************
211 //function: void write_page_float4(unsigned char StartAddr,float value);
212 //description: this function write float data to x5045,the first byte address is specified
213 //parameter: StartAddr---the first address of the unit will be write;value---value to be write
214 //return: none
215 //*****************************************************************************************
216 void write_page_float4(unsigned char StartAddr,float value)//write 4 byte float data to x5045
217 { //address from the parametre StartAddr
218 1 union {float x1;unsigned char x2[4];}store;
219 1 unsigned int nopp;
220 1 ////write one byte to 00-ffh address
221 1 store.x1=value;
222 1 cs5045=0;
223 1 _nop_();
224 1 write_8bit(WREN);//send write enable command
225 1 _nop_();
226 1 cs5045=1;
227 1 _nop_();
228 1 cs5045=0;
229 1 _nop_();
230 1 write_8bit(WRITE0);//send write command
231 1 write_8bit(StartAddr);//send write address
232 1 write_8bit(store.x2[0]);
233 1 write_8bit(store.x2[1]);
234 1 write_8bit(store.x2[2]);
235 1 write_8bit(store.x2[3]);
236 1 _nop_();
237 1 cs5045=1;
238 1 for(nopp=0;nopp<4000;nopp++)
239 1 {
240 2 ;
241 2 }
C51 COMPILER V7.06 PER 10/23/2004 16:55:19 PAGE 5
242 1 cs5045=0;
243 1 _nop_();
244 1 write_8bit(WRDI);//send write disable command
245 1 _nop_();
246 1 cs5045=1;
247 1 }
248 //*****************************************************************************************
249 //function: void write_page_array12(unsigned char StartAddr,unsigned char *p)
250 //description: this function write 12 byte data to x5045,the first byte address is specified
251 //parameter: StartAddr---the first address of the unit will be write;value---value to be write
252 // p---pointer to array
253 //return: none
254 //*****************************************************************************************
255 void write_page_array12(unsigned char StartAddr,unsigned char *p)//write 12 byte data to x5045
256 { //address from the parametre StartAddr
257 1 unsigned int nopp;
258 1 unsigned char i;
259 1 ////write one byte to 00-ffh address
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -