0% found this document useful (0 votes)
98 views19 pages

Esd Lab - 9

This document describes using a synchronous serial interface (SSI) module on a Tiva microcontroller to interface with a Nokia 5110 LCD. It provides the theory of SSI operation, algorithms for initializing the LCD and SSI, and an example code to display an image on the LCD by initializing the ports, SSI, and LCD, setting the cursor position, and writing data. The code initializes port A pins for SSI operation, enables the LCD peripherals, writes functions for LCD control, and displays an image by calling the initialization and writing functions.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
98 views19 pages

Esd Lab - 9

This document describes using a synchronous serial interface (SSI) module on a Tiva microcontroller to interface with a Nokia 5110 LCD. It provides the theory of SSI operation, algorithms for initializing the LCD and SSI, and an example code to display an image on the LCD by initializing the ports, SSI, and LCD, setting the cursor position, and writing data. The code initializes port A pins for SSI operation, enables the LCD peripherals, writes functions for LCD control, and displays an image by calling the initialization and writing functions.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 19

ESD LAB-9

SSI with Tiva


Microcontroller

KRISHNA KANT
EVD19I001
30-3-23
Objective

• A Synchronous serial interface (SSI) module is used to interface the Tiva


microcontroller to a Nokia5110 LCD.

• An image of choice is displayed using the LCD.


Theory:

SSI module Introduction :


• The TM4C123 microcontroller has 4 Synchronous Serial Interfaces or SSI
modules.
• Two devices communicating with synchronous serial interfaces (SSI) operate
from the same clock (synchronized)
• The SSI protocol includes four I/O lines
i) A negative logic control signal from master to slave signal signifying the
channel is active.
ii) A 50% duty cycle clock generated by the master.
iii) A data line driven by the master and received by the slave.
iv) A data line driven by the slave and received by the master.

SSI Initialization :
Initialize LCD write function :
Algorithm for 6 bit DAC :

• Include header files


• Initialize Port A for SSI
• Enable the required LCD peripheral settings
• Write functions to
o Set cursor position on LCD
o Clear LCD
o Draw image on LCD
• In the main call all the initialization functions
• Display an image of your choice

Algorithm for 6 bit DAC :

• The timer of cortex M-4 microcontrollers are utilized to create time delays
and generate periodic interrupts.
• It's based on a 24-bit down counter with an auto reload, which is called
“current”, which counts down at the bus clock frequency.
• It can be configured following 3 registers:
o SysTick Control and Status (STCTRL)
o SysTick Reload Value (STCTRL)
o SysTick Current Value (STCTRL)

GPIO MODULE:
• It stands for General Purpose Input Output Module
• The GPIO module gives access to the user to interface sensors and actuators
with the processor
• In TIVA TM4C123GH6PM Launch Pad there are 43 programmable input/output
pins divided into 6 ports.
• The Port F has an onboard LED connected and there are two onboard switches
that are connected in negative logic.
RUN MODE CLOCK GATING CONTROL REGISTER 2 (RCGC2):
• This register controls the clock gating logic in normal Run mode.
• Each bit, if set, the corresponding module receives a clock and functions.
• Otherwise, the module is un-clocked and disabled.

• The above table represents the case when port F is utilized


• In our case Port B and Port B is used
• The value of SYSCTL_RCG2_R changes to 0x0000_0010 ie 0x02 for PORT B and
0x0010_0000 ie 0x20 for Port F

• When we are interfacing sensors or actuators, we have to specify if the


directionality of the port, whether it is input or output
• In the case of LED, it is output and in case of switches it is input
• We have to specify in GPIODIR that it is 1 for output and 0 for input
Example

• Display the IIITDM logo in the Texas Nokia peripheral.


CODE:

/*Nokia LCD Display*/

// Blue Nokia 5110


