Skip to content

Instantly share code, notes, and snippets.

@RickKimball
Created October 16, 2012 22:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save RickKimball/3902327 to your computer and use it in GitHub Desktop.
Save RickKimball/3902327 to your computer and use it in GitHub Desktop.
SugarAddict lcd driver
/*
* main.c
*/
#include "inc\hw_types.h"
#include "inc\hw_memmap.h"
#include "driverlib\pin_map.h"
#include "inc\lm4f120h5qr.h"
#include "driverlib\sysctl.h"
#include "driverlib\ssi.h"
#include "driverlib\gpio.h"
void LCDSend(unsigned long ulData);
void LCDInit();
void LCDGotoXY(short col, short row);
int main(void) {
SysCtlClockSet(
SYSCTL_SYSDIV_4 | SYSCTL_USE_PLL | SYSCTL_XTAL_16MHZ
| SYSCTL_OSC_MAIN);
// Nuke on-board LEDs
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);
GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE,
GPIO_PIN_1 | GPIO_PIN_2 | GPIO_PIN_3);
GPIOPinWrite(GPIO_PORTF_BASE, (GPIO_PIN_1 | GPIO_PIN_2 | GPIO_PIN_3), 0x00);
// PB0: Reset
// PB1: Chip Select(L)
// PB2: Data(H)/Command(L)
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB); // Before SSI
GPIOPinTypeGPIOOutput(GPIO_PORTB_BASE,
GPIO_PIN_0 | GPIO_PIN_1 | GPIO_PIN_2);
// Setup SSI
SysCtlPeripheralEnable(SYSCTL_PERIPH_SSI2);
GPIOPinConfigure(GPIO_PB4_SSI2CLK);
GPIOPinConfigure(GPIO_PB5_SSI2FSS);
GPIOPinConfigure(GPIO_PB6_SSI2RX);
GPIOPinConfigure(GPIO_PB7_SSI2TX);
GPIOPinTypeSSI(GPIO_PORTB_BASE,
GPIO_PIN_4 | GPIO_PIN_5 | GPIO_PIN_6 | GPIO_PIN_7);
SSIConfigSetExpClk(SSI2_BASE, SysCtlClockGet(), SSI_FRF_MOTO_MODE_0,
SSI_MODE_MASTER, 20000000, 8);
SSIEnable(SSI2_BASE);
LCDInit();
LCDGotoXY(1, 1);
LCDSend(0x46);
LCDSend(0x49);
LCDSend(0x49);
LCDSend(0x49);
LCDSend(0x31);
while (1) {
SysCtlDelay(100);
}
}
void LCDSend(unsigned long ulData) {
GPIOPinWrite(GPIO_PORTB_BASE, GPIO_PIN_1, 0x00); // CS LOW
SysCtlDelay(200);
SSIDataPut(SSI2_BASE, ulData);
while (SSIBusy(SSI2_BASE)) { //kill time
}
GPIOPinWrite(GPIO_PORTB_BASE, GPIO_PIN_1, 0x02); // CS HIGH
SysCtlDelay(200);
}
void LCDInit() {
// Initially only Reset High
GPIOPinWrite(GPIO_PORTB_BASE, (GPIO_PIN_0 | GPIO_PIN_1 | GPIO_PIN_2), 0x01);
SysCtlDelay(200);
// Set all High
GPIOPinWrite(GPIO_PORTB_BASE, (GPIO_PIN_0 | GPIO_PIN_1 | GPIO_PIN_2), 0x07);
SysCtlDelay(200);
// Reset Low
GPIOPinWrite(GPIO_PORTB_BASE, (GPIO_PIN_0 | GPIO_PIN_1 | GPIO_PIN_2), 0x06);
SysCtlDelay(200);
// Reset High
GPIOPinWrite(GPIO_PORTB_BASE, (GPIO_PIN_0 | GPIO_PIN_1 | GPIO_PIN_2), 0x07);
SysCtlDelay(200);
// Command Low
GPIOPinWrite(GPIO_PORTB_BASE, (GPIO_PIN_0 | GPIO_PIN_1 | GPIO_PIN_2), 0x03);
SysCtlDelay(200);
LCDSend(0xA6); //Display: Normal
LCDSend(0xA3); //LCD Bias Settings: 1/7 (0xA2 for 1/9)
LCDSend(0xA0); //ADC Selection: Reverse
LCDSend(0xA1); //ADC Selection: Reverse
//LCDSend(0xC8); //Common Output: Upside Down
LCDSend(0xC0); //Common Output: Normal Direction
LCDSend(0x22); //Set the V5 output Voltage
LCDSend(0x81); //set Electronic Volume - brightness
LCDSend(0x2E); //Power Controller Set:
LCDSend(0x2F); //Power Controller Set: Voltage follower circuit: ON
LCDSend(0xE3); //Non-OPeration Command
LCDSend(0x40); //Set the start line
LCDSend(0xAF); //LCD On
LCDSend(0xA4); //Display All Points: NORMAL
// Data High
GPIOPinWrite(GPIO_PORTB_BASE, (GPIO_PIN_0 | GPIO_PIN_1 | GPIO_PIN_2), 0x07);
SysCtlDelay(200);
}
void LCDGotoXY(short col, short row) {
GPIOPinWrite(GPIO_PORTB_BASE, GPIO_PIN_2, 0x00); // Command Low
SysCtlDelay(200);
LCDSend(0xB0 + row); // page address
col += 18;
LCDSend(0x10 + (col >> 4)); // column address
LCDSend(0x00 + (col & 0x0F));
GPIOPinWrite(GPIO_PORTB_BASE, GPIO_PIN_2, 0x04); // Data High
SysCtlDelay(200);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment