• 基于51单片机出租车计费设计(proteus仿真+程序+原理图+设计说明书)


    基于51单片机出租车计费仿真设计(proteus仿真+程序+原理图+设计说明书)

    仿真图proteus 7.8

    程序编译器:keil 4/keil 5

    编程语言:C语言

    设计编号:C0050

    功能说明

    51单片机 + 1302时钟芯片准确计时 + LCD1602液晶显示 + 24c02芯片可以掉电存储数据 + 3v直流电机模拟发动机工作。

    1、当无乘客时液晶可以显示时间(年月日时分秒),时间可以按键设置,此时电机不工作;

    2、当有乘客时电机工作,可以通过按键开始计费系统工作,有清零键,收费可以修改(包括起价费、超过起价费每公里或分钟收费、白天和夜晚收费标准);

    3、可以切换白天和夜晚收费标准,可以按照分钟或公里收费切换。

    仿真图

    imgimg

    程序

    img

    //出租车计价器
    //宏定义
    #define uchar unsigned char
    #define uint unsigned int 
    
    //头函数声明
    #include 
    #include "Lcd.h"
    #include "Data.h"
    #include "DS1302.h"
    #include "AT24C02.h"
    
    
    //键盘定义
    sbit K1=P3^4;	//模式切换
    sbit K2=P3^6;	//减按键
    sbit K3=P3^5;	//加按键
    sbit K4=P3^7;	//万年历模式时:设置时间信息。计价器模式时:设置单价
    
    //模式0时钟 1时钟调整			   			
    uchar Mode=0;
    //时钟屏幕调整
    uchar Wei=0;
    uchar SS=0;
    //价格调整
    uchar JGWei=0;
    
    //计价器参数
    uint Day=0;
    uint Night=0;
    uint DanJia=0;
    uint DJ_min=0;
    uint  ZJ=0;
    unsigned long  GL=0;
    uint  Time=0;
    uint count=0;
    uchar m=0;
    //白天/晚上
    uchar DN=0;
    //公里/时间
    uchar GT=0;
    
    //初始化函数
    void InitTimer0();
    //写初值
    void SETS();
    //读初值
    void READS();
    
    //主函数
    void main()
    {
    	//初始化
    	Ds1302_Init();
    	Init_LCD();
    	initeeprom();
    	//SETS();
    	//读取初始参数
    	READS();
    	//定时器初始化
    	InitTimer0();
    	//循环
    	while(1)
    	{
    		//时钟模式
    		if(Mode==0)
    		{
    			//读时间
    			if(Wei==0)
    			{
    				Ds1302_Read_Time();
    				//显示时间
    				display_NYR(time_buf1,Wei,0);
    			}
    		}
    		else if(Mode==1)
    		{
    			if(time_buf1[4]>=23||time_buf1[4]<7)  
    			DN=1;
    			else
    			DN=0;
    			//显示计价器信息
    			
    			display_S(Day,Night,DanJia,ZJ,GL/10,Time,GT,DN);
    		}
    
    
    		if(K4==0)
    		{
    			delay(100);
    			//调时
    			if(Mode==0)
    			{
    				Wei++;
    				if(Wei==1)
    				{
    					SS=1;
    				}
    				//闪烁
    				display_NYR(time_buf1,Wei,SS);
    				if(Wei==7)
    				{
    					Wei=0;
    					//保存时间
    					Ds1302_Write_Time();
    					Init_LCD();
    				}
    			}
    			else if(Mode==1)
    			{
    				JGWei++;
    				if(JGWei==1)
    				{
    					Mode=2;
    					//显示计价器价格
    					Init_LCD_JGTZ();
    					display_D(Day,Night,DanJia,JGWei,DJ_min);
    				}
    			}
    			else if(Mode==2)
    			{	
    				JGWei++;	
    				display_D(Day,Night,DanJia,JGWei,DJ_min);
    				if(JGWei==5)
    				{
    					Mode=1;
    					JGWei=0;
    					//参数初始化
    					//保存
    					SETS();
    					//读初值
    					READS();
    	
    					ZJ=0;
    					GL=0;
    					Time=0;
    					//开启定时器
    					TR0=1;
    					//显示计价器
    					Init_LCD_JJQ();
    				}
    			}
    			while(K4==0);
    		}
    		//+
    		if(K3==0)
    		{
    			delay(100);
    			//调时
    			if(Mode==0)
    			{
    				//年
    				if(Wei==1)
    				{
    					time_buf1[1]++;
    					if(time_buf1[1]>=100)
    						time_buf1[1]=0;
    				}
    				//月
    				else if(Wei==2)
    				{
    					time_buf1[2]++;
    					if(time_buf1[2]>=13)
    						time_buf1[2]=1;
    				}
    				//日
    				else if(Wei==3)
    				{
    					time_buf1[3]++;
    					if(time_buf1[3]>=YDay(time_buf1[1],time_buf1[2])+1)
    						time_buf1[3]=1;
    				}	
    				//时
    				else if(Wei==4)
    				{
    					time_buf1[4]++;
    					if(time_buf1[4]>=24)
    						time_buf1[4]=0;
    				}	
    				//分
    				else if(Wei==5)
    				{
    					time_buf1[5]++;
    					if(time_buf1[5]>=60)
    						time_buf1[5]=0;
    				}
    				//秒
    				else if(Wei==6)
    				{
    					time_buf1[6]++;
    					if(time_buf1[6]>=60)
    						time_buf1[6]=0;
    				}
    				//显示
    				if(Wei!=0)
    					display_NYR(time_buf1,Wei,SS);			
    			}
    			//调价
    			else if(Mode==2)
    			{
    				//单价
    				if(JGWei==1)
    				{
    					DanJia++;
    					if(DanJia>999)
    					{
    						DanJia=1;
    					}
    				}
    				//等待时间单价
    				else if(JGWei==2)
    				{
    					DJ_min++;
    					if(DJ_min>999)
    					{
    						DJ_min=1;
    					}
    				}
    				//夜间
    				else if(JGWei==3)
    				{
    					Night++;
    					if(Night>999)
    					{
    						Night=1;
    					}
    				}
    				//白天
    				else if(JGWei==4)
    				{
    					Day++;
    					if(Day>999)
    					{
    						Day=1;
    					}
    				}
    				display_D(Day,Night,DanJia,JGWei,DJ_min);
    			}
    
    			while(K3==0);
    		}
    
    		//-
    		if(K2==0)
    		{
    			delay(100);
    			//调时
    			if(Mode==0)
    			{
    				//年
    				if(Wei==1)
    				{
    					time_buf1[1]--;
    					if(time_buf1[1]<0)
    						time_buf1[1]=99;
    				}
    				//月
    				else if(Wei==2)
    				{
    					time_buf1[2]--;
    					if(time_buf1[2]<=0)
    						time_buf1[2]=12;
    				}
    				//日
    				else if(Wei==3)
    				{
    					time_buf1[3]--;
    					if(time_buf1[3]<=0)
    						time_buf1[3]=YDay(time_buf1[1],time_buf1[2]);
    				}	
    				//时
    				else if(Wei==4)
    				{
    					time_buf1[4]--;
    					if(time_buf1[4]<0)
    						time_buf1[4]=23;
    				}	
    				//分
    				else if(Wei==5)
    				{
    					time_buf1[5]--;
    					if(time_buf1[5]<0)
    						time_buf1[5]=59;
    				}
    				//秒
    				else if(Wei==6)
    				{
    					time_buf1[6]--;
    					if(time_buf1[6]<0)
    						time_buf1[6]=59;
    				}
    				//显示
    				if(Wei!=0)
    					display_NYR(time_buf1,Wei,SS);			
    			}
    			//调价
    			else if(Mode==2)
    			{
    				//单价
    				if(JGWei==1)
    				{
    					DanJia--;
    					if(DanJia==0)
    					{
    						DanJia=999;
    					}
    				}
    				//等待时间单价
    				else if(JGWei==2)
    				{
    					DJ_min--;
    					if(DJ_min==0)
    					{
    						DJ_min=999;
    					}
    				}
    				//夜间
    				else if(JGWei==3)
    				{
    					Night--;
    					if(Night==0)
    					{
    						Night=999;
    					}
    				}
    				//白天
    				else if(JGWei==4)
    				{
    					Day--;
    					if(Day==0)
    					{
    						Day=999;
    					}
    				}
    				display_D(Day,Night,DanJia,JGWei,DJ_min);
    			}
    			while(K2==0);
    		}	
    		//切换
    		if(K1==0)
    		{
    			delay(100);
    			//计价器模式
    			if(Mode==1)
    			{
    				Mode=0;
    				ZJ=0;
    				GL=0;
    				Time=0;
    				//开启定时器
    				TR0=0;
    				EX0=0;
    				//显示计价器
    				Init_LCD();
    			}
    			else if(Mode==0)
    			{
    				Mode=1;
    				//参数初始化
    				//读初值
    				READS();
    				ZJ=0;
    				GL=0;
    				Time=0;
    				//开启定时器
    				m=0;
    				TR0=1;
    				EX0=1;
    				//显示计价器
    				Init_LCD_JJQ();
    			}
    			while(K1==0);
    		}
    	}
    }
    
    //初始化函数
    void InitTimer0(void)
    {
        TMOD = 0x01;
        TH0 = 0x3C;
        TL0 = 0xB0;		//10ms
        EA = 1;
        ET0 = 1;
        TR0 = 1;
    	IT0=1;	//INT0负跳变触发
    	EX0=0;//开外部INTO中断
    }
    
    //定时器0中断10ms
    void Timer0Interrupt(void) interrupt 1
    {
        TH0 = 0x3C;
        TL0 = 0xB0;   //赋初值
    	m++;
    	if(m>=20)
    	{
    		m=0;
    		if(count>=60)
    		{
    			GT=0;
    			GL=GL+count/10;
    			count=0;
    		}
    		else
    		{
    			count=0;
    			GT=1;
    			Time++;	 //时间++
    		}
    	}
    	 //计算钱数
    	 //公里数小于3
    	 if(GL<=300)
    	 {
    		if(DN==0)
    		{
    			if(Time>60)
    				ZJ=Day+Time/60*DJ_min;
    			else
    				ZJ=Day;
    		}	
    		else
    		{
    			if(Time>60)
    				ZJ=Night+Time/60*DJ_min;
    			else
    				ZJ=Night;
    		}
    	 }
    	 else
    	 {
    		if(DN==0)
    		{
    			if(Time>60)
    				ZJ=Day+(GL/10-20)/10*DanJia+Time/60*DJ_min;
    			else
    				ZJ=Day+(GL/10-20)/10*DanJia;
    
    		}	
    		else
    		{
    			if(Time>60)
    				ZJ=Night+(GL/10-20)/10*DanJia+Time/60*DJ_min;
    			else
    				ZJ=Night+(GL/10-20)/10*DanJia;
    		}
    	 }
    }
    void EXINT0() interrupt 0
    {
    	count++;
    }
    
    //读初值
    void READS()
    {
    	uchar SH=0,SL=0;
    	uint temp=0;
    
    	delay(10);
    	SL=read_add(0x01);
    	delay(10);
    	SH=read_add(0x02);
    	temp=SH;
    	temp=temp<<8;
    	temp=temp+SL;
    	Day=temp;
    
    	delay(10);
    	SL=read_add(0x03);
    	delay(10);
    	SH=read_add(0x04);
    	temp=SH;
    	temp=temp<<8;
    	temp=temp+SL;
    	Night=temp;
    
    	delay(10);
    	SL=read_add(0x05);
    	delay(10);
    	SH=read_add(0x06);
    	temp=SH;
    	temp=temp<<8;
    	temp=temp+SL;
    	DanJia=temp;
    
    	delay(10);
    	SL=read_add(0x07);
    	delay(10);
    	SH=read_add(0x08);
    	temp=SH;
    	temp=temp<<8;
    	temp=temp+SL;
    	DJ_min=temp;
    }
    
    
    //写初值
    void SETS()
    {
    	uchar SH=0,SL=0;
    	uint temp=0;
    
    	temp=Day;
    	SL=temp&0x00ff;
    	SH=temp>>8;
    	delay(10);
    	write_add(0x01,SL);
    	delay(10);
    	write_add(0x02,SH);
    
    	temp=Night;
    	SL=temp&0x00ff;
    	SH=temp>>8;
    	delay(10);
    	write_add(0x03,SL);
    	delay(10);
    	write_add(0x04,SH); 
    
    	temp=DanJia;
    	SL=temp&0x00ff;
    	SH=temp>>8;
    	delay(10);
    	write_add(0x05,SL);
    	delay(10);
    	write_add(0x06,SH);
    
    	temp=DJ_min;
    	SL=temp&0x00ff;
    	SH=temp>>8;
    	delay(10);
    	write_add(0x07,SL);
    	delay(10);
    	write_add(0x08,SH);
    }
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
    • 54
    • 55
    • 56
    • 57
    • 58
    • 59
    • 60
    • 61
    • 62
    • 63
    • 64
    • 65
    • 66
    • 67
    • 68
    • 69
    • 70
    • 71
    • 72
    • 73
    • 74
    • 75
    • 76
    • 77
    • 78
    • 79
    • 80
    • 81
    • 82
    • 83
    • 84
    • 85
    • 86
    • 87
    • 88
    • 89
    • 90
    • 91
    • 92
    • 93
    • 94
    • 95
    • 96
    • 97
    • 98
    • 99
    • 100
    • 101
    • 102
    • 103
    • 104
    • 105
    • 106
    • 107
    • 108
    • 109
    • 110
    • 111
    • 112
    • 113
    • 114
    • 115
    • 116
    • 117
    • 118
    • 119
    • 120
    • 121
    • 122
    • 123
    • 124
    • 125
    • 126
    • 127
    • 128
    • 129
    • 130
    • 131
    • 132
    • 133
    • 134
    • 135
    • 136
    • 137
    • 138
    • 139
    • 140
    • 141
    • 142
    • 143
    • 144
    • 145
    • 146
    • 147
    • 148
    • 149
    • 150
    • 151
    • 152
    • 153
    • 154
    • 155
    • 156
    • 157
    • 158
    • 159
    • 160
    • 161
    • 162
    • 163
    • 164
    • 165
    • 166
    • 167
    • 168
    • 169
    • 170
    • 171
    • 172
    • 173
    • 174
    • 175
    • 176
    • 177
    • 178
    • 179
    • 180
    • 181
    • 182
    • 183
    • 184
    • 185
    • 186
    • 187
    • 188
    • 189
    • 190
    • 191
    • 192
    • 193
    • 194
    • 195
    • 196
    • 197
    • 198
    • 199
    • 200
    • 201
    • 202
    • 203
    • 204
    • 205
    • 206
    • 207
    • 208
    • 209
    • 210
    • 211
    • 212
    • 213
    • 214
    • 215
    • 216
    • 217
    • 218
    • 219
    • 220
    • 221
    • 222
    • 223
    • 224
    • 225
    • 226
    • 227
    • 228
    • 229
    • 230
    • 231
    • 232
    • 233
    • 234
    • 235
    • 236
    • 237
    • 238
    • 239
    • 240
    • 241
    • 242
    • 243
    • 244
    • 245
    • 246
    • 247
    • 248
    • 249
    • 250
    • 251
    • 252
    • 253
    • 254
    • 255
    • 256
    • 257
    • 258
    • 259
    • 260
    • 261
    • 262
    • 263
    • 264
    • 265
    • 266
    • 267
    • 268
    • 269
    • 270
    • 271
    • 272
    • 273
    • 274
    • 275
    • 276
    • 277
    • 278
    • 279
    • 280
    • 281
    • 282
    • 283
    • 284
    • 285
    • 286
    • 287
    • 288
    • 289
    • 290
    • 291
    • 292
    • 293
    • 294
    • 295
    • 296
    • 297
    • 298
    • 299
    • 300
    • 301
    • 302
    • 303
    • 304
    • 305
    • 306
    • 307
    • 308
    • 309
    • 310
    • 311
    • 312
    • 313
    • 314
    • 315
    • 316
    • 317
    • 318
    • 319
    • 320
    • 321
    • 322
    • 323
    • 324
    • 325
    • 326
    • 327
    • 328
    • 329
    • 330
    • 331
    • 332
    • 333
    • 334
    • 335
    • 336
    • 337
    • 338
    • 339
    • 340
    • 341
    • 342
    • 343
    • 344
    • 345
    • 346
    • 347
    • 348
    • 349
    • 350
    • 351
    • 352
    • 353
    • 354
    • 355
    • 356
    • 357
    • 358
    • 359
    • 360
    • 361
    • 362
    • 363
    • 364
    • 365
    • 366
    • 367
    • 368
    • 369
    • 370
    • 371
    • 372
    • 373
    • 374
    • 375
    • 376
    • 377
    • 378
    • 379
    • 380
    • 381
    • 382
    • 383
    • 384
    • 385
    • 386
    • 387
    • 388
    • 389
    • 390
    • 391
    • 392
    • 393
    • 394
    • 395
    • 396
    • 397
    • 398
    • 399
    • 400
    • 401
    • 402
    • 403
    • 404
    • 405
    • 406
    • 407
    • 408
    • 409
    • 410
    • 411
    • 412
    • 413
    • 414
    • 415
    • 416
    • 417
    • 418
    • 419
    • 420
    • 421
    • 422
    • 423
    • 424
    • 425
    • 426
    • 427
    • 428
    • 429
    • 430
    • 431
    • 432
    • 433
    • 434
    • 435
    • 436
    • 437
    • 438
    • 439
    • 440
    • 441
    • 442
    • 443
    • 444
    • 445
    • 446
    • 447
    • 448
    • 449
    • 450
    • 451
    • 452
    • 453
    • 454
    • 455
    • 456
    • 457
    • 458
    • 459
    • 460
    • 461
    • 462
    • 463
    • 464
    • 465
    • 466
    • 467
    • 468
    • 469
    • 470
    • 471
    • 472
    • 473
    • 474
    • 475
    • 476
    • 477
    • 478
    • 479
    • 480
    • 481
    • 482
    • 483
    • 484
    • 485
    • 486
    • 487
    • 488
    • 489
    • 490
    • 491
    • 492
    • 493
    • 494
    • 495
    • 496
    • 497
    • 498
    • 499
    • 500
    • 501
    • 502
    • 503
    • 504
    • 505
    • 506
    • 507
    • 508
    • 509
    • 510
    • 511
    • 512
    • 513
    • 514
    • 515
    • 516
    • 517
    • 518
    • 519
    • 520
    • 521
    • 522
    • 523
    • 524
    • 525
    • 526
    • 527
    • 528
    • 529
    • 530
    • 531
    • 532
    • 533
    • 534
    • 535
    • 536
    • 537

    原理图

    img

    设计说明书

    img

    摘要

    ​ 出租车行业在我国是八十年代初兴起的一项新兴行业,随着我国国民经济的高速发展,出租汽车已成为城市公共交通的重要组成部分。多年来国内普遍使用的计价器只具备单一的计量功能。目前全世界的计价器中有90%为台湾所生产。现在各个城市出租车行业都已普及,因此出租车计价器的技术已经成熟,但是出租车计价器的市场还具有广阔的前景。随着城市建设的日益完善,关乎城市面貌的出租车行业也将迅速发展,出租车计价器的的大批量需求也是毫无疑问的,所以未来出租车计价器的市场还是有相当大的潜力。

    ​ 本次出租车计价器设计可以分为六个模块,主控模块、计时模块、存储模块、显示模块、按键模块和电机驱动模块。本设计采用STC89C52单片机作为主控模块的主控芯片,结合单片机的外围电路实现对整个系统的控制,DS1302时钟芯片准确计时具有重新上电不用调时的功能,显示部分采用LCD1602液晶显示,24c02芯片可以掉电存储设置的计费数据,即使掉电也不会丢失设置的费用,3v直流电机模拟发动机工作,使整个设计更加逼真,当无乘客时液晶可以显示时间(年月日时分秒),时间可以按键设置,此时电机不工作;当有乘客时电机工作,可以通过按键开始计费系统工作,有清零键,收费可以修改(包括起价费、超过起价费每公里或分钟收费、白天和夜晚收费标准),可以切换白天和夜晚收费标准,可以按照分钟或公里收费切换。汽车计价器是乘客与司机双方的交易准则,它是出租车行业发展的重要标志,是出租车中最重要的工具。它关系着交易双方的利益。具有良好性能的计价器无论是对广大出租车司机朋友还是乘客来说都是很必要的。因此,汽车计价器的研究也是有一定的应用价值的。

    设计清单(提供资料清单所有文件)

    资料下载

    img

  • 相关阅读:
    模拟面试01
    计算机毕业设计ssm基于JAVA的食品类购物系统q645b系统+程序+源码+lw+远程部署
    《016.SpringBoot+vue校园社团管理系统》【有文档】
    6.netty线程模型-Reactor
    前缀和实例1 (【模板】前缀和 )
    案例分享:原生广告如何助力app实现高效变现收益的转化
    MySQL2:MySQL中一条查询SQL是如何执行的?
    Haproxy的ACL配置及案例
    冥想第六百二十四天
    多线程之ThreadPoolExecutor
  • 原文地址:https://blog.csdn.net/weixin_52733843/article/details/126476016