// ---------------
// Signal (Nokia 5110) LaunchPad pin
// Reset (RST, pin 1) connected to PA7
// SSI0Fss (CE, pin 2) connected to PA3
// Data/Command (DC, pin 3) connected to PA6
// SSI0Tx (Din, pin 4) connected to PA5
// SSI0Clk (Clk, pin 5) connected to PA2
// 3.3V (Vcc, pin 6) power
// back light (BL, pin 7) not connected, consists of 4 white LEDs which draw ~80mA
total
// Ground (Gnd, pin 8) ground

// Red SparkFun Nokia 5110 (LCD-10168)


// -----------------------------------
// Signal (Nokia 5110) LaunchPad pin
// 3.3V (VCC, pin 1) power
// Ground (GND, pin 2) ground
// SSI0Fss (SCE, pin 3) connected to PA3
// Reset (RST, pin 4) connected to PA7
// Data/Command (D/C, pin 5) connected to PA6
// SSI0Tx (DN, pin 6) connected to PA5
// SSI0Clk (SCLK, pin 7) connected to PA2
// back light (LED, pin 8) not connected, consists of 4 white LEDs which draw
~80mA total

#include "tm4c123gh6pm.h"
#include <stdint.h>
#include "PLL.h"

// Maximum dimensions of the LCD, although the pixels are


// numbered from zero to (MAX-1). Address may automatically
// be incremented after each transmission.
#define MAX_X 84
#define MAX_Y 48

// Contrast value 0xB1 looks good on red SparkFun


// and 0xB8 looks good on blue Nokia 5110.
// Adjust this from 0xA0 (lighter) to 0xCF (darker) for your display.
#define CONTRAST 0xB1

// *************************** Screen dimensions


***************************
#define SCREENW 84
#define SCREENH 48

#define DC (*((volatile uint32_t *)0x40004100))


#define DC_COMMAND 0
#define DC_DATA 0x40
#define RESET (*((volatile uint32_t *)0x40004200))
#define RESET_LOW 0
#define RESET_HIGH 0x80

enum typeOfWrite{
COMMAND, // the transmission is an LCD command
DATA // the transmission is data
};

// The Data/Command pin must be valid when the eighth bit is


// sent. The SSI module has hardware input and output FIFOs
// that are 8 locations deep. Based on the observation that
// the LCD interface tends to send a few commands and then a
// lot of data, the FIFOs are not used when writing
// commands, and they are used when writing data. This
// ensures that the Data/Command pin status matches the byte
// that is actually being transmitted.
// The write command operation waits until all data has been
// sent, configures the Data/Command pin for commands, sends
// the command, and then waits for the transmission to
// finish.
// The write data operation waits until there is room in the
// transmit FIFO, configures the Data/Command pin for data,
// and then adds the data to the transmit FIFO.

// This is a helper function that sends an 8-bit message to the LCD.


// inputs: type COMMAND or DATA
// message 8-bit code to transmit
// outputs: none
// assumes: SSI0 and port A have already been initialized and enabled
void static lcdwrite(enum typeOfWrite type, uint8_t message){
if(type == COMMAND){
// wait until SSI0 not busy/transmit FIFO empty
while((SSI0_SR_R&0x00000010)==0x00000010){};
DC = DC_COMMAND;
SSI0_DR_R = message; // command out
// wait until SSI0 not busy/transmit FIFO empty
while((SSI0_SR_R&0x00000010)==0x00000010){};
} else{
while((SSI0_SR_R&0x00000002)==0){}; // wait until transmit FIFO not full
DC = DC_DATA;
SSI0_DR_R = message; // data out
}
}

void static lcddatawrite(uint8_t data){


while((SSI0_SR_R&0x00000002)==0){}; // wait until transmit FIFO not full
DC = DC_DATA;
SSI0_DR_R = data; // data out
}

//********Nokia5110_Init*****************
// Initialize Nokia 5110 48x84 LCD by sending the proper
// commands to the PCD8544 driver. One new feature of the
// LM4F120 is that its SSIs can get their baud clock from
// either the system clock or from the 16 MHz precision
// internal oscillator.
// inputs: none
// outputs: none
// assumes: system clock rate of 80 MHz
void Nokia5110_Init(void){
volatile uint32_t delay;
SYSCTL_RCGC1_R |= 0x00000010; // activate SSI0
SYSCTL_RCGC2_R |= 0x00000001; // activate port A
delay = SYSCTL_RCGC2_R; // allow time to finish activating
GPIO_PORTA_DIR_R |= 0xC0; // make PA6,7 out
GPIO_PORTA_AFSEL_R |= 0x2C; // enable alt funct on PA2,3,5
GPIO_PORTA_AFSEL_R &= ~0xC0; // disable alt funct on PA6,7
GPIO_PORTA_DEN_R |= 0xEC; // enable digital I/O on
PA2,3,5,6,7
GPIO_PORTA_PCTL_R = (GPIO_PORTA_PCTL_R&0xFF0F00FF)+0x00202200; //
configure PA2,3,5 as SSI
GPIO_PORTA_PCTL_R = (GPIO_PORTA_PCTL_R&0x00FFFFFF)+0x00000000; //
configure PA6,7 as GPIO
GPIO_PORTA_AMSEL_R &= ~0xEC; // disable analog functionality on
PA2,3,5,6,7
SSI0_CR1_R &= ~(0x00000002); // disable SSI
SSI0_CR1_R &= ~(0x00000004); // master mode
// configure for system clock/PLL baud clock source
SSI0_CC_R &= ~(0x0000000F);
// clock divider for 3.33 MHz SSIClk (80 MHz PLL/24)
// SysClk/(CPSDVSR*(1+SCR))
// 80/(24*(1+0)) = 3.33 MHz (slower than 4 MHz)
SSI0_CPSR_R = (SSI0_CPSR_R&~(0x000000FF))+24; // must be even number
SSI0_CR0_R &= ~(0x0000FFF0); // SCR = 0 (3.33 Mbps data rate) // SPH = 0 //
SPO = 0

// FRF = Freescale format


SSI0_CR0_R |= 0x00000007; // DSS = 8-bit data
SSI0_CR1_R |= 0x00000002; // enable SSI

RESET = RESET_LOW; // reset the LCD to a known state


for(delay=0; delay<10; delay=delay+1);// delay minimum 100 ns
RESET = RESET_HIGH; // negative logic

lcdwrite(COMMAND, 0x21); // chip active; horizontal addressing mode (V =


0); use extended instruction set (H = 1)
// set LCD Vop (contrast), which may require some tweaking:
lcdwrite(COMMAND, CONTRAST); // try 0xB1 (for 3.3V red SparkFun), 0xB8 (for
3.3V blue SparkFun), 0xBF if your display is too dark, or 0x80 to 0xFF if experimenting
lcdwrite(COMMAND, 0x04); // set temp coefficient
lcdwrite(COMMAND, 0x14); // LCD bias mode 1:48: try 0x13 or 0x14

lcdwrite(COMMAND, 0x20); // we must send 0x20 before modifying the


display control mode
lcdwrite(COMMAND, 0x0C); // set display control to normal mode: 0x0D for
inverse
}
//********Nokia5110_SetCursor*****************
// Move the cursor to the desired X- and Y-position. The
// next character will be printed here. X=0 is the leftmost
// column. Y=0 is the top row.
// inputs: newX new X-position of the cursor (0<=newX<=11)
// newY new Y-position of the cursor (0<=newY<=5)
// outputs: none
void Nokia5110_SetCursor(uint8_t newX, uint8_t newY){
if((newX > 11) || (newY > 5)){ // bad input
return; // do nothing
}
// multiply newX by 7 because each character is 7 columns wide
lcdwrite(COMMAND, 0x80|(newX*7)); // setting bit 7 updates X-position
lcdwrite(COMMAND, 0x40|newY); // setting bit 6 updates Y-position
}

//********Nokia5110_Clear*****************
// Clear the LCD by writing zeros to the entire screen and
// reset the cursor to (0,0) (top left corner of screen).
// inputs: none
// outputs: none
void Nokia5110_Clear(void){
int i;
for(i=0; i<(MAX_X*MAX_Y/8); i=i+1){
lcddatawrite(0x00);
}
Nokia5110_SetCursor(0, 0);
}

//********Nokia5110_DrawFullImage*****************
// Fill the whole screen by drawing a 48x84 bitmap image.
// inputs: ptr pointer to 504 byte bitmap
// outputs: none
// assumes: LCD is in default horizontal addressing mode (V = 0)
void Nokia5110_DrawFullImage(const uint8_t *ptr){
int i;
Nokia5110_SetCursor(0, 0);
for(i=0; i<(MAX_X*MAX_Y/8); i=i+1){
lcddatawrite(ptr[i]);
}
}

// image of a IIITDM logo


const unsigned char IIITDMlogo [] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x80, 0x80, 0x00, 0x00,
0x00, 0x00, 0x30, 0xF8, 0xD8, 0x18, 0x30, 0x30, 0x60, 0x60, 0xC0, 0xFE, 0x7F, 0x03,
0x06, 0x06,
0x0C, 0x38, 0x30, 0x30, 0x30, 0x3C, 0x8F, 0xC3, 0xC1, 0x83, 0x1E, 0x3C, 0x30, 0x30,
0x38, 0x0C,
0x06, 0x03, 0x03, 0x7F, 0x7E, 0xC0, 0x60, 0x20, 0x30, 0x18, 0x98, 0xE8, 0xF8, 0x10,
0x00, 0x00,
0x80, 0x80, 0x80, 0x80, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0xE0, 0xE0, 0xE0, 0x60,
0x60, 0x63,
0x67, 0x6D, 0x79, 0x73, 0x33, 0x02, 0x06, 0x06, 0x07, 0x83, 0xC0, 0xC0, 0xC6, 0xC4,
0xCC, 0xC8,
0xD8, 0xD8, 0xF0, 0xB0, 0xF0, 0xE0, 0xE0, 0xE0, 0xE0, 0xC4, 0xDF, 0xFF, 0xFF, 0xDF,
0xCE, 0xE0,
0xE0, 0xE0, 0xE0, 0xF0, 0xB0, 0xF8, 0xD8, 0xD8, 0xCC, 0xCC, 0xC4, 0xC6, 0xC0, 0xC0,
0x83, 0x83,
0x06, 0x03, 0x03, 0x03, 0x31, 0x79, 0x6D, 0x67, 0x23, 0x20, 0xB0, 0xB0, 0xF0, 0xE0,
0x60, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x38, 0x78,
0x78, 0x59,
0xC9, 0xCB, 0xCB, 0x8E, 0x0E, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
0x01, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x81, 0xC3, 0x63, 0xB7, 0xFF,
0x7F, 0x3F,
0x1F, 0x3E, 0xFF, 0xFF, 0xF3, 0xE3, 0xC3, 0x81, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00,
0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x0F,
0xCD, 0x6D,
0x6C, 0x6C, 0x2C, 0x3C, 0x38, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x0C,
0x1C, 0x16, 0x16, 0x12, 0x92, 0x93, 0xD3, 0x71, 0x70, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xC0, 0xF8, 0xFE, 0x8F, 0xE3,
0xFD, 0x7F,
0x07, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x07, 0xFE, 0xFD, 0xC7, 0x9F, 0xFC,
0xF0, 0x80,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00,
0x20, 0x78, 0x59, 0xD9, 0xDB, 0x9B, 0x1B, 0x0A, 0x0E, 0x0C, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x07, 0x05, 0x06, 0x06, 0x86, 0xE6, 0xF6,
0x9A, 0xDE,
0xCC, 0xC0, 0x60, 0x60, 0x60, 0xC0, 0xC0, 0x70, 0x70, 0x50, 0x76, 0x76, 0x70, 0x71,
0x71, 0x71,
0x7F, 0x5F, 0x7F, 0x7E, 0x2E, 0x7F, 0x7E, 0x73, 0x7E, 0x7B, 0x7A, 0x7E, 0x7E, 0x3E,
0x7D, 0x6F,
0x7F, 0x71, 0x71, 0x71, 0x60, 0x76, 0x66, 0x70, 0x70, 0x70, 0x70, 0xC0, 0xE0, 0x20,
0x60, 0x60,
0x44, 0xCE, 0xDF, 0xDB, 0xF2, 0x62, 0x02, 0x02, 0x06, 0x03, 0x03, 0x00, 0x00, 0x00,
0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0E, 0x1F, 0x1B, 0x08, 0x0C, 0x04, 0x06,
0x03, 0x03,
0x3F, 0x7E, 0x40, 0x60, 0x30, 0x38, 0x0C, 0x04, 0x04, 0x3C, 0x78, 0xC0, 0x80, 0xE0,
0x78, 0x1C,
0x0C, 0x04, 0x04, 0x1C, 0x18, 0x30, 0x60, 0x62, 0x7F, 0x3F, 0x03, 0x03, 0x06, 0x06,
0x0C, 0x0C,
0x0B, 0x0F, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
};

