Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

/ * Seven - segment display counter * * This program counts number 0 - 3 on the seven segment display. * The seven segment

/* Seven-segment display counter
*
* This program counts number 0-3 on the seven segment display.
* The seven segment display is driven by a shift register which is
* connected to SSI2 in SPI mode.
*
* Built and tested with Keil MDK-ARM v5.28 and TM4C_DFP v1.1.0
*/
#include "TM4C123.h"
void delayMs(int n);
void sevenseg_init(void);
void SSI2_write(unsigned char data);
int main(void){
const static unsigned char digitPattern[]={0xB0,0xA4,0xF9,0xC0};
int i;
sevenseg_init(); // initialize SSI2 that connects to the shift registers
while(1){
SSI2_write(digitPattern[i]); // write digit pattern to the seven segments
SSI2_write((1<< i)); // select digit
if (++i >3)
i =0;
delayMs(4); //1000/60/4=4.17
}
}
// enable SSI2 and associated GPIO pins
void sevenseg_init(void){
SYSCTL->RCGCGPIO |=0x02; // enable clock to GPIOB
SYSCTL->RCGCGPIO |=0x04; // enable clock to GPIOC
SYSCTL->RCGCSSI |=0x04; // enable clock to SSI2
// PORTB 7,4 for SSI2 TX and SCLK
GPIOB->AMSEL &= ~0x90; // turn off analog of PORTB 7,4
GPIOB->AFSEL |=0x90; // PORTB 7,4 for alternate function
GPIOB->PCTL &= ~0xF00F0000; // clear functions for PORTB 7,4
GPIOB->PCTL |=0x20020000; // PORTB 7,4 for SSI2 function
GPIOB->DEN |=0x90; // PORTB 7,4 as digital pins
// PORTC 7 for SSI2 slave select
GPIOC->AMSEL &= ~0x80; // disable analog of PORTC 7
GPIOC->DATA |=0x80; // set PORTC 7 idle high
GPIOC->DIR |=0x80; // set PORTC 7 as output for SS
GPIOC->DEN |=0x80; // set PORTC 7 as digital pin
SSI2->CR1=0; // turn off SSI2 during configuration
SSI2->CC =0; // use system clock
SSI2->CPSR =16; // clock prescaler divide by 16 gets 1 MHz clock
SSI2->CR0=0x0007; // clock rate div by 1, phase/polarity 00, mode freescale, data size 8
SSI2->CR1=2; // enable SSI2 as master
}
// This function enables slave select, writes one byte to SSI2,
// wait for transmit complete and deassert slave select.
void SSI2_write(unsigned char data){
GPIOC->DATA &= ~0x80; // assert slave select
SSI2->DR = data; // write data
while (SSI2->SR & 0x10){}// wait for transmit done
GPIOC->DATA |=0x80; // deassert slave select
}
/* delay n milliseconds (50 MHz CPU clock)*/
void delayMs(int n){
int i, j;
for(i =0 ; i< n; i++)
for(j =0; j <6265; j++)
{}/* do nothing for 1 ms */
}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Processing

Authors: David Kroenke

11th Edition

0132302675, 9780132302678

More Books

Students also viewed these Databases questions