|
|
C51 COMPILER V9.56.0.0 IRIN 04/06/2022 23:56:38 PAGE 1 |
|
|
|
|
|
|
|
|
C51 COMPILER V9.56.0.0, COMPILATION OF MODULE IRIN |
|
|
OBJECT MODULE PLACED IN IRIN.OBJ |
|
|
COMPILER INVOKED BY: D:\Keil_v5\C51\BIN\C51.EXE IRIN.c OPTIMIZE(8,SPEED) BROWSE DEBUG OBJECTEXTEND TABS(2) |
|
|
|
|
|
line level source |
|
|
|
|
|
1 #include "IRIN.h" |
|
|
2 #include "i2c.h" |
|
|
3 |
|
|
4 uint journey; |
|
|
5 uint journey1; |
|
|
6 extern uchar pwm_left; |
|
|
7 unsigned int b; |
|
|
8 unsigned int c; |
|
|
9 extern uint time1; |
|
|
10 extern uchar pwm_val_left; |
|
|
11 unsigned int b2; |
|
|
12 unsigned int c2; |
|
|
13 |
|
|
14 uint money=7; |
|
|
15 uint sudu=0; |
|
|
16 |
|
|
17 uint count=0; //栅格是一圈20个 |
|
|
18 |
|
|
19 uchar ms=0; |
|
|
20 uint speed=0; |
|
|
21 uint r_s=0; |
|
|
22 |
|
|
23 bit state=0; |
|
|
24 bit s0=0; |
|
|
25 bit flas=0; |
|
|
26 |
|
|
27 uchar sec=0; |
|
|
28 uchar sec1=0; |
|
|
29 |
|
|
30 /******************************************************************************* |
|
|
31 * 函 数 名 : delay |
|
|
32 * 函数功能 : 延时函数,i=1时,大约延时10us |
|
|
33 *******************************************************************************/ |
|
|
34 void delay11(int i) |
|
|
35 { |
|
|
36 1 while(i--); |
|
|
37 1 } |
|
|
38 |
|
|
39 void IRIN_Init(void) |
|
|
40 { |
|
|
41 1 TMOD=0x01 | 0x20 ;//定时器1工作方式1 |
|
|
42 1 TH0=0x3C; |
|
|
43 1 TL0=0xb0; |
|
|
44 1 ET0=1; |
|
|
45 1 TR0=1; |
|
|
46 1 EA=1; |
|
|
47 1 EX1=1; |
|
|
48 1 IT1=1; |
|
|
49 1 } |
|
|
50 |
|
|
51 void display() |
|
|
52 { |
|
|
53 1 if(state==0) |
|
|
54 1 { |
|
|
55 2 sudu=At24c02Read(10); |
|
|
C51 COMPILER V9.56.0.0 IRIN 04/06/2022 23:56:38 PAGE 2 |
|
|
|
|
|
56 2 if(money>7) |
|
|
57 2 { |
|
|
58 3 money=At24c02Read(5); |
|
|
59 3 } |
|
|
60 2 LcdSetCursor(0,0); |
|
|
61 2 LcdShowStr(0,0,"Speed:"); |
|
|
62 2 Lcd1602_Write_Data(0x30+sudu/100%10); |
|
|
63 2 Lcd1602_Write_Data(0x30+sudu/10%10); |
|
|
64 2 Lcd1602_Write_Data(0x30+sudu%10); |
|
|
65 2 LcdShowStr(10,0,"KM/h"); |
|
|
66 2 |
|
|
67 2 LcdShowStr(0,1,"L:"); |
|
|
68 2 Lcd1602_Write_Data(journey/10000%10+0x30); |
|
|
69 2 Lcd1602_Write_Data(journey/1000%10+0x30); |
|
|
70 2 Lcd1602_Write_Data(journey/100%10+0x30); |
|
|
71 2 Lcd1602_Write_Data(journey/10%10+0x30); |
|
|
72 2 Lcd1602_Write_Data(journey%10+0x30); |
|
|
73 2 LcdShowStr(7,1,"M"); |
|
|
74 2 |
|
|
75 2 if(journey>1000) |
|
|
76 2 { |
|
|
77 3 money=(journey-1000)*0.002+7; |
|
|
78 3 At24c02Write(5,money); |
|
|
79 3 } |
|
|
80 2 money=money*10; |
|
|
81 2 LcdShowStr(9,1,"Q:"); |
|
|
82 2 Lcd1602_Write_Data(money/1000%10+0x30); |
|
|
83 2 Lcd1602_Write_Data(money/100%10+0x30); |
|
|
84 2 Lcd1602_Write_Data(money/10%10+0x30); |
|
|
85 2 LcdShowStr(14,1,"."); |
|
|
86 2 Lcd1602_Write_Data(money%10+0x30); |
|
|
87 2 |
|
|
88 2 money=money/10; |
|
|
89 2 |
|
|
90 2 } |
|
|
91 1 } |
|
|
92 |
|
|
93 |
|
|
94 |
|
|
95 void keypros() |
|
|
96 { |
|
|
97 1 if(k2==0) |
|
|
98 1 { |
|
|
99 2 delay11(1000); //消抖处理 |
|
|
100 2 if(k2==0) |
|
|
101 2 { |
|
|
102 3 sudu=At24c02Read(10); //读取EEPROM地址1内的数据 |
|
|
103 3 |
|
|
104 3 b2=At24c02Read(1); |
|
|
105 3 c2=At24c02Read(8); |
|
|
106 3 journey=(b2<<8) | c2; |
|
|
107 3 |
|
|
108 3 money=At24c02Read(5); |
|
|
109 3 |
|
|
110 3 } |
|
|
111 2 while(!k2); |
|
|
112 2 } |
|
|
113 1 |
|
|
114 1 if(k1==0) |
|
|
115 1 { |
|
|
116 2 delay11(1000); //消抖处理 |
|
|
117 2 if(k1==0) |
|
|
C51 COMPILER V9.56.0.0 IRIN 04/06/2022 23:56:38 PAGE 3 |
|
|
|
|
|
118 2 { |
|
|
119 3 flas=1; |
|
|
120 3 |
|
|
121 3 } |
|
|
122 2 while(!k1); |
|
|
123 2 } |
|
|
124 1 if(k4==0) |
|
|
125 1 { |
|
|
126 2 delay11(1000); //消抖处理 |
|
|
127 2 if(k4==0) |
|
|
128 2 { |
|
|
129 3 if(pwm_left>=20) |
|
|
130 3 { |
|
|
131 4 pwm_left=1; |
|
|
132 4 } |
|
|
133 3 else |
|
|
134 3 { |
|
|
135 4 pwm_left++; |
|
|
136 4 } |
|
|
137 3 } |
|
|
138 2 while(!k4); |
|
|
139 2 } |
|
|
140 1 |
|
|
141 1 } |
|
|
142 |
|
|
143 void time0() interrupt 1 //定时器 0 |
|
|
144 { |
|
|
145 1 TH0=0x3C; |
|
|
146 1 TL0=0xb0; //50ms定时 |
|
|
147 1 ms++; //变量50ms加一 |
|
|
148 1 if(ms%5==0) s0=~s0; |
|
|
149 1 |
|
|
150 1 |
|
|
151 1 if(ms%10==0) //500ms定时 |
|
|
152 1 { |
|
|
153 2 |
|
|
154 2 if(sec!=0) sec--; |
|
|
155 2 if(sec1!=0) sec1--; |
|
|
156 2 ms=0; //清零变量 |
|
|
157 2 EX1=0; //关闭外部中断,保证变量在计算的时候不会增加 |
|
|
158 2 r_s=count; //因为是500ms检测一次转动数据,所以要想一秒转动的圈数是 speed=count*2 ,但是光栅是一圈2 |
|
|
-0格,所以还要除以20; |
|
|
159 2 //综合一下,一秒转动的圈数就是 speed=count*2/20 ==》 speed=counr/10; |
|
|
160 2 count=0; //清零变量 |
|
|
161 2 EX1=1; //打开外部中断 |
|
|
162 2 speed=speed*0.5+(r_s*6)*0.5; // 这里r_s是一秒走的圈数,然后乘以60得到60秒走的圈数,单位变成了 |
|
|
- r/min; 总方式 speed=count/10*60; ==>> speed=count*6; |
|
|
163 2 |
|
|
164 2 if(flas==0) |
|
|
165 2 { |
|
|
166 3 sudu=(0.15*speed); |
|
|
167 3 At24c02Write(10,sudu); |
|
|
168 3 |
|
|
169 3 journey=journey+(r_s*2.5/20); |
|
|
170 3 journey1=journey; |
|
|
171 3 c = journey & 0x00FF; |
|
|
172 3 At24c02Write(8,c); |
|
|
173 3 |
|
|
174 3 delay11(1000); |
|
|
175 3 b=journey1>>8; |
|
|
176 3 At24c02Write(1,b); |
|
|
177 3 } |
|
|
C51 COMPILER V9.56.0.0 IRIN 04/06/2022 23:56:38 PAGE 4 |
|
|
|
|
|
178 2 else |
|
|
179 2 { |
|
|
180 3 journey=0; |
|
|
181 3 money=7; |
|
|
182 3 At24c02Write(1,journey); |
|
|
183 3 At24c02Write(8,journey); |
|
|
184 3 At24c02Write(5,money); |
|
|
185 3 flas=0; |
|
|
186 3 } |
|
|
187 2 } |
|
|
188 1 } |
|
|
189 |
|
|
190 void int1() interrupt 2 //外部中断 1 |
|
|
191 { |
|
|
192 1 |
|
|
193 1 count++; //中断每触发一次,变量加一 |
|
|
194 1 |
|
|
195 1 } |
|
|
196 |
|
|
197 |
|
|
198 |
|
|
199 |
|
|
200 |
|
|
201 |
|
|
202 |
|
|
|
|
|
|
|
|
MODULE INFORMATION: STATIC OVERLAYABLE |
|
|
CODE SIZE = 1006 ---- |
|
|
CONSTANT SIZE = 22 ---- |
|
|
XDATA SIZE = ---- ---- |
|
|
PDATA SIZE = ---- ---- |
|
|
DATA SIZE = 25 ---- |
|
|
IDATA SIZE = ---- ---- |
|
|
BIT SIZE = 3 ---- |
|
|
END OF MODULE INFORMATION. |
|
|
|
|
|
|
|
|
C51 COMPILATION COMPLETE. 0 WARNING(S), 0 ERROR(S)
|
|
|
|