int main(void){

PLL_Init(); // set system clock to 80 MHz


Nokia5110_Init(); // Initialize SSI
Nokia5110_Clear(); // Clear LCD screen

Nokia5110_DrawFullImage(IIITDMlogo); //print IIITDM logo

}
Output

EXERCISE

• Display an image of your choice in the Texas Nokia peripheral.


/*Nokia LCD Display*/

// Blue Nokia 5110


// ---------------
// Signal (Nokia 5110) LaunchPad pin
// Reset (RST, pin 1) connected to PA7
// SSI0Fss (CE, pin 2) connected to PA3
// Data/Command (DC, pin 3) connected to PA6
// SSI0Tx (Din, pin 4) connected to PA5
// SSI0Clk (Clk, pin 5) connected to PA2
// 3.3V (Vcc, pin 6) power
// back light (BL, pin 7) not connected, consists of 4 white LEDs which draw ~80mA
total
// Ground (Gnd, pin 8) ground

// Red SparkFun Nokia 5110 (LCD-10168)


// -----------------------------------
// Signal (Nokia 5110) LaunchPad pin
// 3.3V (VCC, pin 1) power
// Ground (GND, pin 2) ground
// SSI0Fss (SCE, pin 3) connected to PA3
// Reset (RST, pin 4) connected to PA7
// Data/Command (D/C, pin 5) connected to PA6
// SSI0Tx (DN, pin 6) connected to PA5
// SSI0Clk (SCLK, pin 7) connected to PA2
// back light (LED, pin 8) not connected, consists of 4 white LEDs which draw ~80mA
total

#include "tm4c123gh6pm.h"
#include <stdint.h>
#include "PLL.h"

// Maximum dimensions of the LCD, although the pixels are


// numbered from zero to (MAX-1). Address may automatically
// be incremented after each transmission.
#define MAX_X 84
#define MAX_Y 48

// Contrast value 0xB1 looks good on red SparkFun


// and 0xB8 looks good on blue Nokia 5110.
// Adjust this from 0xA0 (lighter) to 0xCF (darker) for your display.
#define CONTRAST 0xB1

// *************************** Screen dimensions


***************************
#define SCREENW 84
#define SCREENH 48

#define DC (*((volatile uint32_t *)0x40004100))


#define DC_COMMAND 0
#define DC_DATA 0x40
#define RESET (*((volatile uint32_t *)0x40004200))
#define RESET_LOW 0
#define RESET_HIGH 0x80

enum typeOfWrite{
COMMAND, // the transmission is an LCD command
DATA // the transmission is data
};

// The Data/Command pin must be valid when the eighth bit is


// sent. The SSI module has hardware input and output FIFOs
// that are 8 locations deep. Based on the observation that
// the LCD interface tends to send a few commands and then a
// lot of data, the FIFOs are not used when writing
// commands, and they are used when writing data. This
// ensures that the Data/Command pin status matches the byte
// that is actually being transmitted.
// The write command operation waits until all data has been
// sent, configures the Data/Command pin for commands, sends
// the command, and then waits for the transmission to
// finish.
// The write data operation waits until there is room in the
// transmit FIFO, configures the Data/Command pin for data,
// and then adds the data to the transmit FIFO.

// This is a helper function that sends an 8-bit message to the LCD.


// inputs: type COMMAND or DATA
// message 8-bit code to transmit
// outputs: none
// assumes: SSI0 and port A have already been initialized and enabled
void static lcdwrite(enum typeOfWrite type, uint8_t message){
if(type == COMMAND){
// wait until SSI0 not busy/transmit FIFO empty
while((SSI0_SR_R&0x00000010)==0x00000010){};
DC = DC_COMMAND;
SSI0_DR_R = message; // command out
// wait until SSI0 not busy/transmit FIFO empty
while((SSI0_SR_R&0x00000010)==0x00000010){};
} else{
while((SSI0_SR_R&0x00000002)==0){}; // wait until transmit FIFO not full
DC = DC_DATA;
SSI0_DR_R = message; // data out
}
}

void static lcddatawrite(uint8_t data){


while((SSI0_SR_R&0x00000002)==0){}; // wait until transmit FIFO not full
DC = DC_DATA;
SSI0_DR_R = data; // data out
}

//********Nokia5110_Init*****************
// Initialize Nokia 5110 48x84 LCD by sending the proper
// commands to the PCD8544 driver. One new feature of the
// LM4F120 is that its SSIs can get their baud clock from
// either the system clock or from the 16 MHz precision
// internal oscillator.
// inputs: none
// outputs: none
// assumes: system clock rate of 80 MHz
void Nokia5110_Init(void){
volatile uint32_t delay;
SYSCTL_RCGC1_R |= 0x00000010; // activate SSI0
SYSCTL_RCGC2_R |= 0x00000001; // activate port A
delay = SYSCTL_RCGC2_R; // allow time to finish activating
GPIO_PORTA_DIR_R |= 0xC0; // make PA6,7 out
GPIO_PORTA_AFSEL_R |= 0x2C; // enable alt funct on PA2,3,5
GPIO_PORTA_AFSEL_R &= ~0xC0; // disable alt funct on PA6,7
GPIO_PORTA_DEN_R |= 0xEC; // enable digital I/O on PA2,3,5,6,7
GPIO_PORTA_PCTL_R = (GPIO_PORTA_PCTL_R&0xFF0F00FF)+0x00202200; //
configure PA2,3,5 as SSI
GPIO_PORTA_PCTL_R = (GPIO_PORTA_PCTL_R&0x00FFFFFF)+0x00000000; //
configure PA6,7 as GPIO
GPIO_PORTA_AMSEL_R &= ~0xEC; // disable analog functionality on PA2,3,5,6,7
SSI0_CR1_R &= ~(0x00000002); // disable SSI
SSI0_CR1_R &= ~(0x00000004); // master mode
// configure for system clock/PLL baud clock source
SSI0_CC_R &= ~(0x0000000F);
// clock divider for 3.33 MHz SSIClk (80 MHz PLL/24)
// SysClk/(CPSDVSR*(1+SCR))
// 80/(24*(1+0)) = 3.33 MHz (slower than 4 MHz)
SSI0_CPSR_R = (SSI0_CPSR_R&~(0x000000FF))+24; // must be even number
SSI0_CR0_R &= ~(0x0000FFF0); // SCR = 0 (3.33 Mbps data rate) // SPH = 0 //
SPO = 0

// FRF = Freescale format


SSI0_CR0_R |= 0x00000007; // DSS = 8-bit data
SSI0_CR1_R |= 0x00000002; // enable SSI

RESET = RESET_LOW; // reset the LCD to a known state


for(delay=0; delay<10; delay=delay+1);// delay minimum 100 ns
RESET = RESET_HIGH; // negative logic

lcdwrite(COMMAND, 0x21); // chip active; horizontal addressing mode (V =


0); use extended instruction set (H = 1)
// set LCD Vop (contrast), which may require some tweaking:
lcdwrite(COMMAND, CONTRAST); // try 0xB1 (for 3.3V red SparkFun), 0xB8 (for
3.3V blue SparkFun), 0xBF if your display is too dark, or 0x80 to 0xFF if experimenting
lcdwrite(COMMAND, 0x04); // set temp coefficient
lcdwrite(COMMAND, 0x14); // LCD bias mode 1:48: try 0x13 or 0x14

