/********************************************************************* * Function: void PutPixel(SHORT x, SHORT y) * * PreCondition: none * * Input: pixel position * * Output: none * * Side Effects: none * * Overview: puts pixel with current color at given position * * Note: none * ********************************************************************/ void PutPixel(SHORT x, SHORT y){ BYTE value; if(_clipRgn){ if(x<_clipLeft) return; if(x>_clipRight) return; if(y<_clipTop) return; if(y>_clipBottom) return; } x += DISP_START_COLUMN; CS_LAT_BIT = 0; // set address WriteCmd(CMD_COLUMN_ADDR_LSB|(x&0x0f)); WriteCmd(CMD_COLUMN_ADDR_MSB|((x>>4)&0x0f)); WriteCmd(CMD_PAGE_ADDR|(DISP_START_PAGE+(y>>2))); // read 4 pixels value = ReadData(); value = ReadData(); PMCONbits.PMPEN = 0; // suspend PMP value = PMDIN1; // read value PMCONbits.PMPEN = 1; // resume PMP // set pixel switch(y&0x03){ case 0: value &= 0b11111100; value |= _color; break; case 1: value &= 0b11110011; value |= _color<<2; break; case 2: value &= 0b11001111; value |= _color<<4; break; case 3: value &= 0b00111111; value |= _color<<6; break; } // set address WriteCmd(CMD_COLUMN_ADDR_LSB|(x&0x0f)); WriteCmd(CMD_COLUMN_ADDR_MSB|((x>>4)&0x0f)); WriteCmd(CMD_PAGE_ADDR|(DISP_START_PAGE+(y>>2))); // write 4 pixels back WriteData(value); CS_LAT_BIT = 1; }
void WriteDigit( char number,char pos ) { WriteCmd(0x44); STB = 0; Write1638( 0xc0 | pos ); Write1638( FontNumber[ 0X0f & number ]); STB = 1; WriteCmd( 0x89 ); }
void DisplaySetVop(uint8_t v) { I2C_SetSlaveAddr(DISPLAY_ADDRESS); WriteCmd(0x01);// jump to page 101 WriteCmd(0x0D); v|=0x80; WriteCmd(v);// V op I2C_Stop(); }
void DisplaySetMirror(int mirrorX, int mirrorY) { I2C_SetSlaveAddr(DISPLAY_ADDRESS); WriteCmd(0x1);// jump to page 111 WriteCmd(0x0E);// jump to page 110 mirrorX &= 1; mirrorY &= 1; WriteCmd(0x08 + (mirrorX << 2) + (mirrorY << 1));// mirror X, Y I2C_Stop(); }
void locate16(int row, int col) { switch(row) { case 1: WriteCmd(0x80+col-1); break; case 2: WriteCmd(0x90+col-1); break; case 3: WriteCmd(0x88+col-1); break; case 4: WriteCmd(0x98+col-1); break; } }
void Lcd_t::Init(void) { BckLt.Init(LCD_BCKLT_GPIO, LCD_BCKLT_PIN, LCD_BCKLT_TMR, LCD_BCKLT_CHNL, LCD_TOP_BRIGHTNESS); // Remap Timer15 to PB14 & PB15 AFIO->MAPR2 |= 0x00000001; // ==== GPIOs ==== // Configure LCD_XRES, LCD_XCS, LCD_SCLK & LCD_SDA as Push-Pull output PinSetupOut(LCD_GPIO, LCD_XRES, omPushPull); PinSetupOut(LCD_GPIO, LCD_XRES, omPushPull); PinSetupOut(LCD_GPIO, LCD_XCS, omPushPull); PinSetupOut(LCD_GPIO, LCD_SCLK, omPushPull); PinSetupOut(LCD_GPIO, LCD_SDA, omPushPull); // ========================= Init LCD ====================================== SCLK_Lo(); XCS_Hi(); // Reset display XRES_Lo(); chThdSleepMilliseconds(7); XRES_Hi(); WriteCmd(0xAF); // display ON // Reset display again XRES_Lo(); chThdSleepMilliseconds(7); XRES_Hi(); chThdSleepMilliseconds(7); // Initial commands WriteCmd(0xAF); // display ON WriteCmd(0xA4); // Set normal display mode WriteCmd(0x2F); // Charge pump on WriteCmd(0x40); // Set start row address = 0 WriteCmd(0xC8); // Mirror Y axis //WriteCmd(0xA1); // Mirror X axis // Set x=0, y=0 WriteCmd(0xB0); // Y axis initialization WriteCmd(0x10); // X axis initialisation1 WriteCmd(0x00); // X axis initialisation2 Cls(); // clear LCD buffer // ====================== Switch to USART + DMA ============================ PinSetupAlterFuncOutput(LCD_GPIO, LCD_SCLK, omPushPull); PinSetupAlterFuncOutput(LCD_GPIO, LCD_SDA, omPushPull); // Workaround hardware bug with disabled CK3 when SPI2 is enabled SPI2->CR2 |= SPI_CR2_SSOE; // ==== USART init ==== clock enabled, idle low, first edge, enable last bit pulse rccEnableUSART3(FALSE); USART3->CR1 = USART_CR1_UE; // Enable USART3->BRR = Clk.APB1FreqHz / LCD_UART_SPEED; USART3->CR2 = USART_CR2_CLKEN | USART_CR2_LBCL; // Enable clock, enable last bit clock USART3->CR1 = USART_CR1_UE | USART_CR1_M | USART_CR1_TE; USART3->CR3 = USART_CR3_DMAT; // Enable DMA at transmitter // DMA dmaStreamAllocate (LCD_DMA, IRQ_PRIO_LOW, nullptr, NULL); dmaStreamSetPeripheral(LCD_DMA, &USART3->DR); dmaStreamSetMemory0 (LCD_DMA, IBuf); dmaStreamSetTransactionSize(LCD_DMA, LCD_VIDEOBUF_SIZE); dmaStreamSetMode (LCD_DMA, LCD_DMA_TX_MODE); // Start transmission XCS_Lo(); dmaStreamEnable(LCD_DMA); }
//inicjalizacja sterownika void LcdInit(void) { int i; HAL_GPIO_WritePin(PORT_DISP_NOKIA,LCD_PWR,GPIO_PIN_RESET); HAL_GPIO_WritePin(PORT_DISP_NOKIA,LCD_BKLT,GPIO_PIN_RESET); delay_ms(500); HAL_GPIO_WritePin(PORT_DISP_NOKIA,LCD_BKLT,GPIO_PIN_SET); HAL_GPIO_WritePin(PORT_DISP_NOKIA,LCD_PWR,GPIO_PIN_SET); HAL_GPIO_WritePin(PORT_DISP_NOKIA,RES,GPIO_PIN_RESET); delay_ms(2); HAL_GPIO_WritePin(PORT_DISP_NOKIA,RES,GPIO_PIN_SET); WriteCmd(0x21);//komendy rozszerzone WriteCmd(0x05);//komenda „przelaczajaca” sterownik w tryb pracy zgodny PCD8544 WriteCmd(0xd5);//ustawienie Vop Delay(2); //WriteCmd(0x13);//bias WriteCmd(0x06);//korekcja temperatury dla PCD8544 WriteCmd(0x14);//wspólczynnik multipleksowania WriteCmd(0x20);//komendy standardowe - adresowanie poziome Delay(2); WriteCmd(0x0c);//tryb wyœwietlania Standard Mode WriteCmd(0x40);//zerowanie licznika wierszy WriteCmd(0x80);//zerowanie licznika kolumn Delay(2); // for(i=0;i<(48*84);i++)//612 // WriteData(0x00);//zerowanie pamieci RAM wyswietlacza LoWaterMark = LCD_CACHE_SIZE; HiWaterMark = 0; LcdClear(); LcdUpdate(); }
void DisplaySetInversion(int v) { I2C_SetSlaveAddr(DISPLAY_ADDRESS); WriteCmd(0x1);// jump to page 111 WriteCmd(0x0E);// jump to page 110 if(v!=0) WriteCmd(0x07); else WriteCmd(0x06); I2C_Stop(); }
/*-------------------------------------------------------------------------------------------------- Name : LcdClear Description : Clears the display. LcdUpdate must be called next. Argument(s) : None. Return value : None. --------------------------------------------------------------------------------------------------*/ void LcdClear ( void ) { unsigned int i; for ( i = 0; i <= LCD_CACHE_SIZE; i++ ) LcdCache[i] = 0x00; LoWaterMark = 0; HiWaterMark = LCD_CACHE_SIZE - 1; WriteCmd(0x80); WriteCmd(0x40); LcdUpdate(); }
void ILI9341_kbv::setAddrWindow(int16_t x, int16_t y, int16_t x1, int16_t y1) { CS_ACTIVE; WriteCmd(ILI9341_CMD_COLUMN_ADDRESS_SET); write16(x); write16(x1); WriteCmd(ILI9341_CMD_PAGE_ADDRESS_SET); write16(y); write16(y1); CS_IDLE; }
void Lcd_t::Task() { for (uint8_t i=0; i < LCD_VIDEOBUF_SIZE; i++) { WriteData(IBuf[i]); } WriteCmd(0xB3); // Y axis initialization WriteCmd(0x10); // X axis initialisation1 WriteCmd(0x08); // X axis initialisation2 if(BackligthValue != 50) { BackligthValue++; Backlight(BackligthValue); } chThdSleepMilliseconds(12); }
void ILI9341_kbv::drawPixel(int16_t x, int16_t y, uint16_t color) { // ILI934X just plots at edge if you try to write outside of the box: if (x < 0 || y < 0 || x >= width() || y >= height()) return; CS_ACTIVE; WriteCmd(ILI9341_CMD_COLUMN_ADDRESS_SET); write16(x); WriteCmd(ILI9341_CMD_PAGE_ADDRESS_SET); write16(y); WriteCmd(ILI9341_CMD_MEMORY_WRITE); write16(color); CS_IDLE; }
/** * @brief OLED_Fill,填充整个屏幕 * @param fill_Data:要填充的数据 * @retval 无 */ void OLED_Fill(unsigned char fill_Data)//全屏填充 { unsigned char m,n; for(m=0;m<8;m++) { WriteCmd(0xb0+m); //page0-page1 WriteCmd(0x00); //low column start address WriteCmd(0x10); //high column start address for(n=0;n<128;n++) { WriteDat(fill_Data); } } }
void LcdUpdate ( void ) { int i; if ( LoWaterMark < 0 ) LoWaterMark = 0; else if ( LoWaterMark >= LCD_CACHE_SIZE ) LoWaterMark = LCD_CACHE_SIZE - 1; if ( HiWaterMark < 0 ) HiWaterMark = 0; else if ( HiWaterMark >= LCD_CACHE_SIZE ) HiWaterMark = LCD_CACHE_SIZE - 1; WriteCmd( 0x80 | (LoWaterMark % LCD_X_RES)); WriteCmd( 0x40 | (LoWaterMark / LCD_X_RES)); for ( i = LoWaterMark; i <= HiWaterMark; i++ ) WriteData( LcdCache[i]); LoWaterMark = LCD_CACHE_SIZE - 1; HiWaterMark = 0; UpdateLcd = FALSE; }
void DisplayString( const char *msg) { CLK = 1; WriteCmd(0x40); STB = 0; Write1638( 0xC0 ); Write1638( FontChar[msg[0]-32] ); Write1638( 0b11111100 ); Write1638( FontChar[msg[1]-32] ); Write1638( 0b11111111 ); Write1638( FontChar[msg[2]-32] ); Write1638( 0b11111100 ); Write1638( FontChar[msg[3]-32] ); Write1638( 0b11111111 ); Write1638( FontChar[msg[4]-32] ); Write1638( 0b11111100 ); Write1638( FontChar[msg[5]-32] ); Write1638( 0b11111111 ); Write1638( FontChar[msg[6]-32] ); Write1638( 0b11111100 ); Write1638( FontChar[msg[7]-32] ); Write1638( 0b11111111 ); STB = 1; CLK = 1; }
void ILI9341_kbv::begin(uint16_t ID) { _lcd_ID = ID; uint8_t *p = (uint8_t *) tableNNNN; int16_t size = sizeof(tableNNNN); reset(); while (size > 0) { uint8_t cmd = pgm_read_byte(p++); uint8_t len = pgm_read_byte(p++); if (cmd == TFTLCD_DELAY8) { delay(len); len = 0; } else { CS_ACTIVE; WriteCmd(cmd); for (uint8_t d = 0; d < len; d++) { uint8_t x = pgm_read_byte(p++); xchg8(x); } CS_IDLE; } size -= len + 2; } setRotation(0); //PORTRAIT }
void Tc1602::SetCursorPos(uint8_t col, uint8_t row) { assert(row <= 3); const uint8_t row_offsets[] = { 0x00, 0x40, 0x14, 0x54 }; WriteCmd(LCD_SETDDRAMADDR | (col + row_offsets[row & 0x03])); }
void SetPixelBox(uchar xLeft, uchar yTop, uchar xRight, uchar yBottom, int fWrite) { WriteCmd(ocColAddr); WriteData(xLeft); WriteData(xRight); WriteCmd(ocRowAddr); WriteData(yTop); WriteData(yBottom); if (fWrite) WriteCmd(ocWriteRAM); else { WriteCmd(ocReadRAM); (void)Read(false); // dummy read } }
void WriteData(unsigned char Adress,unsigned char Data) { WriteCmd(0x44); STB = 0; Write1638( 0xc0 | Adress ); Write1638( Data ); STB = 1; }
void ILI9341_kbv::fillRect(int16_t x, int16_t y, int16_t w, int16_t h, uint16_t color) { int16_t end; if (w < 0) { w = -w; x -= w; } //+ve w end = x + w; if (x < 0) x = 0; if (end > width()) end = width(); w = end - x; if (h < 0) { h = -h; y -= h; } //+ve h end = y + h; if (y < 0) y = 0; if (end > height()) end = height(); h = end - y; setAddrWindow(x, y, x + w - 1, y + h - 1); CS_ACTIVE; WriteCmd(ILI9341_CMD_MEMORY_WRITE); if (h > w) { end = h; h = w; w = end; } while (h-- > 0) { write16_N(color, w); } CS_IDLE; setAddrWindow(0, 0, width() - 1, height() - 1); }
void LedRefresh (void) { CLK = 1; WriteCmd(0x40); STB = 0; Write1638( 0xC0 ); Write1638( FontNumber[DisplayBuffer[0]] ); Write1638( 0b11111100 ); Write1638( FontNumber[DisplayBuffer[1]] ); Write1638( 0b11111111 ); Write1638( FontNumber[DisplayBuffer[2]] ); Write1638( 0b11111100 ); Write1638( FontNumber[DisplayBuffer[3]] ); Write1638( 0b11111111 ); Write1638( FontNumber[DisplayBuffer[4]] ); Write1638( 0b11111100 ); Write1638( FontNumber[DisplayBuffer[5]] ); Write1638( 0b11111111 ); Write1638( FontNumber[DisplayBuffer[6]] ); Write1638( 0b11111100 ); Write1638( FontNumber[DisplayBuffer[7]] ); Write1638( 0b11111111 ); STB = 1; CLK = 1; }
void ILI9341_kbv::pushCommand(uint16_t cmd, uint8_t * block, int8_t N) { CS_ACTIVE; WriteCmd(cmd); write8_block(block, N); CS_IDLE; }
void Init1638(void) { STB = 1; CLK = 1; _delay(4000); WriteCmd( 0x40 ); WriteDisplayBuffer(); _delay(400); }
void InitDis(void) //��ʼ�� 12864 ��Ҫ�õ��� STM 32 �����š� { IOInitOut(); delay_init(72); //��ʼ����ʱ����������������� GPIO_SetBits(DisIOB,PSB); //��PSB=1������Ϊ��������ģʽ�� Delay_us(400); WriteCmd(0x30); //ѡ�����ָ����ͣ�8λ����ģʽ�� Delay_us(400); WriteCmd(0x0c); //����ʾ,���α�,������. Delay_us(400); WriteCmd(0x01); //�����ʾ������ DDRAM �ĵ�ַ������ AC ��Ϊ 00H. Delay_us(400); WriteCmd(0x06); //���ã��ⲿ��д���ݺ�,��ַ������ AC ���Զ��� 1�� Delay_us(400); WriteCmd(0x80); //�� DDRAM ��ַ������ AC ��Ϊ 0. Delay_us(400); }
void ILI9341_kbv::vertScroll(int16_t top, int16_t scrollines, int16_t offset) { int16_t bfa = HEIGHT - top - scrollines; // bottom fixed area int16_t vsp; vsp = top + offset; // vertical start position if (offset < 0) vsp += scrollines; //keep in unsigned range CS_ACTIVE; WriteCmd( 0x0033); write16(top); //TOP write16(scrollines); //VSA write16(bfa); //BFA WriteCmd(0x0037) write16(vsp); //VLSP CS_IDLE; }
void ClearScreen() { WriteCmd(ocClearWin); WriteData(0); WriteData(0); WriteData(xMost); WriteData(yMost); WaitMs(5); // give it time to finish }
void DrawCircle(uchar x, uchar y, uchar r, CLR clrOutline, CLR clrFill) { WriteCmd(ocDrawCirc); WriteData(x); // x center WriteData(y); // y center WriteData(r); // radius WriteClrCmd(clrOutline); WriteClrCmd(clrFill); WaitMs(5); // give it time to do the drawing }
void DrawLine(uchar x1, uchar y1, uchar x2, uchar y2, CLR clr) { WriteCmd(ocDrawLine); WriteData(x1); WriteData(y1); WriteData(x2); WriteData(y2); WriteClrCmd(clr); WaitMs(5); // give it time to do the drawing }
/********************************************************************* * Function: void ClearDevice(void) * * PreCondition: none * * Input: none * * Output: none * * Side Effects: none * * Overview: clears screen with current color * * Note: none * ********************************************************************/ void ClearDevice(void){ WORD counter; BYTE pattern; pattern = _color; pattern |= pattern<<2; pattern |= pattern<<4; CS_LAT_BIT = 0; WriteCmd(CMD_COLUMN_ADDR_LSB|(DISP_START_COLUMN&0x0f)); WriteCmd(CMD_COLUMN_ADDR_MSB|((DISP_START_COLUMN>>4)&0x0f)); WriteCmd(CMD_PAGE_ADDR|DISP_START_PAGE); for(counter=0; counter<(DWORD)(GetMaxX()+1)*(GetMaxY()+1)/4; counter++){ WriteData(pattern); } CS_LAT_BIT = 1; }
void DrawRectangle(uchar xLeft, uchar yTop, uchar xRight, uchar yBottom, CLR clrOutline, CLR clrFill) { WriteCmd(ocDrawRect); WriteData(xLeft); WriteData(yTop); WriteData(xRight); WriteData(yBottom); WriteClrCmd(clrOutline); WriteClrCmd(clrFill); WaitMs(5); // give it time to do the drawing }