C51 COMPILER V9.56.0.0 IRIN 04/06/2022 21:56:10 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;//定时器1工作方式1 42 1 TH0=0x3C; 43 1 TL0=0xb0; 44 1 ET0=1; 45 1 TH1=0XFc; 46 1 TL1=0X18; 47 1 ET1=1; 48 1 TR1=1; 49 1 TR0=1; 50 1 EA=1; 51 1 EX1=1; 52 1 IT1=1; 53 1 54 1 } 55 C51 COMPILER V9.56.0.0 IRIN 04/06/2022 21:56:10 PAGE 2 56 void display() 57 { 58 1 if(state==0) 59 1 { 60 2 sudu=At24c02Read(10); 61 2 if(money>7) 62 2 { 63 3 money=At24c02Read(5); 64 3 } 65 2 LcdSetCursor(0,0); 66 2 LcdShowStr(0,0,"Speed:"); 67 2 Lcd1602_Write_Data(0x30+sudu/100%10); 68 2 Lcd1602_Write_Data(0x30+sudu/10%10); 69 2 Lcd1602_Write_Data(0x30+sudu%10); 70 2 LcdShowStr(10,0,"KM/h"); 71 2 72 2 LcdShowStr(0,1,"L:"); 73 2 Lcd1602_Write_Data(journey/10000%10+0x30); 74 2 Lcd1602_Write_Data(journey/1000%10+0x30); 75 2 Lcd1602_Write_Data(journey/100%10+0x30); 76 2 Lcd1602_Write_Data(journey/10%10+0x30); 77 2 Lcd1602_Write_Data(journey%10+0x30); 78 2 LcdShowStr(7,1,"M"); 79 2 80 2 if(journey>1000) 81 2 { 82 3 money=(journey-1000)*0.002+7; 83 3 At24c02Write(5,money); 84 3 } 85 2 money=money*10; 86 2 LcdShowStr(9,1,"Q:"); 87 2 Lcd1602_Write_Data(money/1000%10+0x30); 88 2 Lcd1602_Write_Data(money/100%10+0x30); 89 2 Lcd1602_Write_Data(money/10%10+0x30); 90 2 LcdShowStr(14,1,"."); 91 2 Lcd1602_Write_Data(money%10+0x30); 92 2 93 2 money=money/10; 94 2 95 2 96 2 } 97 1 } 98 99 100 101 void keypros() 102 { 103 1 if(k2==0) 104 1 { 105 2 delay11(1000); //消抖处理 106 2 if(k2==0) 107 2 { 108 3 sudu=At24c02Read(10); //读取EEPROM地址1内的数据 109 3 110 3 b2=At24c02Read(1); 111 3 c2=At24c02Read(8); 112 3 journey=(b2<<8) | c2; 113 3 114 3 money=At24c02Read(5); 115 3 116 3 } 117 2 while(!k2); C51 COMPILER V9.56.0.0 IRIN 04/06/2022 21:56:10 PAGE 3 118 2 } 119 1 120 1 if(k1==0) 121 1 { 122 2 delay11(1000); //消抖处理 123 2 if(k1==0) 124 2 { 125 3 flas=1; 126 3 127 3 } 128 2 while(!k1); 129 2 } 130 1 if(k4==0) 131 1 { 132 2 delay11(1000); //消抖处理 133 2 if(k4==0) 134 2 { 135 3 if(pwm_left>=20) 136 3 { 137 4 pwm_left=1; 138 4 } 139 3 else 140 3 { 141 4 pwm_left++; 142 4 } 143 3 } 144 2 while(!k4); 145 2 } 146 1 147 1 } 148 149 void time0() interrupt 1 //定时器 0 150 { 151 1 TH0=0x3C; 152 1 TL0=0xb0; //50ms定时 153 1 ms++; //变量50ms加一 154 1 if(ms%5==0) s0=~s0; 155 1 156 1 157 1 if(ms%10==0) //500ms定时 158 1 { 159 2 160 2 if(sec!=0) sec--; 161 2 if(sec1!=0) sec1--; 162 2 ms=0; //清零变量 163 2 EX1=0; //关闭外部中断,保证变量在计算的时候不会增加 164 2 r_s=count; //因为是500ms检测一次转动数据,所以要想一秒转动的圈数是 speed=count*2 ,但是光栅是一圈2 -0格,所以还要除以20; 165 2 //综合一下,一秒转动的圈数就是 speed=count*2/20 ==》 speed=counr/10; 166 2 count=0; //清零变量 167 2 EX1=1; //打开外部中断 168 2 speed=speed*0.5+(r_s*6)*0.5; // 这里r_s是一秒走的圈数,然后乘以60得到60秒走的圈数,单位变成了 - r/min; 总方式 speed=count/10*60; ==>> speed=count*6; 169 2 170 2 if(flas==0) 171 2 { 172 3 sudu=(0.15*speed); 173 3 At24c02Write(10,sudu); 174 3 175 3 journey=journey+(r_s*2.5/20); 176 3 journey1=journey; 177 3 c = journey & 0x00FF; C51 COMPILER V9.56.0.0 IRIN 04/06/2022 21:56:10 PAGE 4 178 3 At24c02Write(8,c); 179 3 180 3 delay11(1000); 181 3 b=journey1>>8; 182 3 At24c02Write(1,b); 183 3 } 184 2 else 185 2 { 186 3 journey=0; 187 3 money=7; 188 3 At24c02Write(1,journey); 189 3 At24c02Write(8,journey); 190 3 At24c02Write(5,money); 191 3 flas=0; 192 3 } 193 2 } 194 1 } 195 196 void int1() interrupt 2 //外部中断 1 197 { 198 1 199 1 count++; //中断每触发一次,变量加一 200 1 201 1 } 202 203 204 205 206 207 208 MODULE INFORMATION: STATIC OVERLAYABLE CODE SIZE = 1016 ---- 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)