lcdwrite(COMMAND, 0x20); // we must send 0x20 before modifying the


display control mode
lcdwrite(COMMAND, 0x0C); // set display control to normal mode: 0x0D for
inverse
}

//********Nokia5110_SetCursor*****************
// Move the cursor to the desired X- and Y-position. The
// next character will be printed here. X=0 is the leftmost
// column. Y=0 is the top row.
// inputs: newX new X-position of the cursor (0<=newX<=11)
// newY new Y-position of the cursor (0<=newY<=5)
// outputs: none
void Nokia5110_SetCursor(uint8_t newX, uint8_t newY){
if((newX > 11) || (newY > 5)){ // bad input
return; // do nothing
}
// multiply newX by 7 because each character is 7 columns wide
lcdwrite(COMMAND, 0x80|(newX*7)); // setting bit 7 updates X-position
lcdwrite(COMMAND, 0x40|newY); // setting bit 6 updates Y-position
}
//********Nokia5110_Clear*****************
// Clear the LCD by writing zeros to the entire screen and
// reset the cursor to (0,0) (top left corner of screen).
// inputs: none
// outputs: none
void Nokia5110_Clear(void){
int i;
for(i=0; i<(MAX_X*MAX_Y/8); i=i+1){
lcddatawrite(0x00);
}
Nokia5110_SetCursor(0, 0);
}

//********Nokia5110_DrawFullImage*****************
// Fill the whole screen by drawing a 48x84 bitmap image.
// inputs: ptr pointer to 504 byte bitmap
// outputs: none
// assumes: LCD is in default horizontal addressing mode (V = 0)
void Nokia5110_DrawFullImage(const uint8_t *ptr){
int i;
Nokia5110_SetCursor(0, 0);
for(i=0; i<(MAX_X*MAX_Y/8); i=i+1){
lcddatawrite(ptr[i]);
}
}

const unsigned char rcb [] = {


0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x30, 0x38, 0x38, 0x38, 0x38, 0x38, 0x38,
0x38, 0x38,
0x38, 0x38, 0x38, 0xF8, 0xF0, 0xF0, 0xF0, 0xE0, 0x00, 0x00, 0xC0, 0xE0, 0xF0, 0xF0,
0x70, 0x38,
0x38, 0x38, 0x38, 0x38, 0x38, 0x38, 0x38, 0x38, 0x38, 0x18, 0x08, 0x00, 0x00, 0xA0,
0xB0, 0xB8,
0xB8, 0xB8, 0xB8, 0xB8, 0xB8, 0xB8, 0xB8, 0xB8, 0xB8, 0xB8, 0xF8, 0xF0, 0xF0, 0xF0,
0x60, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F,
0x03, 0x03,
0x03, 0x03, 0x03, 0x07, 0x07, 0x0F, 0x0F, 0x1F, 0x1F, 0x1B, 0x19, 0x10, 0x10, 0x00,
0x03, 0x07,
0x0F, 0x0F, 0x0E, 0x1C, 0x1C, 0x1C, 0x1C, 0x1C, 0x1C, 0x1C, 0x1C, 0x1C, 0x1C, 0x0C,
0x04, 0x00,
0x00, 0x1F, 0x1F, 0x1F, 0x1F, 0x1D, 0x1D, 0x1D, 0x1D, 0x1D, 0x1D, 0x1D, 0x1D, 0x1D,
0x1F, 0x0F,
0x0F, 0x0F, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
};

int main(void){

PLL_Init(); // set system clock to 80 MHz


Nokia5110_Init(); // Initialize SSI
Nokia5110_Clear(); // Clear LCD screen

Nokia5110_DrawFullImage(rcb); //print IIITDM logo

}
Output

Results
• A Synchronous serial interface (SSI) module is used to interface the Tiva
microcontroller to a Nokia5110 LCD and an image of choice is successfully
displayed using the given LCD

You might also like