⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 main2151.c

📁 出 租 车 计 价 器 源 码 LCM12864 24C02 AT89C51
💻 C
字号:
//////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////出租车计价器///////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////
#include <reg52.h>
#include <intrins.h>
#include <string.h>
#define uchar unsigned char
#define uint unsigned int
#define TIME0H 0x9C	//0.1ms

sbit KEY_1= P1^0;
sbit KEY_2= P1^1;
sbit KEY_3= P1^2;
sbit KEY_4= P1^3;
uchar KEY;
uchar tpKEY;
//////////////////////////////////////////Menu//////////////////////////////////////////////

uchar setPriceMod=0;//0设置白天,1设置晚上

uchar priceMod=0;//0按白天计价,1按晚上计价


///////////////////////////////////计算用全局变量///////////////////////////////////////////
float dayPrice=5.5, nightPrice=6.5;	//价格
float distance;//里程

uint wheelPerimeter=100;//车轮周长cm
uint circle=0; //圈数


///////////////////////////////////////显示/////////////////////////////////////////////////
uchar data arr_dayPrice[3],arr_nightPrice[3];
uchar data arr_totalCost[3];
uchar data arr_distance[4];
uchar data arr_wheelPerimeter[3];
uchar data arr_circle[3];


//-----------------------------------LCD------------------------------
#define  LCD12864_IO  P0
#define  LINE1   0
#define  LINE2   1
#define  HIGH   1
#define  LOW    0
#define  CLERADISPLAY LCD12864_command(0x01);
#define   uchar  unsigned char
#define   uint   unsigned int
sbit xssjj=P2^5;

