📄 main.lst
字号:
C51 COMPILER V7.01 MAIN 05/26/2009 13:59:49 PAGE 1
C51 COMPILER V7.01, COMPILATION OF MODULE MAIN
OBJECT MODULE PLACED IN main.OBJ
COMPILER INVOKED BY: C:\Keil\C51\BIN\C51.EXE main.c BROWSE DEBUG OBJECTEXTEND
stmt level source
1 #include <INTRINS.H>
2
3 //#include <at89x52.h>
4 #include <string.h>
5 #include <stdlib.h>
6 #include <absacc.h>
7 #include <stdio.h>
8
9 #include "ch452cmd.h"
10 #include "pin.h"
11
12 #define uchar unsigned char
13 #define uint unsigned int
14
15 #define KBD_PORT=P0;
16 #define FSM_INIT 0x00;
17 #define FSM_WAIT_PRESS 0x01;
18 #define FSM_VERFY1 0x02;
19 #define FSM_VERFY2 0x03;
20 #define FSM_WAIT_RELEASE 0x04;
21
22 #define FILTER_A 10
23 #define FILTER_N 11
24 unsigned int last_value;
25 unsigned char scankey=0;
26 bit Timerout=0;
27 bit keypress;
28
29 #define RELOAD_HIGH 0x3C
30 #define RELOAD_LOW 0xD2
31 #define DB_VAL 2
32 sbit PBTN=P0^0;
33 sbit NBTN=P0^1;
34 sbit RSTBTN=P0^2;
35 sbit vHigh=P2^0;
36 sbit vLow=P2^1;
37 sbit vDir=P2^2;
38 sbit lRun=P2^3;
39 sbit lOk=P2^4;
40 sbit lErr=P2^5;
41 sbit buzzer=P1^6;
42 unsigned int keepcnt=0xff;
43 unsigned int itimeover=0xffff;
44 bit keepok=0;
45 bit btimeover=0;
46
47 bit almpulse;
48
49 unsigned char alarm;
50
51 bit pmode=0;
52 bit nmode=0;
53 bit rstmode=0;
54 bit disp_updata=0;
55 unsigned char istep=0;
C51 COMPILER V7.01 MAIN 05/26/2009 13:59:49 PAGE 2
56
57 //0Pa=1.241mv
58 #define PP3_63k 34944
59 #define PP3_04k 34708
60 #define PP10_00k 40239
61 #define PP20_00k 46085
62 #define PP21_00k 46531
63 #define NP49 32270
64 #define NP588 31929
65
66 sbit ADC_DIN=P3^0;
67 sbit ADC_CLK=P3^1;
68 sbit ADC_DRDY=P3^2;
69
70 unsigned char code displaybit[]={0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f};
71 unsigned char code displaycode[]={0x3f,0x06,0x5b,0x4f,
72 0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71,0x00,0x40};
73 unsigned char code dotcode[32]={0,3,6,9,12,16,19,22,
74 25,28,31,34,38,41,44,48,
75 50,53,56,59,63,66,69,72,
76 75,78,81,84,88,91,94,97};
77 unsigned char displaybuf[8]={16,16,16,16,16,16,16,16};
78
79 float voltage;
80 unsigned int data_out;
81
82 void system_tick(void) interrupt 1
83 {
84 1 static unsigned char second_cnt=20;
85 1 TR0=0;
86 1 TH0=RELOAD_HIGH;
87 1 TL0=RELOAD_LOW;
88 1 TR0=1;
89 1
90 1 Timerout=1;
91 1 scankey=KBD_PORT;
*** WARNING C275 IN LINE 91 OF MAIN.C: expression with possibly no effect
92 1 if(!PBTN || !NBTN)
93 1 {
94 2 keypress=1;
95 2 }
96 1 else
97 1 {
98 2 keypress=0;
99 2 }
100 1
101 1 if((istep==1)||(istep==2)||(istep==3)||(istep==4)||(istep==5)||(istep==7)||(istep==8))
102 1 {
103 2 if(!keepok&&keepcnt) keepcnt--;
104 2 if(!keepcnt)
105 2 {
106 3 keepok=1;
107 3 }
108 2 if(keepok)
109 2 {
110 3 itimeover--;
111 3 if(!itimeover) btimeover=1;
112 3 }
113 2 }
114 1
115 1 if(alarm) alarm--;
116 1
C51 COMPILER V7.01 MAIN 05/26/2009 13:59:49 PAGE 3
117 1 second_cnt--;
118 1 if(!second_cnt)
119 1 {
120 2 second_cnt=20;
121 2 disp_updata=1;
122 2 }
123 1 if(disp_updata&&(istep==10))
124 1 almpulse=!almpulse;
125 1 else
126 1 almpulse=0;
127 1
128 1 }
129
130 void delay1(uint ms)
131 {
132 1 uint i,j;
133 1 for(i=0;i<ms;i++)
134 1 for(j=0;j<1000;j++);
135 1 }
136
137 void delay2(uint us)
138 {
139 1 uint i;
140 1 for(i=0;i<us;i++)
141 1 _nop_();
142 1 }
143
144 unsigned char rearrange(unsigned char a)
145 {
146 1 unsigned char i,b;
147 1 b=a&0x01;
148 1 for(i=1; i<8; i++)
149 1 {
150 2 b=b<<1;
151 2 a=a>>1;
152 2 b=b+(a&0x01);
153 2 }
154 1 return(b);
155 1 }
156
157 void WriteToReg_ADC(unsigned char a)
158 {
159 1 SCON=0;
160 1 TI=0;
161 1 SBUF=a;
162 1 while(!TI);
163 1 }
164
165 void MX7705_Init()
166 {
167 1 unsigned char i;
168 1
169 1 ADC_CLK=1;
170 1 ADC_DIN=1;
171 1 for(i=0;i<100;i++)
172 1 {
173 2 ADC_CLK=0;
174 2 ADC_CLK=1;
175 2 }
176 1 WriteToReg_ADC(0x04); //0x20
177 1 WriteToReg_ADC(0x30); //0x0c
178 1 WriteToReg_ADC(0x08); //0x10
C51 COMPILER V7.01 MAIN 05/26/2009 13:59:49 PAGE 4
179 1 WriteToReg_ADC(0x42); //0x42
180 1
181 1 }
182
183 unsigned int ReadWord()
184 {
185 1 unsigned char high8,low8;
186 1 unsigned int out;
187 1
188 1 SCON=0;
189 1
190 1 REN=1;
191 1 RI=0;
192 1 while(!RI);
193 1 high8=SBUF;
194 1
195 1 ADC_CLK=1;
196 1
197 1 RI=0;
198 1 while(!RI);
199 1 low8=SBUF;
200 1 REN=0;
201 1 out=rearrange(high8);
202 1 out=out<<8;
203 1 out=out+rearrange(low8);
204 1 return(out);
205 1
206 1 }
207
208 uint get_ad()
209 {
210 1 uint value;
211 1 while(ADC_DRDY==0)
212 1 {
213 2 WriteToReg_ADC(0x1C);
214 2 value=ReadWord();
215 2 }
216 1 return value;
217 1 }
218
219 uint filter2()
220 {
221 1 uint value_buf[FILTER_N];
222 1 uint temp;
223 1 char count,i,j;
224 1 for(count=0;count<FILTER_N;count++)
225 1 {
226 2 value_buf[count]=get_ad();
227 2 delay2(10);
228 2 }
229 1
230 1 for(j=0;j<FILTER_N-1;j++)
231 1 {
232 2 for(i=1;i<FILTER_N-j;i++)
233 2 {
234 3 if(value_buf[i]>value_buf[i-1])
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -