1、延时void delay1(unsigned int ms) /12.000MHzunsigned int j,k;k=ms*10;for(;k!=0;k-)for(j=0;j0;us-);12864 显示/*/* */*检查 LCD 忙状态 */*lcd_busy 为 1 时,忙,等待。lcd- busy 为 0 时,闲,可写指令与数据。 */* */*/bit lcd_busy() bit result;LCD_RS = 0;LCD_RW = 1;LCD_EN = 1;delayNOP();result = (bit)(P2LCD_EN = 0;return(result); /*/* *
2、/*写指令数据到 LCD */*RS=L,RW=L,E=高脉冲,D0-D7= 指令码。 */* */*/void lcd_wcmd(uchar cmd) while(lcd_busy();LCD_RS = 0;LCD_RW = 0;LCD_EN = 0;delay_us(3); P2 = cmd;delayNOP();LCD_EN = 1;delayNOP();LCD_EN = 0; /*/* */*写显示数据到 LCD */*RS=H,RW=L,E=高脉冲,D0-D7=数据。 */* */*/void lcd_wdat(uchar dat) while(lcd_busy();LCD_RS =
3、 1;LCD_RW = 0;LCD_EN = 0;P2 = dat;delayNOP();LCD_EN = 1;delayNOP();LCD_EN = 0; /*/* */* LCD 初始化设定 */* */*/void lcd_init() LCD_PSB = 1; /并口方式LCD_RST = 0; /液晶复位delay(5); LCD_RST = 1; delay(5);lcd_wcmd(0x34); /扩充指令操作delay(5);lcd_wcmd(0x30); /基本指令操作delay(5);lcd_wcmd(0x0C); /显示开,关光标delay(5);lcd_wcmd(0x01
4、); /清除 LCD 的显示内容delay(5);/*/* */* 设定显示位置 */* */*/void lcd_pos(uchar X,uchar Y) uchar pos;if (X=1)X=0x80;else if (X=2)X=0x90;else if (X=3)X=0x88;else if (X=4)X=0x98;pos = X+Y ; lcd_wcmd(pos); /显示地址/* * 清屏函数 * */void clr_screen()lcd_wcmd(0x34); /扩充指令操作delay(5); lcd_wcmd(0x30); /基本指令操作delay(5); lcd_wcm
5、d(0x01); /清屏 delay(5); 主函数uchar code menu_1=“U: V I: A“;uchar code menu_2=“恒压: V 步“;uchar code menu_3=“ 恒流: A 进“;uchar code menu_4=“ 恒阻: “;uchar code menu=“0123456789.m -:“;void lcd_menu() /开机显示uchar i;lcd_pos(1,0);for(i=0;i=10000)S/=10;out0=menuS%10000/1000;out1=menuS%1000/100;out2=menu10; out3=men
6、uS%100/10;out4=menuS%10; elseout0=menuS%10000/1000;out1=menu10;out2=menuS%1000/100; out3=menuS%100/10;out4=menuS%10; for(i=0;i5;i+)lcd_wdat(outi);delay(1);void lcd_Iin(uint S) /显示输出电流uchar i,out4;out0=menuS%1000/100;out1=menu10;out2=menuS%100/10;out3=menuS%10;lcd_pos(1,5);lcd_wdat(menu14);delay_us(4
7、);for(i=0;i4;i+)lcd_wdat(outi);delay(1);void lcd_Uset(uint S) /显示设置电压uchar i,out5;out0=menuS%10000/1000;out1=menuS%1000/100;out2=menu10;out3=menuS%100/10;out4=menuS%10; /* out0=menuS%10000/1000;out1=menu10;out2=menuS%1000/100;out3=menuS%100/10;out4=menuS%10; */lcd_pos(2,3);lcd_wdat(menu14);delay(1);
8、for(i=0;i5;i+)lcd_wdat(outi);delay(1);void lcd_Iset(uint S) /显示设置电流uchar i,out5;out0=menuS%10000/1000;out1=menu10;out2=menuS%1000/100;out3=menuS%100/10;out4=menuS%10;lcd_pos(3,3);lcd_wdat(menu14);delay(1);for(i=0;i5;i+)lcd_wdat(outi);delay(1);void lcd_R(uint S) /电阻uchar i,out3;if(S100)out0=menuS%100
9、/10;out1=menu10;out2=menuS%10;else if(S1000)S/=10;out1=menuS%100/10;out2=menuS%10;out0=menu_40;else if(S10000)S/=10;out0=menuS/1000;out1=menuS%100/10;out2=menuS%10;lcd_pos(4,3);lcd_wdat(menu14);delay(1);for(i=0;i3;i+)lcd_wdat(outi);delay(1);void lcd_bj(uchar S) /显示步进电压uchar out3,i;out0=menuS/100;out1=menu10;out2=menuS%100/10;lcd_pos(4,7);for(i=0;i3;i+)lcd_wdat(outi);delay(1);void lcd_fu(bit a) /显示负号 1 负 0 正if(a=1)lcd_pos(2,4);lcd_wdat(menu12);delay_us(4);lcd_wdat(menu13);delay_us(4);if(a=0)lcd_pos(2,4);lcd_wdat(menu12);delay_us(4);lcd_wdat(menu12);delay_us(4);