void LCD_Init(void) { LCD_CS(1); LCD_CLK(0); LCD_DATA(0); LCD_RESET(1); delay(50); LCD_RESET(0); delay(50); LCD_RESET(1); delay(50); LCD_CS(1); LCD_CLK(1); LCD_DATA(1); delay(10); SendLcd(LCDCommand,SWRESET); delay(10); SendLcd(LCDCommand,SLEEPOUT); // Sleepout // SendLcd(LCDCommand,INVON); // Invert display mode // SendLcd(LCDCommand,BSTRON); // BoostON SendLcd(LCDCommand,MADCTL); // memory access control SendLcd(LCDData,0xe0); SendLcd(LCDCommand,SETCON); // Set Contrast SendLcd(LCDData,0x40); delay(10); SendLcd(LCDCommand,DISPON); // Display On SendLcd(LCDCommand,COLMOD); // Set Color Mode SendLcd(LCDData,0x03); // 12bit per pixel SendLcd(LCDCommand,NOP); // Set Color Mode }
/****************************************************************************** * Initializes the display in 4x booster for 2.4-3.3V supply voltage * scheme according to datasheet * Suitable for all DOGS, DOGM, DOGL and DOGXL displays * in both bottom or top-view orientation. */ void lcd_init() { LCD_SET_PIN_DIRECTIONS(); //set outputs LCD_INIT_SPI(); //Initialize SPI Interface LCD_RESET(); //Apply Reset to the Display Controller //Load settings #if DISPLAY_TYPE == 240 //LCD_SYSTEM_RESET; // software reset //_delay_ms(5); // Gib dem Display ein bisschen Zeit für den Reset LCD_SET_COM_END(127); // set last COM electrode LCD_SET_PARTIAL_DISPLAY(0, 127); // set partial display start and end LCD_SET_POTI(0x8F); // set Contrast to mid range lvl LCD_SET_MAPPING_CTRL(2); // set mapping control to "bottom view" LCD_SET_LINE_RATE(11); // set line rate to 9.4 kilo lines per second LCD_SET_TEMP_COMP(1); // set tmep compensation to -0.10% LCD_SWITCH_ON(); // set display enable (0xA9) LCD_SET_DISPLAY_PATTERN(1); // set display pattern (0xD1) LCD_SET_RAM_ADDR_CTRL(1); // set auto-increment #endif #if DISPLAY_TYPE == 160 LCD_SET_COM_END(103); //set last COM electrode #if ORIENTATION_UPSIDEDOWN = 0 LCD_SET_BOTTOM_VIEW(); //6 o'clock mode, normal orientation #else LCD_SET_TOP_VIEW(); //12 o'clock mode, reversed orientation #endif LCD_SET_START_LINE(0); //set scrolling to 0 LCD_SET_PANEL_LOAD(3); //set panel loading to 28-38nF LCD_SET_BIAS_RATIO(3); //set bias ratio LCD_SET_VOLTAGE_BIAS(0x5F); //set Vbias potentiometer for contrast LCD_SET_RAM_ADDR_CTRL(1); //set auto-increment #endif #if DISPLAY_TYPE == 132 LCD_SET_FIRST_LINE(0); //first bit in RAM is on the first line of the LCD #if ORIENTATION_UPSIDEDOWN == 0 LCD_SET_BOTTOM_VIEW(); //6 o'clock mode, normal orientation LCD_ORIENTATION_NORMAL(); #else LCD_SET_TOP_VIEW(); //12 o'clock mode, reversed orientation LCD_ORIENTATION_UPSIDEDOWN(); #endif LCD_SHOW_ALL_PIXELS_OFF(); //Normal Pixel mode LCD_SET_MODE_POSITIVE(); //positive display LCD_SET_BIAS_RATIO_1_9(); //bias 1/9 LCD_SET_POWER_CONTROL(7); //power control mode: all features on LCD_SET_BIAS_VOLTAGE(3); //set voltage regulator R/R LCD_SET_VOLUME_MODE(0x1F); //volume mode set LCD_SET_INDICATOR_OFF(); //switch indicator off, no blinking #endif #if DISPLAY_TYPE == 128 LCD_SET_FIRST_LINE(0); //first bit in RAM is on the first line of the LCD #if ORIENTATION_UPSIDEDOWN == 0 LCD_SET_BOTTOM_VIEW(); //6 o'clock mode, normal orientation LCD_ORIENTATION_NORMAL(); #else LCD_SET_TOP_VIEW(); //12 o'clock mode, reversed orientation LCD_ORIENTATION_UPSIDEDOWN(); #endif LCD_SHOW_ALL_PIXELS_OFF(); //Normal Pixel mode LCD_SET_MODE_POSITIVE(); //positive display LCD_SET_BIAS_RATIO_1_7(); //bias 1/7 LCD_SET_POWER_CONTROL(7); //power control mode: all features on LCD_SET_BIAS_VOLTAGE(7); //set voltage regulator R/R LCD_SET_VOLUME_MODE(0x06); //volume mode set LCD_SET_INDICATOR_OFF(); //switch indicator off, no blinking #endif #if DISPLAY_TYPE == 102 LCD_SET_FIRST_LINE(0); //first bit in RAM is on the first line of the LCD #if ORIENTATION_UPSIDEDOWN == 0 LCD_SET_BOTTOM_VIEW(); //6 o'clock mode, normal orientation LCD_ORIENTATION_NORMAL(); #else LCD_SET_TOP_VIEW(); //12 o'clock mode, reversed orientation LCD_ORIENTATION_UPSIDEDOWN(); #endif LCD_SHOW_ALL_PIXELS_OFF(); //Normal Pixel mode LCD_SET_MODE_POSITIVE(); //positive display LCD_SET_BIAS_RATIO_1_9(); //bias 1/9 LCD_SET_POWER_CONTROL(7); //power control mode: all features on LCD_SET_BIAS_VOLTAGE(7); //set voltage regulator R/R LCD_SET_VOLUME_MODE(0x9); //volume mode set LCD_SET_ADV_PROG_CTRL(LCD_TEMPCOMP_HIGH); #endif lcd_clear_area_xy(LCD_RAM_PAGES,LCD_WIDTH,NORMAL,0,0); //clear display content LCD_SWITCH_ON(); //Switch display on return; }
//****************************************************************** //函数名: LCD_Init //作者: xiao冯@全动电子 //日期: 2013-02-22 //功能: LCD初始化 //输入参数:无 //返回值: 无 //修改记录:无 //****************************************************************** void lcd_init(void) { #if USE_HARDWARE_SPI //使用硬件SPI SPI1_Init(); #else LCD_GPIOInit();//使用模拟SPI #endif LCD_RESET(); //液晶屏复位 //************* Start Initial Sequence **********// //开始初始化液晶屏 LCD_WR_REG(0x11);//Sleep exit delay_ms (120); //ST7735R Frame Rate LCD_WR_REG(0xB1); LCD_WR_DATA(0x01); LCD_WR_DATA(0x2C); LCD_WR_DATA(0x2D); LCD_WR_REG(0xB2); LCD_WR_DATA(0x01); LCD_WR_DATA(0x2C); LCD_WR_DATA(0x2D); LCD_WR_REG(0xB3); LCD_WR_DATA(0x01); LCD_WR_DATA(0x2C); LCD_WR_DATA(0x2D); LCD_WR_DATA(0x01); LCD_WR_DATA(0x2C); LCD_WR_DATA(0x2D); LCD_WR_REG(0xB4); //Column inversion LCD_WR_DATA(0x07); //ST7735R Power Sequence LCD_WR_REG(0xC0); LCD_WR_DATA(0xA2); LCD_WR_DATA(0x02); LCD_WR_DATA(0x84); LCD_WR_REG(0xC1); LCD_WR_DATA(0xC5); LCD_WR_REG(0xC2); LCD_WR_DATA(0x0A); LCD_WR_DATA(0x00); LCD_WR_REG(0xC3); LCD_WR_DATA(0x8A); LCD_WR_DATA(0x2A); LCD_WR_REG(0xC4); LCD_WR_DATA(0x8A); LCD_WR_DATA(0xEE); LCD_WR_REG(0xC5); //VCOM LCD_WR_DATA(0x0E); LCD_WR_REG(0x36); //MX, MY, RGB mode LCD_WR_DATA(0xC8); //ST7735R Gamma Sequence LCD_WR_REG(0xe0); LCD_WR_DATA(0x0f); LCD_WR_DATA(0x1a); LCD_WR_DATA(0x0f); LCD_WR_DATA(0x18); LCD_WR_DATA(0x2f); LCD_WR_DATA(0x28); LCD_WR_DATA(0x20); LCD_WR_DATA(0x22); LCD_WR_DATA(0x1f); LCD_WR_DATA(0x1b); LCD_WR_DATA(0x23); LCD_WR_DATA(0x37); LCD_WR_DATA(0x00); LCD_WR_DATA(0x07); LCD_WR_DATA(0x02); LCD_WR_DATA(0x10); LCD_WR_REG(0xe1); LCD_WR_DATA(0x0f); LCD_WR_DATA(0x1b); LCD_WR_DATA(0x0f); LCD_WR_DATA(0x17); LCD_WR_DATA(0x33); LCD_WR_DATA(0x2c); LCD_WR_DATA(0x29); LCD_WR_DATA(0x2e); LCD_WR_DATA(0x30); LCD_WR_DATA(0x30); LCD_WR_DATA(0x39); LCD_WR_DATA(0x3f); LCD_WR_DATA(0x00); LCD_WR_DATA(0x07); LCD_WR_DATA(0x03); LCD_WR_DATA(0x10); LCD_WR_REG(0x2a); LCD_WR_DATA(0x00); LCD_WR_DATA(0x00); LCD_WR_DATA(0x00); LCD_WR_DATA(0x7f); LCD_WR_REG(0x2b); LCD_WR_DATA(0x00); LCD_WR_DATA(0x00); LCD_WR_DATA(0x00); LCD_WR_DATA(0x9f); LCD_WR_REG(0xF0); //Enable test command LCD_WR_DATA(0x01); LCD_WR_REG(0xF6); //Disable ram power save mode LCD_WR_DATA(0x00); LCD_WR_REG(0x3A); //65k mode LCD_WR_DATA(0x05); LCD_WR_REG(0x29);//Display on LCD_SetParam();//设置LCD参数 LCD_Clear(BLACK); LCD_LED_CLR;//点亮背光 }
int main(void){ bPriLev=PRI_MAIN; tTime.bDay=7; tTime.bMonth=8; tTime.bYear=11; _init(); while(1) { /* Infinite Loop */ switch(bState){ /*--------------------------------------------------------------------------------------------------*/ case STATE_IDLE: switch(bBtn){ case NO_BTN: if(bTimeColonToToggle){ toggleTimeColon(); bTimeColonToToggle=0; } refreshQuote(); bFirst=1; break; case BTN_A: case BTN_B: case BTN_C: case BTN_A_LONG: case BTN_B_LONG: START_BACKLIGHT(); bBtn=NO_BTN; break; case BTN_C_LONG: bState = STATE_MENU; BACKLIGHT_ON(); bBtn=NO_BTN; break; default: break; } break; /*--------------------------------------------------------------------------------------------------*/ case STATE_MENU: switch(bBtn){ case NO_BTN: if(bSelectionMenuChanged || bFirst){ bFirst=0; bSelectionMenuChanged=0; LCDWriteStringXY(0,0,"-"); LCDWriteStringXY(1,0, options[bSelectionMenu]); LCDWriteStringXY(0,1," "); LCDWriteStringXY(1,1, options[bSelectionMenu+1]); } break; case BTN_A: bSelectionMenu++; bSelectionMenu %= NUMBER_OF_OPTIONS; bSelectionMenuChanged=1; bBtn=NO_BTN; break; case BTN_B: if(bSelectionMenu>0) bSelectionMenu--; else bSelectionMenu=(NUMBER_OF_OPTIONS-1); bSelectionMenu %= NUMBER_OF_OPTIONS; bSelectionMenuChanged=1; bBtn=NO_BTN; break; case BTN_C: switch(bSelectionMenu){ case SEL_DATE: bState = STATE_EDIT_DATE; bBtn = NO_BTN; break; case SEL_TIME: bState = STATE_EDIT_TIME; bBtn = NO_BTN; break; case SEL_TIMEZONE: bState = STATE_EDIT_TIMEZONE; bBtn = NO_BTN; break; default: break; } bFirst=1; break; case BTN_C_LONG: bState = STATE_IDLE; bBtn=NO_BTN; BACKLIGHT_OFF(); START_BACKLIGHT(); LCD_RESET(); bSelectionMenu=0; bDateChanged=1; // Appena rientro in idle stampo le quote bTimeChanged=1; bTempChanged=1; break; default: break; } break; /*--------------------------------------------------------------------------------------------------*/ case STATE_EDIT_DATE: switch(bBtn){ case NO_BTN: if(bFirst){ bFirst=0; LCDClear(); tTimeEditing = tTime; sprintf(str, "%02d/%02d/%02d", tTimeEditing.bDay, tTimeEditing.bMonth, tTimeEditing.bYear); LCDWriteStringXY(0,0, "Editing date:"); LCDWriteStringXY(3,1, str); LCDCmd(0x0f); // set blinking cursor LCD_CURSOR_LEFT_N(8); } break; case BTN_A: bBtn = NO_BTN; changeEditDate(bSelectionDate, BTN_A); sprintf(str, "%02d/%02d/%02d", tTimeEditing.bDay, tTimeEditing.bMonth, tTimeEditing.bYear); LCDWriteStringXY(3,1,str); LCD_CURSOR_LEFT_N(8-bSelectionDate); break; case BTN_B: bBtn = NO_BTN; changeEditDate(bSelectionDate, BTN_B); sprintf(str, "%02d/%02d/%02d", tTimeEditing.bDay, tTimeEditing.bMonth, tTimeEditing.bYear); LCDWriteStringXY(3,1,str); LCD_CURSOR_LEFT_N(8-bSelectionDate); break; case BTN_C: if(bSelectionDate<7){ LCD_CURSOR_RIGHT_N(1); bSelectionDate++; } else{ bSelectionDate=0; LCD_CURSOR_LEFT_N(7); } // eseguo il controllo della data solo se passo da giorno a mese e da mese a anno if(bSelectionDate==2 || bSelectionDate==5){ LCD_CURSOR_RIGHT_N(1); bSelectionDate++; if(checkDate(&tTimeEditing, aDays)){ sprintf(str, "%02d/%02d/%02d", tTimeEditing.bDay, tTimeEditing.bMonth, tTimeEditing.bYear); LCDWriteStringXY(3,1,str); LCD_CURSOR_LEFT_N(8-bSelectionDate); } } bBtn = NO_BTN; break; case BTN_C_LONG: bState=STATE_EDIT_DATE_CONFIRM; bBtn=NO_BTN; bFirst=1; break; default: break; } break; /*--------------------------------------------------------------------------------------------------*/ case STATE_EDIT_DATE_CONFIRM: switch(bBtn){ case NO_BTN: if(bFirst){ LCDWriteStringXY(0,0, "Confermi? Si/No"); LCD_CURSOR_LEFT_N(5); bFirst=0; bSelectionDate=0; } if(bSelectionDateChanged){ if(bSelectionDate==0){ LCD_SET_CURSOR_POSITION(10); } else{ LCD_SET_CURSOR_POSITION(13); } bSelectionDateChanged=0; } break; case BTN_C: bSelectionDate = (bSelectionDate == 0)?1:0; bSelectionDateChanged=1; bBtn=NO_BTN; break; case BTN_C_LONG: if(bSelectionDate){ bState = STATE_MENU; bSelectionDate=0; }else{ tTime.bDay = tTimeEditing.bDay; tTime.bMonth = tTimeEditing.bMonth; tTime.bYear = tTimeEditing.bYear; bState = STATE_MENU; LCD_RESET(); } bBtn = NO_BTN; bFirst=1; break; default: break; } break; /*--------------------------------------------------------------------------------------------------*/ case STATE_EDIT_TIME: switch(bBtn){ case NO_BTN: if(bFirst){ bFirst=0; LCDClear(); tTimeEditing = tTime; sprintf(str, "%02d:%02d:%02d", tTimeEditing.bHour, tTimeEditing.bMin, tTimeEditing.bSec); LCDWriteStringXY(0,0, "Editing time:"); LCDWriteStringXY(3,1, str); LCDCmd(0x0f); // set blinking cursor LCD_CURSOR_LEFT_N(8); } break; case BTN_A: bBtn = NO_BTN; changeEditTime(bSelectionTime, BTN_A); sprintf(str, "%02d:%02d:%02d", tTimeEditing.bHour, tTimeEditing.bMin, tTimeEditing.bSec); LCDWriteStringXY(3,1,str); LCD_CURSOR_LEFT_N(8-bSelectionTime); break; case BTN_B: bBtn = NO_BTN; changeEditTime(bSelectionTime, BTN_B); sprintf(str, "%02d:%02d:%02d", tTimeEditing.bHour, tTimeEditing.bMin, tTimeEditing.bSec); LCDWriteStringXY(3,1,str); LCD_CURSOR_LEFT_N(8-bSelectionTime); break; case BTN_C: if(bSelectionTime<7){ LCDCmd(0x14); bSelectionTime++; } else{ bSelectionTime=0; LCD_CURSOR_LEFT_N(7); } if(bSelectionTime==2 || bSelectionTime==5){ LCDCmd(0x14); bSelectionTime++; } bBtn = NO_BTN; break; case BTN_C_LONG: bState=STATE_EDIT_TIME_CONFIRM; bBtn=NO_BTN; bFirst=1; break; default: break; } break; /*--------------------------------------------------------------------------------------------------*/ case STATE_EDIT_TIME_CONFIRM: switch(bBtn){ case NO_BTN: if(bFirst){ LCDWriteStringXY(0,0, "Confermi? Si/No"); LCD_CURSOR_LEFT_N(5); bFirst=0; bSelectionTime=0; } if(bSelectionTimeChanged){ if(bSelectionTime==0){ LCD_SET_CURSOR_POSITION(10); } else{ LCD_SET_CURSOR_POSITION(13); } bSelectionTimeChanged=0; } break; case BTN_C: bSelectionTime = (bSelectionTime == 0)?1:0; bSelectionTimeChanged=1; bBtn=NO_BTN; break; case BTN_C_LONG: if(bSelectionTime){ bState = STATE_MENU; bSelectionTime=0; }else{ tTime.bSec = tTimeEditing.bSec; tTime.bMin = tTimeEditing.bMin; tTime.bHour = tTimeEditing.bHour; bState = STATE_MENU; LCD_RESET(); } bBtn = NO_BTN; bFirst=1; break; default: break; } break; /*--------------------------------------------------------------------------------------------------*/ case STATE_EDIT_TIMEZONE: switch(bBtn){ case NO_BTN: if(bFirst){ bFirst=0; LCDClear(); LCDWriteStringXY(0,0, "Edit timezone:"); LCDWriteStringXY(0,1,"1="); } break; default: break; } break; default: break; } } }