void switch_mode(char x) { if(x==1) { if(mode==0) { pos_mode1=0; LCD_CLEAR(); DISPLAY(0,0,res); } if(mode==1) { pos_mode2=0; LCD_CLEAR(); DISPLAY(0,0,fullc); /* float acr = ds_get_acr(); sprintf(fullc,"%d mAh",fullc_int); nowc_int = (int)(acr*fullc_int); sprintf(nowc,"%d mAh",nowc_int);*/ float acr = ds_get_acr(); fullc_int = atoi(fullc); nowc_int = (int)(acr*fullc_int/100); sprintf(nowc,"%05d mAh C",nowc_int); DISPLAY(1,0,nowc); } if(mode==2) { LCD_CLEAR(); LCD_WR_COM(0X0C); } } if(x==3) { //in mode 1 2 and entry the edit. if(mode!=0&&yes) { //cursor to the up left LCD_WR_COM(0x02); //flicker the cursor and the letter LCD_WR_COM(0x0f); } //in mode 1 2 and exit the edit. if(mode!=0&&!yes) { LCD_WR_COM(0X0C); if(mode==2) { float acr = ds_get_acr(); fullc_int = atoi(fullc); nowc_int = (int)(acr*fullc_int); sprintf(nowc,"%05d Om",nowc_int); //res_int = atoi(res); } } } }
/** * @brief Initialize the LCD to wrap at 16 chars, * cursor off, and clear the screen. * * @param none * * @retval none */ void LCDInit(void) { // Wait for LCD to power up SysTickDelay(ST_MS * 20); LCD_DISPLAY_MODE(0x30); LCD_CURSOR_MODE(0x32); LCD_CLEAR(); }
int lcd_open(struct inode *inode, struct file *filp) { printk(KERN_INFO "lcd_couscous: release\n"); LCD_INIT(); LCD_HOME(); LCD_CLEAR(); if(MINOR(inode->i_rdev) != 0) { printk("mauvais numero d unite\n"); return -EINVAL; } return 0; }
//液晶初始化 void LCD_INIT() { //复位 LOW(REST); delay_us(10); HIGH(REST); LOW(SCE); delay_us(2); HIGH(SCE); delay_us(2); //各种设置 详情查表 W_BYTE(0x21,0); W_BYTE(0xC8,0); W_BYTE(0x06,0); W_BYTE(0x13,0); W_BYTE(0x20,0); LCD_CLEAR(); W_BYTE(0x0C,0); LOW(SCE); }
int main() { characters_init(); PORT_INIT(); LCD_INIT(); init_key(); //设定mah 2580 为3000mah 4b00 为6000 /*while(!ds_reset()); ds_write_byte(CMD_ONEWIRE_SKIP_ROM); ds_write_byte(CMD_ONEWIRE_WRITE); ds_write_byte(CMD_ADDR_ACR); ds_write_byte(0X4b); ds_write_byte(0X00);*/ int count = 5; char key; while(1) { key = get_key(); //switch mode and in edit edit. if(key==1) { //in mode 1 go to next cursor if(yes&&mode==1) { //go back to the begining of the line if(pos_mode1==4){LCD_WR_COM(0X02);} else { //cursor to the next LCD_WR_COM(0X14); } //the position of mode1 add pos_mode1 = (pos_mode1+1)%5; } else if(yes&&mode==2) { //go to the begining of the first line if(pos_mode2==4){LCD_WR_COM(0X02);} else { LCD_WR_COM(0x14); } pos_mode2 = (pos_mode2+1)%5; } else { switch_mode(1); mode = (mode+1)%3; } } if(key==3) { yes = ~yes; switch_mode(3); } if(key==2) { if(mode==1&&yes) { res[pos_mode1]=(res[pos_mode1]+1-'0')%10+'0'; LCD_WR_COM(0X80+pos_mode1); LCD_WR_DATA(res[pos_mode1]); LCD_WR_COM(0X10); } if(mode==2&&yes) { fullc[pos_mode2] = (fullc[pos_mode2]+1-'0')%10+'0'; LCD_WR_COM(0x80+pos_mode2); LCD_WR_DATA(fullc[pos_mode2]); LCD_WR_COM(0X10); } } if(mode==0) { if(count==0) { count=4; LCD_CLEAR(); } count--; } update(); mode_pro(); _delay_ms(50); } }
int main (void) { /// Configure Devices ////////////////////////////////////// // Display configuration: frontLCD.ddr = &DDRD; frontLCD.port = &PORTD; frontLCD.pin = &PIND; frontLCD.pinNr_EN = PD5; frontLCD.pinNr_RS = PD4; frontLCD.pinNr_D4 = PD0; frontLCD.pinNr_D5 = PD1; frontLCD.pinNr_D6 = PD2; frontLCD.pinNr_D7 = PD3; // Buttion A configuration button_A.ddr = &DDRC; button_A.port = &PORTC; button_A.pin = &PINC; button_A.pinNr = PC7; button_A.internPullup = True; button_A.bounce_ms = 40; // Buttion B configuration button_B.ddr = &DDRC; button_B.port = &PORTC; button_B.pin = &PINC; button_B.pinNr = PC4; button_B.internPullup = True; button_B.bounce_ms = 40; // Rotary encoder A configuration encoder_A.ddr = &DDRC; encoder_A.port = &PORTC; encoder_A.pin = &PINC; encoder_A.pinNr_A = PC6; encoder_A.pinNr_B = PC5; encoder_A.internPullup = True; encoder_A.autoAcceleration = True; encoder_A.accerelationFactor = 200; // Rotary encoder B configuration encoder_B.ddr = &DDRC; encoder_B.port = &PORTC; encoder_B.pin = &PINC; encoder_B.pinNr_A = PC3; encoder_B.pinNr_B = PC2; encoder_B.internPullup = True; encoder_B.autoAcceleration = True; encoder_B.accerelationFactor = 100; /// END Configure Devices ////////////////////////////////// /// INIT Devices /////////////////////////////////////////// // INIT display LCD_INIT(&frontLCD); LCD_CLEAR(&frontLCD); // INIT buttons BUTTON_INIT(&button_A); BUTTON_INIT(&button_B); // INIT rotary encoders ROTARYENC_INIT(&encoder_A); ROTARYENC_INIT(&encoder_B); /// END INIT Devices /////////////////////////////////////// while(1) MainMenu(); // Enter main-menu (see below) return 0; }