#include #include #define uchar unsigned char#define uint unsigned int #define LCD_DB P0sbit LCD_RS = P2^4; sbit LCD_RW = P2^3; sbit LCD_E = P2^2; sbit K1 = P1^0;sbit K2 = P1^1;sbit K3 = P1^2;sbit K4 = P1^3;sbit K5 = P1^4;sbit M1 = P1^5;sbit M2 = P1^6;sbit M3 = P1^7;sbit DCY1 = P3^0;sbit DCY2 = P3^1;sbit CLK = P3^2;sbit EN = P2^6;sbit UD = P2^5;sbit UD1 = P2^1;uchar bin2dec(uchar a ,uchar b ,uchar c);uchar bin2dec1(uchar a ,uchar b);void LCD_init(void);void LCD_write_command(uchar command);void LCD_write_date(uchar dat);void LCD_disp_char(uchar x,uchar y,uchar dat);void LCD_disp_str(uchar row,uchar * str);bit LCD_check_busy(void);void delay_n40us(uint n);void StartTime0(void);uchar code dis1[8][9] = {{"DIV:1/2"},{"DIV:1/8"},{"DIV:1/10"},{"DIV:1/16"},{"DIV:1/20"},{"DIV:1/32"},{"DIV:1/40"},{"DIV:1/64"}};uchar code hz[8] = {1000,1000,1000,1000,1000,1000,1000,1000};uchar selector = 0;uchar o = 0,m = 0,s = 0,save = 0,save1 = 0;void main(){EN = 1;CLK = 0;StartTime0();UD = 0;UD1 = 1;while(1){M1 = K1;M2 = K2;M3 = K3;DCY1 = K4;DCY2 = K5;o = bin2dec(M1,M2,M3);UD1 = 1;if(o != save){s = 0;save = o;//selector = o;//ET0 = 0;}else{s = 1;save = o;//ET0 = 1;}m = bin2dec1(DCY2,s);if(save1 != m){switch(m){case 0 : {LCD_init();LCD_disp_str(1,dis1[o]);LCD_disp_str(2,"CW:FORWORD");UD1 = 1;}break;case 1 : {LCD_init();LCD_disp_str(1,dis1[o]);LCD_disp_str(2,"CW:FORWORD");UD1 = 1;}break;case 2 : {LCD_init();LCD_disp_str(1,dis1[o]);LCD_disp_str(2,"CW:BACK");UD1 = 0;}break;case 3 : {LCD_init();LCD_disp_str(1,dis1[o]);LCD_disp_str(2,"CW:BACK");UD1 = 0;}break;default :{LCD_init();LCD_disp_str(1,dis1[o]);}}save1 = m;}}}uchar bin2dec(uchar a ,uchar b ,uchar c){uchar i;a = a<<2;b = b<<1;i = a | b | c;return i;}uchar bin2dec1(uchar a ,uchar b){uchar i;a = a<<1;i = a | b;return i;}void LCD_init(void){LCD_write_command(0x38);delay_n40us(100);LCD_write_command(0x0c);delay_n40us(100);LCD_write_command(0x06);delay_n40us(100);LCD_write_command(0x01);delay_n40us(100);}
評(píng)論