void glcd_init(void) { #if defined(GLCD_CONTROLLER_PCD8544) /* * Set up SPI (SSP) * Note: Max allowed SPI clock is 4 MHz from datasheet. */ /* Select SSP/SPI port */ SSP_IOConfig( CONTROLLER_SPI_PORT_NUMBER ); /* Initialise SSP/SPI port */ SSP_Init( CONTROLLER_SPI_PORT_NUMBER ); /* Above functions take care of SPI pins */ /* Set SS, DC and RST pins to output */ CONTROLLER_SS_PORT->DIR |= (1 << CONTROLLER_SS_PIN); CONTROLLER_DC_PORT->DIR |= (1 << CONTROLLER_DC_PIN); CONTROLLER_RST_PORT->DIR |= (1 << CONTROLLER_RST_PIN); /* Deselect LCD */ //GLCD_DESELECT(); /* Reset the display */ glcd_reset(); /* Get into the EXTENDED mode! */ glcd_command(PCD8544_FUNCTION_SET | PCD8544_EXTENDED_INSTRUCTION); /* LCD bias select (4 is optimal?) */ glcd_command(PCD8544_SET_BIAS | 0x2); /* Set VOP */ glcd_command(PCD8544_SET_VOP | 50); // Experimentally determined /* Back to standard instructions */ glcd_command(PCD8544_FUNCTION_SET); /* Normal mode */ glcd_command(PCD8544_DISPLAY_CONTROL | PCD8544_DISPLAY_NORMAL); glcd_select_screen(glcd_buffer,&glcd_bbox); glcd_clear(); #else /* GLCD_CONTROLLER_PCD8544 */ #error "Controller not supported by LPC111x" #endif }
void glcd_init(void) { #if defined(GLCD_CONTROLLER_PCD8544) // Set up SPI (SSP) // Note: Max allowed SPI clock is 4 MHz from datasheet. // select SSP/SPI port SSP_IOConfig( PCD8544_SPI_PORT_NUMBER ); // initialise SSP/SPI port SSP_Init( PCD8544_SPI_PORT_NUMBER ); // above functions take care of SPI pins // set SS, DC and RST pins to output PCD8544_SS_PORT->DIR |= (1 << PCD8544_SS_PIN); PCD8544_DC_PORT->DIR |= (1 << PCD8544_DC_PIN); PCD8544_RST_PORT->DIR |= (1 << PCD8544_RST_PIN); // deselect LCD //GLCD_DESELECT(); // reset the display glcd_reset(); // get into the EXTENDED mode! glcd_command(PCD8544_FUNCTION_SET | PCD8544_EXTENDED_INSTRUCTION); // LCD bias select (4 is optimal?) glcd_command(PCD8544_SET_BIAS | 0x2); // set VOP glcd_command(PCD8544_SET_VOP | 50); // Experimentally determined // back to standard instructions glcd_command(PCD8544_FUNCTION_SET); // normal mode glcd_command(PCD8544_DISPLAY_CONTROL | PCD8544_DISPLAY_NORMAL); glcd_select_screen((uint8_t *)&glcd_buffer,&glcd_bbox); glcd_clear(); #else /* GLCD_CONTROLLER_PCD8544 */ #error Controller not supported. #endif }
void glcd_init_device(void) { /* STM32CubeMX generated code must be called elsewhere*/ #if defined(GLCD_CONTROLLER_ST7565R) /* Initialization for ST7565R controller */ /* Make sure chip is de-selected by default */ GLCD_DESELECT(); glcd_reset(); glcd_ST7565R_init(); #else #error "Controller not supported by STM32F10x" #endif }
void glcd_init(void) { #if defined(GLCD_CONTROLLER_PCD8544) /* Set up remappable outputs for PIC32, SPI: DO and SCK */ SpiChnOpen(SPI_CHANNEL2, SPI_CON_ON|SPI_CON_MSTEN, 4); /* Set SS, DC and RST pins as output */ PORTSetPinsDigitalOut(LCD_CS_PORT, LCD_CS_PIN); PORTSetPinsDigitalOut(LCD_DC_RESET_PORT, LCD_DC_PIN | LCD_RESET_PIN); /* Deselect LCD */ GLCD_DESELECT(); /* Send reset pulse to LCD */ glcd_reset(); /* Initialise the display */ glcd_PCD8544_init(); #else #error "Controller not supported" #endif /* GLCD_CONTROLLER_* */ }
void glcd_init(void) { #if defined(GLCD_CONTROLLER_PCD8544) /* Set pin directions */ /* * Set up SPI for AVR8 * Note: AVR's SS pin must be set to output, regardless of whether we * actually use it. This is a requirement of SPI mster mode. */ sbi(DDR(AVR_SS_PORT),AVR_SS_PIN); /* * Set MOSI, Master SS, SCK to output (otherwise SPI won't work) * Must be done even if native SS pin not used */ sbi(DDR(CONTROLLER_MOSI_PORT),CONTROLLER_MOSI_PIN); sbi(DDR(CONTROLLER_SS_PORT),CONTROLLER_SS_PIN); sbi(DDR(CONTROLLER_SCK_PORT),CONTROLLER_SCK_PIN); /* Set SS, DC and RST pins to output */ sbi( DDR(CONTROLLER_SS_PORT), CONTROLLER_SS_PIN ); sbi( DDR(CONTROLLER_DC_PORT), CONTROLLER_DC_PIN ); sbi( DDR(CONTROLLER_RST_PORT), CONTROLLER_RST_PIN ); /* Deselect LCD */ GLCD_DESELECT(); /* * Max allowed SPI clock is 4 MHz from datasheet. * Enable SPI, set master mode and clock rate to /4 (4MHz with F_CPU=8MHz) */ SPCR = (1<<SPE)|(1<<MSTR); SPSR = 0; glcd_reset(); /* Get into the EXTENDED mode! */ glcd_command(PCD8544_FUNCTION_SET | PCD8544_EXTENDED_INSTRUCTION); /* LCD bias select (4 is optimal?) */ glcd_command(PCD8544_SET_BIAS | 0x2); /* Set VOP */ glcd_command(PCD8544_SET_VOP | 50); // Experimentally determined /* Back to standard instructions */ glcd_command(PCD8544_FUNCTION_SET); /* Normal mode */ glcd_command(PCD8544_DISPLAY_CONTROL | PCD8544_DISPLAY_NORMAL); /* Select screen buffer */ glcd_select_screen(glcd_buffer,&glcd_bbox); /* Clear screen, we are now ready to go */ glcd_clear(); #elif defined(GLCD_CONTROLLER_ST7565R) /* Set up GPIO directions */ /* * Set up SPI for AVR8 * Note: AVR's SS pin must be set to output, regardless of whether we * actually use it. This is a requirement of SPI mster mode. */ sbi(DDR(AVR_SS_PORT),AVR_SS_PIN); /* Set SCK and MOSI as output */ sbi(DDR(CONTROLLER_SCK_PORT),CONTROLLER_SCK_PIN); sbi(DDR(CONTROLLER_MOSI_PORT),CONTROLLER_MOSI_PIN); /* * Set MISO as input with pullup. This needs to be set for * SPI to work, even though we never use or read it. */ cbi(DDR(CONTROLLER_MISO_PORT),CONTROLLER_MISO_PIN); // B3 MISO as input sbi(CONTROLLER_MISO_PORT,CONTROLLER_MISO_PIN); /* Set pin to controller SS as output */ sbi(DDR(CONTROLLER_SS_PORT),CONTROLLER_SS_PIN); // A5 /* Set LCD A0 pin as output */ sbi(DDR(CONTROLLER_A0_PORT),CONTROLLER_A0_PIN); // A6 /* Init SS pin high (i.e LCD deselected) */ sbi(CONTROLLER_SS_PORT,CONTROLLER_SS_PIN); /* Deselect LCD */ GLCD_DESELECT(); /* MSB first, double speed, SPI mode 0 */ SPCR = (1<<SPE) | (1<<MSTR) | (0<<CPOL) | (0<<CPHA); sbi(SPSR,SPI2X); /* Enable interrupts */ sei(); delay_ms(30); // example in datasheet does this (20ms) glcd_command(ST7565R_RESET); // internal reset glcd_command(0xa2); // 1/9 bias glcd_command(0xa0); // ADC select, normal glcd_command(0xc8); // com output reverse glcd_command(0xa4); // display all points normal glcd_command(0x40); // display start line set glcd_command(0x25); // internal resistor ratio glcd_command(0x81); // electronic volume mode set //glcd_command(0x10); // electronic volume - datasheet's contrast example doesn't work glcd_command(45); // this works better glcd_command(0x2f); // power controller set glcd_command(0xaf); // display on glcd_all_on();
void glcd_init(void) { #if defined(GLCD_CONTROLLER_PCD8544) /* Initialisation for PCD8544 controller */ /* Declare GPIO and SPI init structures */ GPIO_InitTypeDef GPIO_InitStructure; SPI_InitTypeDef SPI_InitStructure; //NVIC_InitTypeDef NVIC_InitStructure; /* Initialise structures (which we will overide later) */ GPIO_StructInit(&GPIO_InitStructure); SPI_StructInit(&SPI_InitStructure); /* Need to make start up the correct peripheral clocks */ RCC_APB2PeriphClockCmd(RCC_APB2Periph_SPI1, ENABLE); /* SS pin */ GPIO_InitStructure.GPIO_Pin = CONTROLLER_SPI_SS_PIN; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_Level_3; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT; GPIO_Init(CONTROLLER_SPI_SS_PORT, &GPIO_InitStructure); /* DC pin */ GPIO_InitStructure.GPIO_Pin = CONTROLLER_SPI_DC_PIN; GPIO_Init(CONTROLLER_SPI_DC_PORT, &GPIO_InitStructure); /* RESET pin */ GPIO_InitStructure.GPIO_Pin = CONTROLLER_SPI_RST_PIN; GPIO_Init(CONTROLLER_SPI_RST_PORT, &GPIO_InitStructure); /* Make sure chip is de-selected by default */ GLCD_DESELECT(); /* Set up GPIO for SPI pins */ GPIO_InitStructure.GPIO_Pin = CONTROLLER_SPI_SCK_PIN | CONTROLLER_SPI_MISO_PIN | CONTROLLER_SPI_MOSI_PIN; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_Level_3; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF; GPIO_Init(CONTROLLER_SPI_PORT, &GPIO_InitStructure); /* Configure alternate function mode for SPI pins */ GPIO_PinAFConfig(GPIOA,CONTROLLER_SPI_SCK_PINSRC,GPIO_AF_0); GPIO_PinAFConfig(GPIOA,CONTROLLER_SPI_MOSI_PINSRC,GPIO_AF_0); GPIO_PinAFConfig(GPIOA,CONTROLLER_SPI_MISO_PINSRC,GPIO_AF_0); /* Initialise SPI */ SPI_InitStructure.SPI_Direction = SPI_Direction_2Lines_FullDuplex; SPI_InitStructure.SPI_Mode = SPI_Mode_Master; SPI_InitStructure.SPI_DataSize = SPI_DataSize_8b; SPI_InitStructure.SPI_CPOL = SPI_CPOL_Low; SPI_InitStructure.SPI_CPHA = SPI_CPHA_2Edge; SPI_InitStructure.SPI_NSS = SPI_NSS_Soft; SPI_InitStructure.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_32; /* Set clock speed! */ SPI_InitStructure.SPI_FirstBit = SPI_FirstBit_MSB; SPI_InitStructure.SPI_CRCPolynomial = 7; SPI_Init(CONTROLLER_SPI_NUMBER, &SPI_InitStructure); /* Enable SPI interupts */ /* SPI_I2S_ITConfig(CONTROLLER_SPI_NUMBER, SPI_I2S_IT_TXE, ENABLE); NVIC_InitStructure.NVIC_IRQChannel = SPI1_IRQn; NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; NVIC_InitStructure.NVIC_IRQChannelPriority = 0x00; NVIC_Init(&NVIC_InitStructure); */ /* Enable SPI */ SPI_Cmd(CONTROLLER_SPI_NUMBER, ENABLE); /* Initialisation sequence of controller */ glcd_reset(); /* Get into the EXTENDED mode! */ glcd_command(PCD8544_FUNCTION_SET | PCD8544_EXTENDED_INSTRUCTION); /* LCD bias select (4 is optimal?) */ glcd_command(PCD8544_SET_BIAS | 0x2); /* Set VOP */ glcd_command(PCD8544_SET_VOP | 50); // Experimentally determined /* Back to standard instructions */ glcd_command(PCD8544_FUNCTION_SET); /* Normal mode */ glcd_command(PCD8544_DISPLAY_CONTROL | PCD8544_DISPLAY_NORMAL); glcd_select_screen((uint8_t *)&glcd_buffer,&glcd_bbox); glcd_set_contrast(50); glcd_clear(); #else #error "Controller not supported by STM32F0xx" #endif }
void glcd_init(void) { #if defined(GLCD_CONTROLLER_PCD8544) /* * Set up SPI (SSP) * Note: Max allowed SPI clock is 4 MHz from datasheet. */ /* Select SSP/SPI port */ SSP_IOConfig( CONTROLLER_SPI_PORT_NUMBER ); /* Initialise SSP/SPI port */ SSP_Init( CONTROLLER_SPI_PORT_NUMBER ); /* Above functions take care of SPI pins */ /* Set SS, DC and RST pins to output */ CONTROLLER_SS_PORT->DIR |= (1 << CONTROLLER_SS_PIN); CONTROLLER_DC_PORT->DIR |= (1 << CONTROLLER_DC_PIN); CONTROLLER_RST_PORT->DIR |= (1 << CONTROLLER_RST_PIN); /* Deselect LCD */ GLCD_DESELECT(); /* Reset the display */ glcd_reset(); /* Get into the EXTENDED mode! */ glcd_command(PCD8544_FUNCTION_SET | PCD8544_EXTENDED_INSTRUCTION); /* LCD bias select (4 is optimal?) */ glcd_command(PCD8544_SET_BIAS | 0x2); /* Set VOP */ glcd_command(PCD8544_SET_VOP | 50); // Experimentally determined /* Back to standard instructions */ glcd_command(PCD8544_FUNCTION_SET); /* Normal mode */ glcd_command(PCD8544_DISPLAY_CONTROL | PCD8544_DISPLAY_NORMAL); glcd_select_screen(glcd_buffer,&glcd_bbox); glcd_clear(); #elif defined(GLCD_CONTROLLER_NT75451) /* Parallel interface controller used on NGX BlueBoards */ /* Set 4x control lines pins as output */ LPC_GPIO->DIR[CONTROLLER_LCD_EN_PORT] |= (1U<<CONTROLLER_LCD_EN_PIN); LPC_GPIO->DIR[CONTROLLER_LCD_RW_PORT] |= (1U<<CONTROLLER_LCD_RW_PIN); LPC_GPIO->DIR[CONTROLLER_LCD_RS_PORT] |= (1U<<CONTROLLER_LCD_RS_PIN); LPC_GPIO->DIR[CONTROLLER_LCD_CS_PORT] |= (1U<<CONTROLLER_LCD_CS_PIN); /* Don't worry about setting default RS/RW/CS/EN, they get set during use */ #ifdef CONTROLLER_LCD_DATA_PORT /* Set data pins as output */ LPC_GPIO->DIR[CONTROLLER_LCD_D0_PORT] |= GLCD_PARALLEL_MASK; #else #error "Support of parallel data pins on different ports not supported." #endif /* Initialise sequence - code by NGX Technologies */ glcd_command(0xE2); /* S/W RESWT */ glcd_command(0xA0); /* ADC select */ glcd_command(0xC8); /* SHL Normal */ glcd_command(0xA3); /* LCD bias */ glcd_command(0x2F); /* Power control */ glcd_command(0x22); /* reg resistor select */ glcd_command(0x40); /* Initial display line 40 */ glcd_command(0xA4); /* Normal display */ glcd_command(0xA6); /* Reverce display a7 */ glcd_command(0x81); /* Ref vg select mode */ glcd_command(0x3f); /* Ref vg reg select */ glcd_command(0xB0); /* Set page address */ glcd_command(0x10); /* Set coloumn addr MSB */ glcd_command(0x00); /* Set coloumn addr LSB */ glcd_command(0xAF); /* Display ON */ /* Select default screen buffer */ glcd_select_screen(glcd_buffer,&glcd_bbox); /* Clear the screen buffer */ glcd_clear(); #else /* GLCD_CONTROLLER_PCD8544 */ #error "Controller not supported by LPC111x" #endif }
void glcd_init(void) { /* Initialization of device */ /* Declare GPIO and SPI init structures */ GPIO_InitTypeDef GPIO_InitStructure; SPI_InitTypeDef SPI_InitStructure; /* Configuring CS, DC (A0) and RST pin */ /* Peripheral clock init. */ RCC_AHB1PeriphClockCmd(CONTROLLER_SPI_DC_RCC | CONTROLLER_SPI_SS_RCC | \ CONTROLLER_SPI_RST_RCC, ENABLE); /* CS pin */ GPIO_InitStructure.GPIO_Pin = CONTROLLER_SPI_SS_PIN; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT; GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; GPIO_Init(CONTROLLER_SPI_SS_PORT, &GPIO_InitStructure); /* DC (A0) pin */ GPIO_InitStructure.GPIO_Pin = CONTROLLER_SPI_DC_PIN; GPIO_Init(CONTROLLER_SPI_DC_PORT, &GPIO_InitStructure); /* RST pin */ GPIO_InitStructure.GPIO_Pin = CONTROLLER_SPI_RST_PIN; GPIO_Init(CONTROLLER_SPI_RST_PORT, &GPIO_InitStructure); /* Make sure chip is de-selected by default */ GLCD_DESELECT(); /* * Configuring SPI: */ /* Enable the SPI clock */ SPIx_CLK_INIT(SPIx_CLK, ENABLE); /* Enable SPI GPIO clocks */ RCC_AHB1PeriphClockCmd(SPIx_SCK_GPIO_CLK | SPIx_MOSI_GPIO_CLK, ENABLE); /* Connect SPI pins to the corresponding alternate function */ GPIO_PinAFConfig(SPIx_SCK_GPIO_PORT, SPIx_SCK_SOURCE, SPIx_SCK_AF); GPIO_PinAFConfig(SPIx_MOSI_GPIO_PORT, SPIx_MOSI_SOURCE, SPIx_MOSI_AF); // GPIO_PinAFConfig(SPIx_MISO_GPIO_PORT, SPIx_MISO_SOURCE, SPIx_MISO_AF); GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz; GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_DOWN; /* SPI SCK pin configuration */ GPIO_InitStructure.GPIO_Pin = SPIx_SCK_PIN; GPIO_Init(SPIx_SCK_GPIO_PORT, &GPIO_InitStructure); /* SPI MOSI pin configuration */ GPIO_InitStructure.GPIO_Pin = SPIx_MOSI_PIN; GPIO_Init(SPIx_MOSI_GPIO_PORT, &GPIO_InitStructure); #if 0 GPIO_InitStructure.GPIO_Pin = SPIx_MISO_PIN; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_DOWN; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF; GPIO_InitStructure.GPIO_OType = GPIO_OType_OD; GPIO_Init(SPIx_MISO_GPIO_PORT, &GPIO_InitStructure); #endif /* SPI configuration */ SPI_I2S_DeInit(SPIx); SPI_InitStructure.SPI_Mode = SPI_Mode_Master; SPI_InitStructure.SPI_Direction = SPI_Direction_1Line_Tx; SPI_InitStructure.SPI_DataSize = SPI_DataSize_8b; SPI_InitStructure.SPI_CPOL = SPI_CPOL_Low; SPI_InitStructure.SPI_CPHA = SPI_CPHA_1Edge; SPI_InitStructure.SPI_NSS = SPI_NSS_Soft; /* Clock set to 8MHz */ SPI_InitStructure.SPI_BaudRatePrescaler = SPIx_PRESCALLER; SPI_InitStructure.SPI_FirstBit = SPI_FirstBit_MSB; SPI_Init(SPIx, &SPI_InitStructure); /* Enable the SPI peripheral */ SPI_Cmd(SPIx, ENABLE); RCC_AHB1PeriphClockCmd(LCD_LED_GPIO_RCC, ENABLE); GPIO_InitStructure.GPIO_Pin = LCD_LED_PIN; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT; GPIO_Init(LCD_LED_PORT, &GPIO_InitStructure); #if defined(GLCD_CONTROLLER_PCD8544) /* Initialisation sequence of controller */ glcd_PCD8544_init(); #elif defined(GLCD_CONTROLLER_ST7565R) glcd_reset(); glcd_enable_backlight(ENABLE); glcd_ST7565R_init(); #else #error "Controller not supported by STM32F0xx" #endif }