void LCD_init(void) { _delay_ms(50); // 연결 핀을 출력으로 설정 if(MODE == 8) DDR_DATA |= 0xFF; else DDR_DATA |= 0xF0; DDR_CONTROL |= (1 << RS_PIN) | (1 << E_PIN); if(MODE == 8) LCD_write_command(COMMAND_8_BIT_MODE); // 8비트 모드 else{ LCD_write_command(0x02); // 4비트 모드 추가 명령 LCD_write_command(COMMAND_4_BIT_MODE); // 4비트 모드 } // display on/off control // 화면 on, 커서 off, 커서 깜빡임 off uint8_t command = 0x08 | (1 << COMMAND_DISPLAY_ON_OFF_BIT); LCD_write_command(command); LCD_clear(); // 화면 지움 // Entry Mode Set // 출력 후 커서를 오른쪽으로 옮김, 즉, DDRAM의 주소가 증가하며 화면 이동은 없음 LCD_write_command(0x06); }
static rt_err_t rt_lcd1602_control(rt_device_t dev, rt_uint8_t cmd, void *args) { switch (cmd) { case DispClear: //LcdUserData.CurCmd = DispEnd; LCD_write_command(0x01); break; case DispConnecting: LcdUserData.CurCmd = DispConnecting; LcdUserData.CurStartIndex = 0; //if (lcd_thread_filename != RT_NULL) //rt_thread_resume(lcd_thread_filename); //if (lcd_thread_connect != RT_NULL) //rt_thread_resume(lcd_thread_connect); break; case DispProcessing: LcdUserData.CurCmd = DispProcessing; LcdUserData.Percent = *((uint8_t*)args); break; case DispEnd: LcdUserData.CurCmd = DispEnd; break; } return RT_EOK; }
void LCD_set_xy( unsigned char x, unsigned char y ) //写地址函数 { unsigned char address; if (y == 0) address = 0x80 + x; else address = 0xc0 + x; LCD_write_command(address); }
void LCD_goto_XY(uint8_t row, uint8_t col) { col %= 16; // [0 15] row %= 2; // [0 1] // 첫째 라인 시작 주소는 0x00, 둘째 라인 시작 주소는 0x40 uint8_t address = (0x40 * row) + col; uint8_t command = 0x80 + address; LCD_write_command(command); // 커서 이동 }
int LCD_PutStr(unsigned char *DData,int pos, int size) { unsigned char i; if(pos==-1) { LCD_write_command(0x01); //清屏 rt_thread_delay(2); pos=0; } while ((*DData)!='\0' && size) { switch(*DData) { case '\n': //如果是\n,则换行 { if(pos<17) { for(i=pos; i<16; i++) LCD_write_char(i%16, i/16, ' '); pos=16; } else { for(i=pos; i<32; i++) LCD_write_char(i%16, i/16, ' '); pos=0; } break; } case '\b': //如果是\b,则退格 { if(pos>0) pos--; LCD_write_char(pos%16, pos/16, ' '); break; } default: { if((*DData)<0x20) { *DData=' '; } LCD_write_char(pos%16, pos/16, *DData); pos++; break; } } DData++; size--; } return(pos); }
void set_temp_init(void) { u16 value; u08 step = 0, empty, tmp[2]; u08 day[3], month[3], year[5]; u08 temp1[3], temp2[3]; u08 skipLoop = 0; LCD_write_command(0x0f); waitms(20); do { empty = 0; LCD_gotoxy((2 + step), 2); value = decode_rc5(); switch (value) { case KEY_0: { LCD_puts("0"); strcpy(tmp, "0"); break; } case KEY_1: { LCD_puts("1"); strcpy(tmp, "1"); break; } case KEY_2: { LCD_puts("2"); strcpy(tmp, "2"); break; } case KEY_3: { LCD_puts("3"); strcpy(tmp, "3"); break; } case KEY_4: { LCD_puts("4"); strcpy(tmp, "4"); break; } case KEY_5: { LCD_puts("5"); strcpy(tmp, "5"); break; } case KEY_6: { LCD_puts("6"); strcpy(tmp, "6"); break; } case KEY_7: { LCD_puts("7"); strcpy(tmp, "7"); break; } case KEY_8: { LCD_puts("8"); strcpy(tmp, "8"); break; } case KEY_9: { LCD_puts("9"); strcpy(tmp, "9"); break; } case KEY_LEFT: { if (step == 5) { step -= 4; } else if (step == 11) { step -= 5; } else { step--; } skipLoop = 1; break; } case KEY_RIGHT: { empty = 1; break; } default: { step--; empty = 1; break; } } if(skipLoop) { skipLoop = 0; continue; } if (!empty) { switch (step) { case 0: strcpy(temp1, tmp); break; case 1: strcat(temp1, tmp); break; case 5: strcpy(temp2, tmp); break; case 6: strcat(temp2, tmp); break; default: break; } } step++; if (step == 2) step += 3; if (step == 7) step += 4; } while (step <= 11); LCD_write_command(0x0C); if (m_dayTemp >= 0 && m_nightTemp >= 0) { m_requiresSettings |= SETTING_TEMP; } m_dayTemp = (atoi(temp1) % 90); m_nightTemp = (atoi(temp2) % 90); m_offsetTemp = (atoi(tmp) % 90); }
void LCD_clear(void) { LCD_write_command(COMMAND_CLEAR_DISPLAY); _delay_ms(2); }
void LCD_init(void) // { LCD_GPIO_Init(); #if 1 Delay_1ms(20); w_4bit_INIT_LCD1602(0x30); //写第一次0x3N命令(N为任意值) Delay_1ms(10); //至少延迟4.1ms w_4bit_INIT_LCD1602(0x30); //写第二次0x3N命令(N为任意值) Delay_1us(200); //至少延迟100us w_4bit_INIT_LCD1602(0x30); //写第三次0x3N命令(N为任意值) Delay_1us(100); //至少延迟40us w_4bit_INIT_LCD1602(0x20); //设置为4位模式 Delay_1us(100); //至少延迟40us LCD_write_command(0x28); //设置为4位模式,2行字符,5 x 7点阵/每字符 Delay_1us(100); //至少延迟40us LCD_write_command(0x06); //写入新数据后光标右移,写入新数据后显示屏不移动 Delay_1us(100); //至少延迟40us LCD_write_command(0x0e); //显示功能开,有光标,光标不闪烁 Delay_1us(100); //至少延迟40us LCD_write_command(0x01); //清除液晶显示器 Delay_1ms(10); //至少延迟1.64ms GPIO_ResetBits(LCD1602_RW_PORT, LCD1602_RW_PIN); Delay_1ms(10); #else LCD_write_command(0x33); Delay_1ms(5); LCD_write_command(0x28); Delay_1ms(5); LCD_write_command(0x28); Delay_1ms(5); LCD_write_command(0x28); Delay_1ms(5); LCD_en_write(); Delay_1ms(5); LCD_write_command(0x28); //4 Delay_1ms(5); LCD_write_command(0x0c); // 显示开 Delay_1ms(5); LCD_write_command(0x01); // 清屏 Delay_1ms(5); GPIO_ResetBits(LCD1602_RW_PORT, LCD1602_RW_PIN); #endif }