#include #define uchar unsigned char #define uint unsigned int /****************端口定义***************/ #define LCD_data P2 //定义数据口 sbit LCD_RS=P0^0; //寄存器选择输入 sbit LCD_RW=P0^1; //液晶读写控制 sbit LCD_EN=P0^2; //液晶时能控制 sbit LCD_PSB=P0^3; //串/并方式控制 sbit key1=P1^0; //按键定义 sbit key2=P1^1; sbit key3=P1^2; /****************定义变量***************/ uchar speed=11;//即时速度 uchar key; uchar keynum=0;//功能键按下次数 int qbwei,gshwei; /****************液晶显示字符串定义***************/ uchar code dis1[]=" 液滴控制 "; uchar code dis2[]="设定速度: 0000"; uchar code dis3[]="实时速度:"; uchar code dis4[]="向前进!向前进!"; uchar dis5[3]; /****************函数声明***************/ void lcd_init(); //LCD 初始化 void lcdinit_display(); //LCD 显示初始化 bit lcd_busy(); //遇忙检测 void write_cmd(uchar cmd); //写命令 void write_dat(uchar dat); //写数据 void lcd_pos(uchar X,uchar Y); //设置显示位置 void write_gshb(uchar add,uchar dat); //取位设置 void matrixkeyscan(); // 键盘扫描 void Moment_speed(uchar speed); // 实时速度 void lcd_display(); // LCD 显示 void delay(uint n); // 延时 /****************主函数***************/ void main() { lcdinit_display(); while(1) { lcd_display(); Moment_speed(speed); } } /************子程序************/ void delay(uint n) { uint i,j; for(i=n;i>0;i--) for(j=110;j>0;j--); } /***********************液晶子程序********************************************/ /*******************************************************************/ /* */ /*检查LCD 忙状态 */ /*lcd_busy 为1 时,忙,等待。lcd-busy 为0 时,闲,可写指令与数据。 */ /* */ /*******************************************************************/ bit lcd_busy() { bit result; LCD_RS = 0; LCD_RW = 1; LCD_EN = 1; delay(5); result = (bit)(P0&0x80); LCD_EN = 0; return(result); } /*********写指令数据到 LCD***...