單片機出租車計價器程序及原理圖
《單片機出租車計價器程序及原理圖》由會員分享,可在線閱讀,更多相關《單片機出租車計價器程序及原理圖(11頁珍藏版)》請在裝配圖網(wǎng)上搜索。
1、#include
2、0 //X方向,半屏64列,0 1 C5 C4 C3 C2 C1 C0 ,0到63列選擇 /*P2+P0口16位編址,有效位是P2.3~P2.0,無關位用“1”表示 P2.0--RS,P2.1--RW,P2.2--CS2,P2.3--CS1 右屏命令和數(shù)據(jù)讀寫編址 CS2 CS1 RW RS*/ #define LLCD_CMD_WR XBYTE[0xf4ff] //0 1 0 0 #define LLCD_DAT_WR XBYTE[0xf5ff] //0 1 0 1 #define LLCD_CMD_RD XBYTE[0x
3、f6ff] //0 1 1 0 #define LLCD_DAT_RD XBYTE[0xf7ff] //0 1 1 1 /*左屏命令和數(shù)據(jù)讀寫編址*/ #define RLCD_CMD_WR XBYTE[0xf8ff] //1 0 0 0 #define RLCD_DAT_WR XBYTE[0xf9ff] //1 0 0 1 #define RLCD_CMD_RD XBYTE[0xfaff] //1 0 1 0 #define RLCD_DAT_RD XBYTE[0xfbff] //1 0 1
4、 1 /**********************數(shù)據(jù)坐標記錄************************** 左-路程:整數(shù)部分 x=9,y=1,小數(shù)部分 x=31,y=1 左-路程費用:整數(shù)部分 x=9,y=3,小數(shù)部分 x=31,y=3 總費用:整數(shù)部分-左:x=45,y=5 路程單價:x=34,y=7 右-時間:整數(shù)部分 x=20,y=1 右-時間費用:整數(shù)部分 x=10,y=3,小數(shù)部分 x=32,y=3 總費用:小數(shù)部分-右:x=2,y=5 時間單價:x=44,y=7 ***************************************
5、**********************/ #define L_Mile_X_Z 9 #define L_Mile_X_D 30 #define L_Mile_Y 1 #define L_Cost_X_Z 9 #define L_Cost_X_D 30 #define L_Cost_Y 3 #define L_Total_X 45 #define L_Total_Y 5 #define L_Unit_X 34 #define L_Unit_Y 7 #define R_Time_X 20 #define R_Time_Y
6、 1 #define R_Cost_X_Z 10 #define R_Cost_X_D 31 #define R_Cost_Y 3 #define R_Total_X 2 #define R_Total_Y 5 #define R_Unit_X 44 #define R_Unit_Y 7 sbit LED=P2^7 ; sbit START=P1^0; sbit STOP=P1^1; sbit CLEAR=P1^2; sbit MUINT_UP=P1^4; sbit MUINT_D=P1^5; sbit TUINT_UP=
7、P1^6; sbit TUINT_D=P1^7; uchar Mile_Unit=4,Time_Unit=2; long time_cost,time_cost_Z,time_cost_D,time_con_s,time_con_m; long mile_cost,mile_cost_Z,mile_cost_D,mile_con_m,mile_con_km; long speed_con,speed_con_m,speed,speed_flag,cost_flag; long total_z=5,total_d; code char shu[10][6]={ 0x
8、3E,0x41,0x41,0x41,0x3E,0x00, //0 0x00,0x42,0x7F,0x40,0x00,0x00, //1 0x42,0x61,0x51,0x49,0x46,0x00, //2 0x22,0x41,0x49,0x49,0x36,0x00, //3 0x38,0x24,0x22,0x7F,0x20,0x00, //4 0x27,0x45,0x45,0x45,0x39,0x00, //5 0x3E,0x45,0x45,0x45,0x38,0x00, //6 0x01,0x01,0x79,0x05,0x03,0x00, //7
9、 0x36,0x49,0x49,0x49,0x36,0x00, //8 0x0E,0x51,0x51,0x51,0x3E,0x00, //9 }; /*************************初始化界面*****************************/ code uchar logo[]= { 0xFF,0x07,0x03,0xE1,0x11,0x09,0x09,0x09,0x08,0x09,0x09,0x09,0x09,0x09,0x09,0x09, 0x08,0x09,0x09,0x09,0x09,0x09,0x09,0x09,0x08,0x09,
10、0x09,0x09,0x09,0x09,0x09,0x09, 0x08,0x09,0x09,0x09,0x09,0x09,0x09,0x09,0x08,0x09,0x09,0x09,0x09,0x09,0x09,0x09, 0x08,0x09,0x09,0x09,0x09,0x09,0x09,0x09,0x08,0x09,0x09,0x11,0xE1,0x03,0x07,0xFF, 0xFF,0x07,0x03,0xE1,0x11,0x09,0x09,0x09,0x08,0x09,0x09,0x09,0x09,0x09,0x09,0x09, 0x08,0x09,0x09,0x09,0x
11、09,0x09,0x09,0x09,0x08,0x09,0x09,0x09,0x09,0x09,0x09,0x09, 0x08,0x09,0x09,0x09,0x09,0x09,0x09,0x09,0x08,0x09,0x09,0x09,0x09,0x09,0x09,0x09, 0x08,0x09,0x09,0x09,0x09,0x09,0x09,0x09,0x08,0x09,0x09,0x11,0xE1,0x03,0x07,0xFF, 0xFE,0x00,0x00,0xFF,0x00,0x7E,0x3C,0x18,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0
12、x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xC0,0xC0,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0xFE,0x10,0x28,0x44,0x82,0x00,0xF8,0x08,0xF8,0x08,0xF8,0x00,0xFF,0x00,0x00,0xFF, 0xFF,0x00,0x00,0xFF,0x00,0x7E,0x3C,0x18,0x00,0x0
13、0,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFE,0x04, 0xF8,0x04,0xFE,0x00,0xF4,0x00,0xF8,0x08,0xF8,0x08,0xF8,0x00,0xFF,0x00,0x00,0xFE, 0xFE,0x00,0x00,0xFF,
14、0x00,0x00,0x00,0x00,0x00,0x02,0x02,0x02,0x02,0x02,0x00,0x02, 0x02,0x02,0x02,0x02,0x00,0x02,0x02,0x02,0x02,0x02,0x00,0x00,0x00,0x00,0x02,0x02, 0x02,0x02,0x02,0x00,0x02,0x02,0x02,0x02,0x02,0x00,0x02,0x02,0x02,0x02,0x02,0x00, 0x00,0x00,0x40,0x80,0x00,0x00,0x00,0x80,0x40,0x00,0x00,0x00,0xFF,0x00,0x00
15、,0xFF, 0xFF,0x00,0x00,0xFF,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x02,0x02,0x02,0x02,0x02,0x00,0x02,0x02,0x02,0x02,0x02,0x00, 0x02,0x02,0x02,0x02,0x02,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x40,0x80,0x00,0x00,0x00,0x80,0x40,0
16、x00,0x00,0x00,0xFF,0x00,0x00,0xFE, 0xFE,0x00,0x00,0xFF,0x00,0xFC,0x78,0x30,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x60,0x60,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x12,0x1
17、2,0x13,0x7E,0x13,0x12,0x12,0x00,0x00,0x00,0xFF,0x00,0x00,0xFF, 0xFF,0x00,0x00,0xFF,0x00,0xFC,0x78,0x30,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x60,0x60,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x
18、00,0x00, 0x00,0x00,0x12,0x12,0x13,0x7E,0x13,0x12,0x12,0x00,0x00,0x00,0xFF,0x00,0x00,0xFE, 0xFE,0x00,0x00,0x01,0x02,0x04,0x04,0x04,0x04,0x05,0x05,0x05,0x05,0x05,0x04,0x05, 0x05,0x05,0x05,0x05,0x04,0x05,0x05,0x05,0x05,0xC5,0x24,0x14,0x14,0x14,0x15,0x15, 0x15,0x15,0x15,0x14,0x15,0x15,0x15,0x15,0x15
19、,0x14,0x15,0x15,0x15,0x15,0x15,0x14, 0x14,0x14,0x14,0x14,0x14,0x14,0x14,0x14,0x14,0x14,0x14,0x12,0x11,0x10,0x10,0x1F, 0x1F,0x10,0x10,0x11,0x12,0x14,0x14,0x14,0x14,0x14,0x15,0x15,0x15,0x15,0x15,0x14, 0x15,0x15,0x15,0x15,0x15,0x14,0x15,0x15,0x15,0x15,0x15,0x14,0x14,0x14,0x14,0x15, 0x15,0x15,0x15,0
20、x15,0x14,0x15,0x25,0xC5,0x05,0x05,0x04,0x05,0x05,0x05,0x05,0x05, 0x05,0x04,0x04,0x04,0x04,0x04,0x04,0x04,0x04,0x04,0x04,0x02,0x01,0x00,0x00,0xFE, 0xFE,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0x00,0x00,0x00,0xFF,
21、0x7E,0x3C, 0x18,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x60, 0x60,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x
22、00,0x00,0x00,0x00,0x00,0x49,0x4A,0x4C, 0xF8,0x4C,0x4A,0x49,0x00,0x00,0x00,0xFF,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFE, 0xFE,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00
23、,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x02,0x04,0x04,0x04,0x04,0x04, 0x04,0x04,0x04,0x04,0x04,0x04,0x04,0x04,0x04,0x04,0x04,0x04,0x04,0x05,0x05,0x05, 0x05,0x05,0x04,0x05,0x05,0x05,0x05,0x05,0x04,0x05,0x05,0x05,0x05,0x05,0x04,0xFC, 0xFC,0x04,0x05,0x05,0x05,0x05,0x05,0x04,0x05,0x05,0x05,0x05,0x05,0x0
24、4,0x05,0x05, 0x05,0x05,0x05,0x04,0x04,0x04,0x04,0x04,0x04,0x04,0x04,0x04,0x04,0x04,0x04,0x04, 0x05,0x04,0x04,0x04,0x04,0x04,0x02,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFE, 0xFE,0xE0,0xC0,0x80,0x80,0x80,0x80,0x80,
25、0x00,0x80,0x80,0x80,0x80,0x80,0x9E,0xA0, 0x20,0x9E,0x80,0xBC,0x82,0x82,0xBC,0x80,0x3D,0x80,0x84,0x9E,0xA4,0xA4,0x80,0xB6, 0x36,0x80,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x30,0x30,0x00,0x3E,0x41,0x41,0x41, 0x3E,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x00,0x80,0x80,0x80,0x80,0xC0,0xE0,0xFF, 0xFF,0xE0,0x
26、C0,0x80,0x80,0x80,0x80,0x80,0x00,0x80,0x80,0x80,0x80,0x80,0x9E,0xA0, 0x20,0x9E,0x80,0xBC,0x82,0x82,0xBC,0x80,0x3D,0x80,0x84,0x9E,0xA4,0xA4,0x80,0xB6, 0x36,0x80,0x80,0x3E,0x41,0x41,0x41,0x3E,0x00,0x30,0x30,0x00,0x00,0x00,0x00,0x00, 0x00,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x00,0x80,0x80,0x80,0x80,0
27、xC0,0xE0,0xFE, }; /************************************************************* 寫命令 *************************************************************/ void lcd_cmd_wr(uchar cmdcode,uchar right) { if(right) RLCD_CMD_WR=cmdcode; else LLCD_CMD_WR=cmdcode; } /*************************
28、************************************ 寫數(shù)據(jù) *************************************************************/ void lcd_data_wr(uchar dispdata,uchar right) { if(right) RLCD_DAT_WR=dispdata; else LLCD_DAT_WR=dispdata; } /************************************************************* 數(shù)據(jù)清屏
29、 *************************************************************/ void lcd_clr(void) { uchar i,j; for(i=0;i<8;i++) { lcd_cmd_wr(SETY+i,0); lcd_cmd_wr(SETX,0); lcd_cmd_wr(SETY+i,1); lcd_cmd_wr(SETX,1); for(j=0;j<64;j++) { lcd_data_wr(0,0); lcd_data_wr(0,1); } } }
30、 /************************************************************* 寫一個數(shù)字 *************************************************************/ void lcd_shu_wr(uchar w,uchar x,uchar y,uchar shu_1) { uchar i; lcd_cmd_wr(SETY+y,w); lcd_cmd_wr(SETX+x,w); for(i=0;i<6;i++) lcd_data_wr(shu[shu_1][i],
31、w); } /************************************************************* 寫一個三個數(shù)字 *************************************************************/ void lcd_sanshu_wr(uchar w,uchar x,uchar y,uint str) { uint bai,shi,ge; bai=str/100; shi=(str%100)/10; ge=str%10; lcd_shu_wr(w,x,y,bai);
32、 lcd_shu_wr(w,x+6,y,shi); lcd_shu_wr(w,x+12,y,ge); } /************************************************************* 寫一貞128X64點的圖片顯示 *************************************************************/ void lcd_bmp_wr(uchar *bmp) { uchar i,j; for(i=0;i<8;i++) { lcd_cmd_wr(SETY+i,0); lc
33、d_cmd_wr(SETX,0); lcd_cmd_wr(SETY+i,1); lcd_cmd_wr(SETX,1); for(j=0;j<64;j++) { lcd_data_wr(bmp[128*i+j],0); lcd_data_wr(bmp[128*i+j+64],1); } } } /************************************************************* 延時函數(shù) *****************************************************
34、********/ DelayNms(uint y) { uint x; for(;y>0;y--) for(x=113;x>0;x--); } /************************************************************* LCD初始化 *************************************************************/ void lcd_init(void) { lcd_cmd_wr(DISPON,0); lcd_cmd_wr(FIRSTROW,0); lcd_c
35、md_wr(SETY,0); lcd_cmd_wr(SETX,0); lcd_cmd_wr(DISPON,1); lcd_cmd_wr(FIRSTROW,1); lcd_cmd_wr(SETY,1); lcd_cmd_wr(SETX,1); lcd_clr(); DelayNms(500); lcd_bmp_wr(logo); //welcome_init(); } /************************************************************** 初始化中斷,定時器等 ****************
36、**********************************************/ void interrput_init() { IT0=1; //外部中斷0觸發(fā)方式:邊沿觸發(fā) EX0=1; //開外部中斷0 ET0=1; //開定時器中斷0 ET1=1; //開定時器中斷1 //EA=1; //開部中斷 TMOD=0x11; //00010001 TH0=(65535-50000)/256; TL0=(65535-50000)%256; TR0=1; TH1=(65535-50000)/256; TL1=(65535
37、-50000)%256; TR1=0; } /************************************************************** 顯示數(shù)據(jù) **************************************************************/ void display() { lcd_sanshu_wr(0,L_Mile_X_Z,L_Mile_Y,mile_con_km); //寫行駛路程 lcd_sanshu_wr(0,L_Mile_X_D,L_Mile_Y,mile_con_m);
38、 lcd_sanshu_wr(0,L_Cost_X_Z,L_Cost_Y,mile_cost_Z); //寫路程費用 lcd_sanshu_wr(0,L_Cost_X_D,L_Cost_Y,mile_cost_D); lcd_sanshu_wr(0,L_Total_X,L_Total_Y,total_z); //寫總費用整數(shù)部分 lcd_shu_wr(0,L_Unit_X,L_Unit_Y,Mile_Unit); //寫路程單價 lcd_sanshu_wr(1,R_Time_X,R_Time_Y,time_con_m); //寫行駛時間 lcd_san
39、shu_wr(1,R_Cost_X_Z,R_Cost_Y,time_cost_Z); //寫時間費用 lcd_shu_wr(1,R_Cost_X_D,R_Cost_Y,time_cost_D); lcd_sanshu_wr(1,R_Total_X,R_Total_Y,total_d); //寫總費用小數(shù)部分 lcd_shu_wr(1,R_Unit_X,R_Unit_Y,Time_Unit); //寫時間單價 } /************************************************************* 鍵盤輸入 *********
40、*****************************************************/ void keyboard() { P1=0xff; if(P1!=0xff) { DelayNms(1); if(P1!=0xff) { if(!START) EA=1; if(!STOP) EA=0; if(!CLEAR) { mile_con_km=0; mile_con_m=0; mile_cost_Z=0; mile_cost_D=0; total_z=5;
41、 time_con_m=0; time_cost_Z=0; time_cost_D=0; total_d=0; display(); } if(!MUINT_UP) { Mile_Unit++; while(!MUINT_UP); lcd_shu_wr(0,L_Unit_X,L_Unit_Y,Mile_Unit);//寫路程單價 } if(!MUINT_D) { Mile_Unit--; while(!MUINT_D); lcd_shu_w
42、r(0,L_Unit_X,L_Unit_Y,Mile_Unit);//寫路程單價 } if(!TUINT_UP) { Time_Unit++; while(!TUINT_UP); lcd_shu_wr(1,R_Unit_X,R_Unit_Y,Time_Unit);//寫時間單價 } if(!TUINT_D) { Time_Unit--; while(!TUINT_D); lcd_shu_wr(1,R_Unit_X,R_Unit_Y,Time_Unit);//寫時間單價 }
43、 } } } /************************************************************** 測速 **************************************************************/ void testspeed() { if(speed>=18) { speed_flag=1; TR1=0; } else { speed_flag=0; TR1=1; } } /****************************
44、********************************** 主函數(shù) **************************************************************/ void main() { lcd_init(); interrput_init(); display(); while(1) { keyboard(); testspeed(); } } /************************************************************* 外部中斷0服務程序 測所
45、走過的路程,并且測車速 *************************************************************/ void Int0() interrupt 0 { LED=!LED; speed_con_m++; if(speed_flag) { mile_con_m++; if(mile_con_m==1000) { mile_con_m=0; mile_con_km++; if(mile_con_km==1) cost_flag=1; } } } /****
46、******************************************************** 定時器0中斷服務程序 測速計時器 *************************************************************/ void timer0() interrupt 1 { TH0=(65535-50000)/256; //50ms TL0=(65535-50000)%256; speed_con++; if(speed_con%5==0) //0.25s測速一次 { speed=s
47、peed_con_m*2; speed_con_m=0; } if(speed_con==20) ////1s刷新顯示一次 { speed_con=0; if(cost_flag) { mile_cost_D=(mile_con_m*Mile_Unit)%1000; //計算路費用 mile_cost_Z=(mile_con_km-1)*Mile_Unit; mile_cost_Z=mile_cost_Z+(mile_con_m*Mile_Unit)/1000; total_z=mile_cost_Z+tim
48、e_cost_Z; //計算總費用 total_z+=5; total_d=mile_cost_D+time_cost_D*100; total_z=total_z+total_d/1000; total_d=total_d%1000; } display(); } } /************************************************************* 定時器1中斷服務程序 按時間計費計時器 ************************************************
49、*************/ void timer1() interrupt 3 { TH1=(65535-50000)/256; //50ms計時 TL1=(65535-50000)%256; time_con_s++; if(time_con_s==1200) //一分鐘 { time_con_s=0; time_con_m++; time_cost=time_con_m*Time_Unit; //計算時間費用 time_cost_Z=time_cost/10; time_cost_D=time_cost%10; } }
- 溫馨提示:
1: 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
2: 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權益歸上傳用戶所有。
3.本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
4. 未經(jīng)權益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
5. 裝配圖網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責。
6. 下載文件中如有侵權或不適當內(nèi)容,請與我們聯(lián)系,我們立即糾正。
7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 6.煤礦安全生產(chǎn)科普知識競賽題含答案
- 2.煤礦爆破工技能鑒定試題含答案
- 3.爆破工培訓考試試題含答案
- 2.煤礦安全監(jiān)察人員模擬考試題庫試卷含答案
- 3.金屬非金屬礦山安全管理人員(地下礦山)安全生產(chǎn)模擬考試題庫試卷含答案
- 4.煤礦特種作業(yè)人員井下電鉗工模擬考試題庫試卷含答案
- 1 煤礦安全生產(chǎn)及管理知識測試題庫及答案
- 2 各種煤礦安全考試試題含答案
- 1 煤礦安全檢查考試題
- 1 井下放炮員練習題含答案
- 2煤礦安全監(jiān)測工種技術比武題庫含解析
- 1 礦山應急救援安全知識競賽試題
- 1 礦井泵工考試練習題含答案
- 2煤礦爆破工考試復習題含答案
- 1 各種煤礦安全考試試題含答案