uchar temp=33;
uchar code  weiB_a[8]={0x80,0x40,0x20,0x10,0x08,0x04,0x02,0x01};
uchar code  weiB_b[8]={0x80,0xa0,0x50,0x28,0x14,0x0a,0x05,0x01};
uchar  weiB_c[8]={0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
    int a=16;
uchar data juli[3];


/********************************************************************/
sbit LCD12864_EN=P2^2;  //en
sbit LCD12864_DIN=P2^0; //rs
sbit LCD12864_CLK=P2^1; //rw
sbit cs1=P2^3;
sbit cs2=P2^4;
/********************************************************************/
//void lcd_gps_wei(unsigned char wei_x,unsigned char wei_y);

void LCD12864_DELAY(unsigned int a)
{
for(;a>0;a--)
_nop_();
}
/*******************************************************************/
void LCD12864_busy(void)
{
    bit BF = 0;
    LCD12864_EN=0;
    LCD12864_DIN=0;
    LCD12864_CLK=1;
    LCD12864_IO=0xff;  //单片机读数据之前必须先置高位
    do
    {
     	LCD12864_EN=1;
        BF=LCD12864_IO&0x80;
        LCD12864_EN=0;
    } while(BF);
}
/*******************************************************************/
//          写入命令
/*******************************************************************/
void LCD12864_command(unsigned char command)
{
    LCD12864_busy();
    LCD12864_EN=0;
    LCD12864_DIN=0;
    LCD12864_CLK=0;

    LCD12864_EN=1;
    LCD12864_IO=command;
    LCD12864_EN=0;
}
/*******************************************************************/
//          写入一字节数据
/*******************************************************************/
 void LCD12864_data(unsigned char dat)
{
    LCD12864_busy();
    LCD12864_EN=0;
    LCD12864_DIN=1;
    LCD12864_CLK=0;

    LCD12864_EN=1;
    LCD12864_IO=dat;
    LCD12864_EN=0;
}
void LCD12864_char(unsigned char dat)
{
if((dat>=0)&&(dat<=9))
     dat|=0x30;
    LCD12864_data(dat);
}

/*******************************************************************/
//          设置显示位置    X(1~8),Y(1~4)
/*******************************************************************/
void LCD12864_address(unsigned char line,unsigned char row)
{
    switch(row)
    {
        case 1:LCD12864_command(0x7f + line);
        break;
        case 2:LCD12864_command(0x8f + line);
        break;
        case 3:LCD12864_command(0x87 + line);
        break;
        case 4:LCD12864_command(0x97 + line);
        default:
        break;
    }
}
/*******************************************************************/
//          在指定位置显示字符串
/*******************************************************************/
void LCD12864_string(unsigned char row,unsigned char line,unsigned char *s)
{
    unsigned char LCD12864_temp;
    LCD12864_address(row,line);
    LCD12864_temp=*s;
    while(LCD12864_temp != 0x00)
    {
        LCD12864_data(LCD12864_temp);
        LCD12864_temp=*(++s);
    }
}
/********************************************************************/
void Delay_100xuS(uint x) //
{
    unsigned int i,j;
    for( i =0;i < x;i++ )
    {
        for( j =0;j<9;j++ );
    }
}
/*******************************************************************/
//          初始化设置
/*******************************************************************/
void LCD12864_init(void)
{
    CLERADISPLAY      //  clear DDRAM
    LCD12864_command(0x30);     //  8 bits unsigned interface,basic instrument
    LCD12864_command(0x02);     //  cursor return
    LCD12864_command(0x0c);     //  display,cursor on
    LCD12864_command(0x03);
    LCD12864_command(0x06);
    CLERADISPLAY       //  clear DDRAM
}

void Mcu_init(void)
{
LCD12864_init();
CLERADISPLAY
CLERADISPLAY
LCD12864_init();
}
//----------------------------------------------------LCD-------------------------------------
//--------------------------------------------------Menu----------------------------------
void MainMenu()
{
	 CLERADISPLAY
	 LCD12864_string(1,1,"1.菜单");
	 if(priceMod==0)
	 	LCD12864_string(7,4,"白天");
	 if(priceMod==1)
	 	LCD12864_string(7,4,"夜晚");
 	 LCD12864_string(1,2,"2.开始计费");
	 LCD12864_string(1,3,"3.停止计费");
	 LCD12864_string(1,4,"4.收费模式");
}
void ListMenu()
{
	CLERADISPLAY
	LCD12864_string(1,1,"1.设置价格");
		//if(feeMode==0)
	LCD12864_string(1,2,"2.设置轮胎周长");
	 //if(feeMode==1)

	LCD12864_string(1,4,"3.返回");
}
void SetPriceMenu()
{
	CLERADISPLAY
	if(setPriceMod==0)
		LCD12864_string(1,1,"1.白天:      元");
	if(setPriceMod==1)
		LCD12864_string(1,1,"1.晚上:      元");
	LCD12864_string(1,2,"2.++");
	LCD12864_string(1,3,"3.--");
	LCD12864_string(1,4,"4.完成");
}

void BillingMenu()
{
	 CLERADISPLAY
	 LCD12864_string(1,1,"行驶:      千米");
	 LCD12864_string(1,2,"单价:        元");
	 LCD12864_string(1,3,"总价:        元");

}
void SetWheelMenu()
{
	 CLERADISPLAY
	 LCD12864_string(1,1,"周长:      厘米");
	 LCD12864_string(1,2,"++");
	 LCD12864_string(1,3,"--");
	 LCD12864_string(1,4,"完成");
}
//--------------------------------------------------Menu----------------------------------

//--------------------------------------------------数据转换------------------------------
void ChangeDayPrice()
{
	uint tpDayPrice=dayPrice*10;
	arr_dayPrice[0]=tpDayPrice/10+'0';
	arr_dayPrice[1]='.';
	arr_dayPrice[2]=tpDayPrice%10+'0';
}
void ChangeNightPrice()
{
  	uint tpNightPrice=nightPrice*10;
	arr_nightPrice[0]=tpNightPrice/10+'0';
	arr_nightPrice[1]='.';
	arr_nightPrice[2]=tpNightPrice%10+'0';
}
void ChangeWheelPerimeter()
{
	 uint tpWheelPerimeter=wheelPerimeter;
	 arr_wheelPerimeter[0]=wheelPerimeter/100+'0';
	 arr_wheelPerimeter[1]=wheelPerimeter/10%10+'0';
	 arr_wheelPerimeter[2]=wheelPerimeter%10+'0';
}
void ChangeCircle()
{
	uint tpCircle=circle;
	arr_circle[0]=tpCircle/100+'0';
	arr_circle[1]=tpCircle/100%10+'0';
	arr_circle[2]=tpCircle%10+'0';
}
void ChangeDistance()
{}
void ChangeTotalCost()
{}

//---------------------------------------------------------------------------------------------
void Delay(void)
{
        unsigned char i;
        unsigned int j;
        for(i=0;i<200;i++)
        for(j=1000;j>0;j--);
}
jisuan()
{
        juli[0]=a/10+'0';
        juli[1]=a%10+'0';
}


void DelayM(unsigned int a)
{//延时函数 1MS/次
		unsigned char i;
		while( --a != 0)
		{
			for(i = 0; i < 125; i++);  //一个 ; 表示空语句,CPU空转。
		}   				   //i 从0加到125,CPU大概就耗时1毫秒
}
void ShowSetPrice()
{
	uchar tpKEY=0;
	SetPriceMenu();
	ChangeDayPrice();
	ChangeNightPrice();
	if(setPriceMod==0)
	{
		LCD12864_string(6,1,arr_dayPrice);
	}
	else if(setPriceMod==1)
	{
		LCD12864_string(6,1,arr_nightPrice);
	}
	while(1)
	{
			if(KEY_1==0)
			{
				DelayM(20);
				tpKEY=1;

				while(KEY_1==0);
				DelayM(20);
				if(tpKEY==1)
				{
					if(setPriceMod==0)
					{
						LCD12864_string(1,1,"1.晚上");
						LCD12864_string(6,1,arr_nightPrice);
						setPriceMod=1;

					}
					else if(setPriceMod==1)
					{
						LCD12864_string(1,1,"1.白天");
						LCD12864_string(6,1,arr_dayPrice);
						setPriceMod=0;
					}
					tpKEY=0;
				}
			}
			if(KEY_2==0)
			{
				DelayM(20);
				tpKEY=1;

				while(KEY_2==0);
				DelayM(20);
				if(tpKEY==1)
				{
					if(setPriceMod==0)
					{
						dayPrice+=0.1;
						ChangeDayPrice();
						LCD12864_string(6,1,arr_dayPrice);
					}
					else if(setPriceMod==1)
					{
						nightPrice+=0.1;
						ChangeNightPrice();
						LCD12864_string(6,1,arr_nightPrice);
					}
				}
				tpKEY=0;
			}
			if(KEY_3==0)
			{
				DelayM(20);
				tpKEY=1;

				while(KEY_3==0);
				DelayM(20);
				if(tpKEY==1)
				{
					if(setPriceMod==0)
					{
						dayPrice-=0.1;
						ChangeDayPrice();
						LCD12864_string(6,1,arr_dayPrice);
					}
					else if(setPriceMod==1)
					{
						nightPrice-=0.1;
						ChangeNightPrice();
						LCD12864_string(6,1,arr_nightPrice);
					}
				}
				tpKEY=0;
			}


			if(KEY_4==0)
			{
				DelayM(20);
				CLERADISPLAY
				return;
				while(KEY_4==0);
				DelayM(20);
			}
		}


}
void ShowSetWheel()
{
	uchar tpKEY=0;
	SetWheelMenu();
	ChangeWheelPerimeter();
	LCD12864_string(5,1,arr_wheelPerimeter);
	while(1)
	{
		 	if(KEY_1==0)
			{
				DelayM(20);
				tpKEY=1;

				while(KEY_1==0);
				DelayM(20);
				if(tpKEY==1)
					tpKEY=0;

			}
			if(KEY_2==0)
			{
				DelayM(20);
				tpKEY=1;

				while(KEY_2==0);
				DelayM(20);
				if(tpKEY==1)
				{

						wheelPerimeter++;
						ChangeWheelPerimeter();
						LCD12864_string(5,1,arr_wheelPerimeter);
				}
				tpKEY=0;
			}
			if(KEY_3==0)
			{
				DelayM(20);
				tpKEY=1;

				while(KEY_3==0);
				DelayM(20);
				if(tpKEY==1)
				{
					wheelPerimeter--;
					ChangeWheelPerimeter();
					LCD12864_string(5,1,arr_wheelPerimeter);
				}
				tpKEY=0;
			}


			if(KEY_4==0)
			{
				DelayM(20);
				return;
				while(KEY_4==0);
				DelayM(20);
			}
		}
}
void ShowList()
{
	uchar tpKEY;
	ListMenu();
	while(1)
	{
			if(KEY_1==0)
			{
				DelayM(20);
				tpKEY=1;

				while(KEY_1==0);
				DelayM(20);
				if(tpKEY==1)
					ShowSetPrice();	  //设置价格

			}
			if(KEY_2==0)
			{
				DelayM(20);
				tpKEY=1;

				while(KEY_2==0);
				DelayM(20);
				if(tpKEY==1)
					ShowSetWheel();		  //设置轮胎周长
				tpKEY=0;

			}
		/*	if(KEY_3==0)
			{
				DelayM(20);
				reSet();
				while(KEY_3==0);
				DelayM(20);
			}	   */


			if(KEY_4==0)
			{
				DelayM(20);
				tpKEY=1;
				while(KEY_4==0);
				DelayM(20);
				if(tpKEY==1)
				{
					CLERADISPLAY
					MainMenu();
					tpKEY=0;
					return;
				}
			}

	}
}
void Billing()
{
	uchar tpKEY=0;
	BillingMenu();
	while(1)
	{
		if(KEY_2==0)
		{
			DelayM(20);
			tpKEY=1;
			while(KEY_2==0);
			DelayM(20);
			if(tpKEY==1)
			{
				tpKEY=0;
				MainMenu();
				return;
			}
		}
	}
}
void ReSet()
{}
void SetMod()
{

	if(priceMod==0)
	{
		LCD12864_string(7,4,"夜晚");
		priceMod=1;
	}
	else if(priceMod==1)
	{
	 	LCD12864_string(7,4,"白天");
		priceMod=0;
	}
}
void Inital()
{ }


	   


void main()
{

	

		Inital();
//		uchar tpKEY;
		Mcu_init();
   	    CLERADISPLAY
		MainMenu();

		while(1)
        {

        	if(KEY_1==0)
			{
				DelayM(20);
				tpKEY=1;
				while(KEY_1==0);
				DelayM(20);
				if(tpKEY==1)
				{
					ShowList();
					tpKEY=0;
				}
			}
			if(KEY_2==0)
			{
				DelayM(20);
				tpKEY=1;
				while(KEY_2==0);
				DelayM(20);
				if(tpKEY==1)
				{
					Billing();
					tpKEY=0;
				}
			}
			if(KEY_3==0)
			{
				DelayM(20);
//				reSet();
				while(KEY_3==0);
				DelayM(20);
			}


			if(KEY_4==0)
			{
				DelayM(20);
				tpKEY=1;
				while(KEY_4==0);
				DelayM(20);
				if(tpKEY==1)
				{
					SetMod();
					tpKEY=0;
				}
			}
			//菜单
			//计费 再按停止计费
			//复位 ,系统复位(长按)
			//白天模式(默认),晚上模式(按)


	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -