/* * Simple program to demonstrate the use of OLED on Digilent Orbit BoosterPack * The OLED uses Solomon Systech SSD1306 controller. * The controller is configured so that the origin (0, 0) is at the upper left corner. * The display is not cleared in initialization. */ #include "TM4C123GH6PM.h" void OrbitOled_init(void); void SSI3Write(unsigned char data); void delayMs(int n); int main(void) { int i, j; char font_table[][6] = { /* sample font table */ {0x7e, 0x11, 0x11, 0x11, 0x7e, 0}, /* A */ {0x7f, 0x49, 0x49, 0x49, 0x36, 0}, /* B */ {0x3e, 0x41, 0x41, 0x41, 0x22, 0}}; /* C */ OrbitOled_init(); /* write ABC at the beginning of first line */ for (j = 0; j < 3; j++) for (i = 0; i < 6; i++) SSI3Write(font_table[j][i]); /* clear the rest of the line */ for (i = 0; i < 110; i++) SSI3Write(0); for (;;) { /* infinite loop */ } } void OrbitOled_init(void) { /* Initialize SSI3 */ SYSCTL->RCGCSSI |= 8; /* enable clock to SSI3 */ SYSCTL->RCGCGPIO |= 8; /* enable clock to GPIOD for SSI3 */ SYSCTL->RCGCGPIO |= 0x20; /* enable clock to GPIOF */ SYSCTL->RCGCGPIO |= 0x10; /* enable clock to GPIOE */ /* configure SSI3 as SPI for OLED */ SSI3->CR1 = 0; /* disable SSI and make it master */ SSI3->CC = 0; /* use system clock */ SSI3->CPSR = 2; /* prescaler divided by 2 */ SSI3->CR0 = 0x0007; /* 8 MHz SSI clock, SPI mode, 8 bit data */ SSI3->CR1 |= 2; /* enable SSI1 */ /* configure PORTD 3, 0 for SSI3 clock and Tx */ GPIOD->AMSEL &= ~0x09; /* disable analog for these pins */ GPIOD->DEN |= 0x09; /* and make them digital */ GPIOD->AFSEL |= 0x09; /* enable alternate function */ GPIOD->PCTL &= ~0x0000F00F; /* assign pins to SSI3 */ GPIOD->PCTL |= 0x00001001; /* assign pins to SSI3 */ /* configure the rest of the control pins */ /* VBAT (PF1) */ GPIOF->DIR |= 0x02; /* set PF1 as output pin */ GPIOF->DEN |= 0x02; /* set PF1 as digital pin */ GPIOF->DATA |= 0x02; /* set PF1 high */ /* VDD (PE1) */ GPIOE->DIR |= 0x02; /* set PE1 as output pin */ GPIOE->DEN |= 0x02; /* set PE1 as digital pin */ GPIOE->DATA |= 0x02; /* set PE1 high */ /* DC (PD7 needs be unlocked to modify) */ GPIOD->LOCK = 0x4C4F434B; /* unlock commit register */ GPIOD->CR = 0x80; /* make PD7 configurable */ GPIOD->LOCK = 0; /* lock commit register */ GPIOD->DIR |= 0x80; /* set PD7 pin as output pin */ GPIOD->DEN |= 0x80; /* set PD7 pin as digital pin */ GPIOD->DATA |= 0x80; /* set PD7 high */ /* RES (PE5) */ GPIOE->DIR |= 0x20; /* set PE5 pin as output pin */ GPIOE->DEN |= 0x20; /* set PE5 pin as digital pin */ GPIOE->DATA |= 0x20; /* set PE5 high */ /* CS (PD1) */ GPIOD->DIR |= 0x02; /* set PD1 pin as output pin */ GPIOD->DEN |= 0x02; /* set PD1 pin as digital pin */ GPIOD->DATA |= 0x02; /* set PD1 high */ /* start OLED initialization sequence */ GPIOD->DATA &= ~0x80; /* clear DC bit to go into command mode */ GPIOE->DATA &= ~0x02; /* turn on Vdd */ delayMs(1); /* wait for power up */ SSI3Write(0xAE); /* turn display off during initialization */ GPIOE->DATA &= ~0x20; /* pulse reset */ delayMs(1); GPIOE->DATA |= 0x20; SSI3Write(0x8D); /* enable charge pump */ SSI3Write(0x14); SSI3Write(0xD9); /* set pre-charge period */ SSI3Write(0xF1); GPIOF->DATA &= ~0x02; /* turn on Vcc */ delayMs(100); SSI3Write(0xA1); /* remap columns */ SSI3Write(0xC8); /* remap rows */ SSI3Write(0xDA); /* set COM config */ SSI3Write(0x20); /* scan top to bottom */ SSI3Write(0xAF); /* turn on display */ /* set cursor to the upper left corner */ SSI3Write(0x22); /* set page */ SSI3Write(0); /* to page 0 */ SSI3Write(0x00); /* set low nibble of column */ SSI3Write(0x10); /* set high nibble of column */ GPIOD->DATA |= 0x80; /* exit command mode */ } void SSI3Write(unsigned char data) { GPIOD->DATA &= ~0x02; /* assert SS low */ while((SSI3->SR & 2) == 0); /* wait until FIFO not full */ SSI3->DR = data; /* transmit high byte */ while(SSI3->SR & 0x10); /* wait until transmit complete */ GPIOD->DATA |= 0x02; /* keep SS idle high */ } /* delay n milliseconds (16 MHz CPU clock) */ void delayMs(int n) { int i, j; for(i = 0 ; i < n; i++) for(j = 0; j < 3180; j++) {} /* do nothing for 1 ms */ } /* This function is called by the startup assembly * code to perform system specific initialization tasks. */ void SystemInit(void) { /* Grant coprocessor access This is required since TM4C123G has a floating point coprocessor */ SCB->CPACR |= 0x00f00000; }