SlideShare a Scribd company logo
1 of 16
Lab 2_5
EENG 3910: Project V - Digital Signal
Processing System Design
9/21/2015
Joseph Chandler
University of North Texas
College of Engineering
Electrical Engineering
Introduction
Lab 2_5 continuesthe studyof the TivaTM
C SeriesEK-TM4C123GXL and CCS software.Lab2_5 's aspects
consistof systemcontrols,timing,uartanddifferentmodules.
Results and Discussions
Problem 5
#include <stdint.h>
Thisline containsthe headerfile forvariabledefinitions.The headerfile isalreadydefinedinthe CCS
software.Examplesof the valuesare bitsize,precision,andsignedorunsignedintegers.
#include <stdbool.h>
Thisline containsthe headerfile forBooleandefinitions.The headerfile isalreadydefinedinthe CCS
software.The file definitionsare usedforoperations,comparingvariables,andprogramcontrol flow.
#include "inc/tm4c123gh6pm.h"
Thisline containsthe headerfile forthe TM4C123GH6PM microcontroller.The headerfile ispart-
specificandcontainsmacrosand definitionstosimplifyprogrammingthe peripheral'sregistersand
interruptcontrol.Thisiscontainedinthe incdirectory. The .c file forthe TM4C123GH6PM
microcontrollerisincludedinthe projectfolderfordirectaccess.
#include "inc/hw_memmap.h"
Thisline containsthe headerfile forthe TivaCSeriesdevice memorymapdefinitions.The headerfile
containsmanyof the same definitionsusedfordirectregisteraccess.The headerfilecontainsmacros
and definitionstosimplifyprogrammingthe peripheral'sregistersandinterruptcontrol.Thisis
containedinthe incdirectory.The definitionsare usedbydriverlibraries andare hiddenfromthe
programmer.
#include "inc/hw_types.h"
Thisline containsthe headerfile forcommontypesandmacros.The headerfile containsmanyof the
same definitionsusedfordirectregisteraccess.Thisiscontainedinthe incdirectory.The definitionsare
usedbydriverlibrariesandare hiddenfromthe programmer.The valuesare a wide varietyof general
use for itemssuchas arithmetic,clocktiming,file recognition,anddevicerecognition.
#include "inc/hw_gpio.h"
Thisline contains the headerfile forcommontypesandmacros.The headerfile containsmanyof the
same definitionsusedfordirectregisteraccess.Thisiscontainedinthe incdirectory.The definitionsare
usedbydriverlibrariesandare hiddenfromthe programmer.The valuesare a wide varietyof general
use for itemssuchas arithmetic,clocktiming,file recognition,anddevicerecognition.
#include "driverlib/sysctl.h"
Thisline containsthe headerfile forthe SystemControl APIdefinitionsandmacros.The headerfile isin
the directory"driverlib"of the CCSsoftware.The driversprovideguidedcontrol of the peripheralsand
allowsforquickapplication.Enablingperipheralsisanexampleof thiscontrol.
#include "driverlib/interrupt.h"
Thisline containsthe headerfile forthe SystemControl APIdefinitionsandmacros.The headerfile isin
the directory"driverlib"of the CCSsoftware.The driversprovideguidedcontrol of the peripheralsand
allowsforquickapplication.Enablingperipheralsisanexampleof thiscontrol.
#include "driverlib/gpio.h"
Thisline containsthe headerfile forGPIOAPIdefinitionsandmacros.The headerfile isinthe directory
"driverlib"of the CCSsoftware.The driverprovidesasetof functionstocontrol the inputand output
module.
#include "driverlib/timer.h"
Thisline containsthe headerfile forTimerAPIdefinitionsandmacros.The headerfile isinthe directory
"driverlib"of the CCSsoftware.The driversprovide quickcontrol of the peripheralsandallowsforquick
application.The timerAPIprovidesasetof functionsforusingthe timermodule.
#include "driverlib/pin_map.h"
Thisline containsthe headerfile forpin_mapAPIdefinitionsandmacros.The headerfile isinthe
directory"driverlib"of the CCSsoftware.The driversprovidequickcontrol of the peripheralsandallows
for quickapplication.The pin_map APIprovidesamapof the peripheral topinconfiguration.
#include "driverlib/uart.h"
Thisline containsthe headerfile forUART(Universal AsynchronousReceiver/Transmitter) API
definitionsandmacros.The headerfile isinthe directory"driverlib"of the CCSsoftware.The drivers
provide quickcontrol of the peripheralsandallowsforquickapplication.The UARTAPIprovidesasetof
functionsforusingthe TIVA UART module.
#include "utils/uartstdio.h"
Thisline containsthe header file forUART.The header file isinthe directory"utils"of the CCS
software.The utilityprovidesquickcontrol of the peripheralsandallowsforquickapplication. The file
containsprototypesforthe UART console functions.Onbuildingthe project,the .cfile hadtobe added
manuallytolinkthe filestogether.
#define RED_LED GPIO_PIN_1
Createsa constantfor pin1 inthe GPIO APImodule thatdisplaysthe red LED.
#define BLUE_LED GPIO_PIN_2
Createsa constantfor pin2 inthe GPIO APImodule thatdisplaysthe blue LED.
#define GREEN_LED GPIO_PIN_3
Createsa constantfor pin3 inthe GPIO APImodule thatdisplaysthe greenLED.
#define NUM_BUTTONS 2
Createsa constantusedfor the twoswitchbuttons.
#define LEFT_BUTTON GPIO_PIN_4
Createsa constantfor pin4 inthe GPIO APImodule forleftswitchbutton.
#define RIGHT_BUTTON GPIO_PIN_0
Createsa constantfor pin0 inthe GPIO APImodule rightswitchbutton.
#define NUM_DEBOUNCE_CHECKS 10
It checksbefore aswitchis debounced. Createsaconstantusedfor50msec debounce time.
#define TIMER0_FREQ 2
Createsa constantusedfor frequencyinthe TimerAPImacrowitha value of 2.
#define TIMER1_FREQ 200
Createsa constantusedfor frequencyinthe Timer APImacrowitha value of 200.
#define UART0_BAUDRATE 115200
Createsa constantusedfor baudrate inthe UART API macro witha of value 115200 bps.
#define NUM_DISP_TEXT_LINE 4
Createsa constantfor the numberof linesof textdisplayinthe characterpointer"disp_text"witha
value of 4.
void init_LEDs(void);
Thisline declaresthe functionprototype "init_LEDs".Declarationatthispointgivesthe actual functiona
global scope.Anyotherfunction,header,or.c file containedinthissource file isgivenaccesstothe
functionandaccessible bythe function.
void init_timer(void);
Thisline declaresthe functionprototype " init_timer".Declarationatthispointgivesthe actual function
a global scope.Anyotherfunction,header,or.cfile containedinthissource fileisgivenaccesstothe
functionandaccessible bythe function.
void init_UART(void);
Thisline declaresthe functionprototype " init_UART".Declarationatthispointgivesthe actual function
a global scope.Anyotherfunction,header,or.cfile containedinthissource fileisgivenaccesstothe
functionandaccessible bythe function.
void init_buttons(void);
Thisline declaresthe functionprototype " init_buttons".Declarationatthispointgivesthe actual
functionaglobal scope.Anyotherfunction,header,or.cfile containedinthissource fileisgivenaccess
to the functionandaccessible bythe function.
void set_button_states(void);
Thisline declaresthe functionprototype " set_button_states ".Declarationatthispointgivesthe actual
functionaglobal scope.Anyotherfunction,header,or.cfile containedinthissource fileisgivenaccess
to the functionandaccessible bythe function.
void Timer0_ISR(void);
Thisline declaresthe functionprototype " Timer0_ISR".Declarationat thispointgivesthe actual
functionaglobal scope.Anyotherfunction,header,or.cfile containedinthissource fileisgivenaccess
to the functionandaccessible bythe function.
void Timer1_ISR(void);
Thisline declaresthe functionprototype " Timer1_ISR".Declarationat thispointgivesthe actual
functionaglobal scope.Anyotherfunction,header,or.cfile containedinthissource fileisgiven access
to the functionandaccessible bythe function.
extern void UARTStdioIntHandler(void);
Thisline declaresafunctionprototype of type "extern".Thisinformsthe microprocessorthatitneedsto
access a functionthatexistsoutsideof thissource file.The uartstdio.cfileisincludedinthe project
folderfordirectaccess.The uartstdio.cfile hasadditional functionsforthe UARTconsole.Thisparticular
functionhandlesinterruptsfromthe UART.The UART has a transmitandreceive bufferthatis usedfor
data transfersbetweenthe microprocessorandthe puttyconsole.
uint32_t sys_clock;
Createsan unsigned32-bitglobal variable forthe systemclock.
uint8_t cur_LED = RED_LED;
Createsan unsigned8-bitglobal variable forthe systemclock.
const char *disp_text[NUM_DISP_TEXT_LINE] = {
"n",
"UART and LED Demon",
"H: help, R: red, G: green, B: blue.n",
"> " };
Thisline createsa pointer fora systemmessage communicated tothe userviaputtyconsole.
volatile uint8_t raw_button_states[NUM_DEBOUNCE_CHECKS];
Createsan unsigned8-bitglobal arrayfordebounce.
volatile uint32_t raw_button_states_index=0;
Createsan unsigned32-bitglobal variable forinitializing index pointerof state.
volatile uint8_t button_states=0;
Createsan unsigned8-bitglobal variable forinitializingdebounced state.
int main(void){
The main processcallsandacts on variables,macros,definitions,andothersystemfunctions.
uint32_t i;
Createsan unsigned32-bitvariable forloops.
unsigned char user_cmd;
Createsan unsignedcharactervariable foruserinput.
uint8_t saved_button_states=0, cur_button_states;
SysCtlClockSet(SYSCTL_SYSDIV_5|SYSCTL_USE_PLL|SYSCTL_XTAL_16MHZ|SYSCTL_OSC_MAIN);
SystemControl ClockSetsetsthe clockingof the device.Osc_Mainconfiguresthe oscillatorsource.
XTAL_16MHZ usesa 16 MHZ crystal clock. USE_PLL is a phase lockedloopat400MHZ. SYSDIV_5 divides
the clock bythe numberspecifiedgiving control of the frequency.
sys_clock = SysCtlClockGet();
Thisline retrievesthe processorclockrate andassignsit toa variable.
init_LEDs();
InitializesLEDconfigurationandenables by calling the function definition.
init_buttons();
Initializesbuttonsconfigurationandenables by calling the function definition.
init_UART();
InitializesUARTconfigurationandenables by calling the function definition.
init_timer();
InitializesTimerconfigurationandenables by calling the function definition.
IntMasterEnable();
ThisNVICAPIfunctionenablesinterruptsfromthe microprocessortointerruptcontroller.
TimerEnable(TIMER0_BASE, TIMER_A);
ThisTIMER API functionenablesoperationof the timer module.
TimerEnable(TIMER1_BASE, TIMER_A);
ThisTIMER API functionenablesoperationof the timer module.
for(i=0; i<NUM_DISP_TEXT_LINE; i++)
Thisline isa for loopto displayprogrammessage onconsole.
UARTprintf(disp_text[i]);
Thisfunctionprintsthe message onthe console.
while(1) {
The while loopprovidesacontinuousloopwhensetto"1".
if(UARTRxBytesAvail())
If the UART has available userinput.
user_cmd = UARTgetc();
Thisline retrievesthe userinputandstoresitina variable.
else
user_cmd = 0;
Else,the usercommandvariable issetto 0.
switch(user_cmd){
Switchcase for the userinputdata.
case 'r':
Switchcase for red.
case ' ':
Switchcase for empty.
case 'H':
Switchcase for H.
case 'h':
Switchcase for h.
for(i=0; i<NUM_DISP_TEXT_LINE; i++)
Switchcase display forlines87-90 is a for looptodisplayconsole message touserviaputtyconsole.
UARTprintf(disp_text[i]);
Thisfunctionprintsthe message onthe puttyconsole.
break;
Switchcase break.
case 'R':
Switchcase for redled.
case 'r':
Switchcase for redled.
cur_LED = RED_LED;
Storesthe red ledincurrentledvariable.
UARTprintf("n> ");
Thisfunctionprintsa newline witha> on the console.
break;
Switchcase break.
case 'B':
Switchcase for blue led.
case 'b':
Switchcase for blue led.
cur_LED = BLUE_LED;
Storesthe blue ledincurrentledvariable.
UARTprintf("n> ");
Thisfunctionprintsa newline witha> on the console.
break;
Switchcase break.
case 'G':
Switchcase for greenled.
case 'g':
Switchcase for greenled.
cur_LED = GREEN_LED;
Storesthe greenledincurrentledvariable.
UARTprintf("n> ");
Thisfunctionprintsa newline witha> on the console.
break;
Switchcase break.
// Check button states.
cur_button_states = button_states;
if(saved_button_states != cur_button_states){
if((~saved_button_states & LEFT_BUTTON) && (cur_button_states &
LEFT_BUTTON)) {
UARTprintf("Left button pushed down.n> ");
}
if((saved_button_states & LEFT_BUTTON) && (~cur_button_states &
LEFT_BUTTON)) {
UARTprintf("Left button released.n> ");
}
if((~saved_button_states & RIGHT_BUTTON) && (cur_button_states &
RIGHT_BUTTON)) {
UARTprintf("Right button pushed down.n> ");
}
if((saved_button_states & RIGHT_BUTTON) && (~cur_button_states &
RIGHT_BUTTON)) {
UARTprintf("Right button released.n> ");
}
if(cur_button_states == (LEFT_BUTTON | RIGHT_BUTTON)) {
UARTprintf("Both buttons held down.n> ");
}
saved_button_states = cur_button_states;
}
*The programcomparesincomingdatato saveddata. Whenthe data is notthe same,a nestedIF
statement ANDsall entriesof the array to configure the switchbuttonoutputdisplayonthe UART.
void init_LEDs(void)
User-definedfunctiondefinitionforinitializingLEDs.The functionreturnsavalue of 0.
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);
The SystemControl APIfunctionenablesthe GPIOportF peripheral.
GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3);
The GPIO APIfunction configurespins1,2, and3 of portF for use as GPIO outputs.
void init_timer(void)
User-definedfunctiondefinitionforinitializingTimer.The functionreturnsavalue of 0.
SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER0);
The SystemControl APIfunction enablesthe timer0peripheral.
SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER1);
The SystemControl APIfunctionenablesthe timer1peripheral.
TimerConfigure(TIMER0_BASE, TIMER_CFG_PERIODIC);
The TimerAPI functionconfiguresthe timerasa 32-bitfull-widthperiodictimer.
TimerLoadSet(TIMER0_BASE, TIMER_A, sys_clock/TIMER0_FREQ -1);
The TimerAPI functionspecifiesthe base addressforconfiguration,the correctname fora full-width
timer,andthe load value specifiedbyuser-definedconstants.
TimerConfigure(TIMER1_BASE, TIMER_CFG_PERIODIC);
The TimerAPI functionconfiguresthe timerasa 32-bitfull-widthperiodictimer.
TimerLoadSet(TIMER1_BASE, TIMER_A, sys_clock/TIMER0_FREQ -1);
The TimerAPI functionspecifiesthe base addressforconfiguration,the correctname fora full-width
timer,andthe load value specifiedbyuser-definedconstants.
IntRegister(INT_TIMER0A, Timer0_ISR);
The NVICAPIfunctionregistersthe "TIMER0_ISR"functiontobe calledwhenthe "TIMER0A"interruptis
enabled.
IntEnable(INT_TIMER0A);
The NVICAPIfunctionenables"TIMER0A"asa full-widthtimer tobe usedforthe interruptfunction
process.
TimerIntEnable(TIMER0_BASE, TIMER_TIMA_TIMEOUT);
The TimerAPI functionenablesthe specifictimermodule(TIMER0_Base) forthe timer interruptsource.
The bit maskof the interruptsource tobe enabledis"TIMER_TIMA_TIMEOUT".
IntRegister(INT_TIMER1A, Timer1_ISR);
The NVICAPIfunctionregistersthe "TIMER1_ISR"functiontobe calledwhenthe "TIMER0A"interruptis
enabled.
IntEnable(INT_TIMER1A);
The NVICAPIfunctionenables"TIMER1A"asa full-widthtimer tobe usedforthe interruptfunction
process.
TimerIntEnable(TIMER1_BASE, TIMER_TIMA_TIMEOUT);
The TimerAPI functionenablesthe specifictimermodule(TIMER1_Base) forthe timerinterruptsource.
The bit maskof the interruptsource tobe enabledis"TIMER_TIMA_TIMEOUT".
void init_UART(void)
User-definedfunctiondefinitionforinitializingUART.The functionreturnsavalue of 0.
SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0);
The SystemControl APIfunctionenablesthe UART0 peripheral.
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);
The SystemControl APIfunctionenablesthe GPIOA peripheral.
GPIOPinConfigure(GPIO_PA0_U0RX);
The GPIO APIfunctionconfiguresthe alternate functionof aGPIO pin.GPIOPort A's pinmux is
configuredforthe UART peripheral.Pin0is configuredforthe UARTreceiverbuffer.
GPIOPinConfigure(GPIO_PA1_U0TX);
The GPIO APIfunctionconfiguresthe alternate functionof aGPIO pin.GPIOPort A's pinmux is
configuredforthe UART0 peripheral.Pin1isconfiguredforthe UART transmitterbuffer.
GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1);
The GPIO APIfunctionconfigurespinsforuse bythe UART peripheral.GPIOPort A will be the peripheral
usedforUART communication.Pins0and1 of port A are available.
IntRegister(INT_UART0, UARTStdioIntHandler);
The NVICAPIfunctionregistersthe "UARTStdioIntHandler"functiontobe calledwhenthe "UART0"
interruptisenabled.
UARTStdioConfig(0, UART0_BAUDRATE, sys_clock);
The UART driverfunctionconfiguresthe UARTforinput/output.UARTPort0 isthe base that will be
used.The user-definedconstant"UART0_BAUDRATE"isthe bitrate forthe UART and the user-defined
constant "sys_clock"isthe frequencyusedforthe source clockof the UART module.
void Timer0_ISR(void)
User-definedfunctiondefinitionforinterrupthandler.The functionreturnsavalue of 0.
TimerIntClear(TIMER0_BASE, TIMER_TIMA_TIMEOUT);
The TimerAPI functionclearsthe timerinterruptsources.TIMER0 isthe base specifiedand
"TIMER_TIMA_TIMEOUT" isthe bitmaskfor the interruptsource cleared.
if(GPIOPinRead(GPIO_PORTF_BASE, GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3)) {
If the GPIOAPIfunctionreadspins1,2, or 3 fromport F.
GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3, 0);
The GPIO APIfunctionwritesa0 to pins1,2, or 3.
else {
Else the GPIO APIfunction...
GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3, cur_LED);
Writesthe value of the variable "cur_LED" to the correct pin.
void Timer1_ISR(void)
User-definedfunctiondefinitionforinterrupthandler.The functionreturnsavalue of 0.
TimerIntClear(TIMER1_BASE, TIMER_TIMA_TIMEOUT);
The TimerAPI functionclearsthe timerinterruptsources.TIMER1 isthe base specifiedand
"TIMER_TIMA_TIMEOUT" isthe bitmaskfor the interruptsource cleared.
set_button_states();
void init_buttons(void)
User-definedfunctiondefinitionfor switchbuttons.
uint32_t i
Createsan unsigned32-bitlocal index variable.
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);
The SystemControl APIfunctionenablesthe GPIO peripheral portF.
HWREG(GPIO_PORTF_BASE + GPIO_O_LOCK) = GPIO_LOCK_KEY;
Unlock port F from NMI as GPIO input pin.
HWREG(GPIO_PORTF_BASE + GPIO_O_CR) |= 0x01;
Configure port F base to enable pins 0 and 4.
HWREG(GPIO_PORTF_BASE + GPIO_O_LOCK) = 0;
Relock port F for permanent configuration.
GPIODirModeSet(GPIO_PORTF_BASE, LEFT_BUTTON|RIGHT_BUTTON, GPIO_DIR_MODE_IN);
The GPIO APIfunctionconfigurespins0and4 of portF for use as GPIO inputs.
GPIOPadConfigSet(GPIO_PORTF_BASE, LEFT_BUTTON|RIGHT_BUTTON,
GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_STD_WPU);
The GPIO APIfunctionconfigures pins0and4 of portF for weak pull-upbuttontype.
for(i=0; i<NUM_DEBOUNCE_CHECKS; i++)
raw_button_states[i] = 0;
The for loopmaintainsbounce statusfromuserinterface.
void set_button_states(void)
User-definedfunctiondefinitionforbuttonstates.
uint32_t i
Createsan unsigned32-bitlocal index variable.
uint8_t states = LEFT_BUTTON|RIGHT_BUTTON;
Createsan unsigned8-bitlocal GPIOportF pinnumber variable.
raw_button_states[raw_button_states_index] = ~ GPIOPinRead(GPIO_PORTF_BASE,
LEFT_BUTTON|RIGHT_BUTTON);
GPIO APIfunctionreadspins0 and4 from portF and storesstate in volatile memory.
if(raw_button_states_index >= NUM_DEBOUNCE_CHECKS-1)
raw_button_states_index = 0;
If the functionreads alarger index thanthe (debouncer - 1) checksfor, itstarts from0 again.
else
raw_button_states_index ++;
else the functionreadsasmallerindex andincrements.
for(i=0; i<NUM_DEBOUNCE_CHECKS; i++)
states = states & raw_button_states[i];
A forloop compares raw buttonstate values andcurrent switchbutton values.
button_states = states;
Updatesthe leftand rightswitchbuttonstates.
Problem 6
cur_button_states = button_states;
if(saved_button_states != cur_button_states){
if((~saved_button_states & LEFT_BUTTON) && (cur_button_states & LEFT_BUTTON))
{
UARTprintf("Left button pushed down.n> ");
GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3, 2);
}
}
if((saved_button_states & LEFT_BUTTON) && (~cur_button_states &
LEFT_BUTTON))
{
UARTprintf("Left button released.n> ");
}
if((~saved_button_states & RIGHT_BUTTON) && (cur_button_states &
RIGHT_BUTTON))
{
UARTprintf("Right button pushed down.n> ");
}
if((saved_button_states & RIGHT_BUTTON) && (~cur_button_states &
RIGHT_BUTTON))
{
UARTprintf("Right button released.n> ");
GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3, 4);
}
if(cur_button_states == (LEFT_BUTTON | RIGHT_BUTTON))
{
UARTprintf("Both buttons held down.n> ");
GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3, 8);
}
saved_button_states = cur_button_states;
}
// Timer0 interrupt service routine
void Timer0_ISR(void)
{
// Clear the timer interrupt.
TimerIntClear(TIMER0_BASE, TIMER_TIMA_TIMEOUT);
// Blink blue LED.
// Read the current state of GPIO pins and write back the opposite state.
if(GPIOPinRead(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, 0);
Summary and Conclusions
The Tiva C SeriesTM4C123G microcontrollerhasattainedbetterprecision,durability,power
management,andinterrupt control.32-bitarchitecture andunaligneddataaccessdeliversafast
processingenvironment.These improvementssetanew tone formicro processingandcreative
environments.
References
TexasInstruments.(2014). TivaWarePeripheral Driver Library: User'sGuide. Austin,Texas:TI.

More Related Content

What's hot

Galvin-operating System(Ch4)
Galvin-operating System(Ch4)Galvin-operating System(Ch4)
Galvin-operating System(Ch4)dsuyal1
 
AirSensEUR: AirQuality monitoring open framework technical presentation
AirSensEUR: AirQuality monitoring open framework technical presentationAirSensEUR: AirQuality monitoring open framework technical presentation
AirSensEUR: AirQuality monitoring open framework technical presentationMarco Signorini
 
Klessydra t - designing vector coprocessors for multi-threaded edge-computing...
Klessydra t - designing vector coprocessors for multi-threaded edge-computing...Klessydra t - designing vector coprocessors for multi-threaded edge-computing...
Klessydra t - designing vector coprocessors for multi-threaded edge-computing...RISC-V International
 
RISC-V 30907 summit 2020 joint picocom_mentor
RISC-V 30907 summit 2020 joint picocom_mentorRISC-V 30907 summit 2020 joint picocom_mentor
RISC-V 30907 summit 2020 joint picocom_mentorRISC-V International
 
Online test program generator for RISC-V processors
Online test program generator for RISC-V processorsOnline test program generator for RISC-V processors
Online test program generator for RISC-V processorsRISC-V International
 
[ZigBee 嵌入式系統] ZigBee 應用實作 - 使用 TI Z-Stack Firmware
[ZigBee 嵌入式系統] ZigBee 應用實作 - 使用 TI Z-Stack Firmware[ZigBee 嵌入式系統] ZigBee 應用實作 - 使用 TI Z-Stack Firmware
[ZigBee 嵌入式系統] ZigBee 應用實作 - 使用 TI Z-Stack FirmwareSimen Li
 
VHDL Practical Exam Guide
VHDL Practical Exam GuideVHDL Practical Exam Guide
VHDL Practical Exam GuideEslam Mohammed
 
LinuxCNC for Fun & Profit
LinuxCNC for Fun & ProfitLinuxCNC for Fun & Profit
LinuxCNC for Fun & ProfitAlastairDSilva
 
Modules and ports in Verilog HDL
Modules and ports in Verilog HDLModules and ports in Verilog HDL
Modules and ports in Verilog HDLanand hd
 
IEEE 1149.1-2013 Addresses Challenges in Test Re-Use from IP to IC to Systems
IEEE 1149.1-2013 Addresses Challenges in Test Re-Use from IP to IC to SystemsIEEE 1149.1-2013 Addresses Challenges in Test Re-Use from IP to IC to Systems
IEEE 1149.1-2013 Addresses Challenges in Test Re-Use from IP to IC to SystemsIEEE Computer Society Computing Now
 
Design and Implementation of 64 Bit RISC Processor Using System.pdf
Design and Implementation of 64 Bit RISC Processor Using System.pdfDesign and Implementation of 64 Bit RISC Processor Using System.pdf
Design and Implementation of 64 Bit RISC Processor Using System.pdfChowdappaKv1
 
32 bit ALU Chip Design using IBM 130nm process technology
32 bit ALU Chip Design using IBM 130nm process technology32 bit ALU Chip Design using IBM 130nm process technology
32 bit ALU Chip Design using IBM 130nm process technologyBharat Biyani
 
Standard cells library design
Standard cells library designStandard cells library design
Standard cells library designBharat Biyani
 
[嵌入式系統] MCS-51 實驗 - 使用 IAR (2)
[嵌入式系統] MCS-51 實驗 - 使用 IAR (2)[嵌入式系統] MCS-51 實驗 - 使用 IAR (2)
[嵌入式系統] MCS-51 實驗 - 使用 IAR (2)Simen Li
 

What's hot (20)

Galvin-operating System(Ch4)
Galvin-operating System(Ch4)Galvin-operating System(Ch4)
Galvin-operating System(Ch4)
 
AirSensEUR: AirQuality monitoring open framework technical presentation
AirSensEUR: AirQuality monitoring open framework technical presentationAirSensEUR: AirQuality monitoring open framework technical presentation
AirSensEUR: AirQuality monitoring open framework technical presentation
 
Klessydra t - designing vector coprocessors for multi-threaded edge-computing...
Klessydra t - designing vector coprocessors for multi-threaded edge-computing...Klessydra t - designing vector coprocessors for multi-threaded edge-computing...
Klessydra t - designing vector coprocessors for multi-threaded edge-computing...
 
RISC-V 30907 summit 2020 joint picocom_mentor
RISC-V 30907 summit 2020 joint picocom_mentorRISC-V 30907 summit 2020 joint picocom_mentor
RISC-V 30907 summit 2020 joint picocom_mentor
 
Online test program generator for RISC-V processors
Online test program generator for RISC-V processorsOnline test program generator for RISC-V processors
Online test program generator for RISC-V processors
 
[ZigBee 嵌入式系統] ZigBee 應用實作 - 使用 TI Z-Stack Firmware
[ZigBee 嵌入式系統] ZigBee 應用實作 - 使用 TI Z-Stack Firmware[ZigBee 嵌入式系統] ZigBee 應用實作 - 使用 TI Z-Stack Firmware
[ZigBee 嵌入式系統] ZigBee 應用實作 - 使用 TI Z-Stack Firmware
 
VHDL Practical Exam Guide
VHDL Practical Exam GuideVHDL Practical Exam Guide
VHDL Practical Exam Guide
 
LinuxCNC for Fun & Profit
LinuxCNC for Fun & ProfitLinuxCNC for Fun & Profit
LinuxCNC for Fun & Profit
 
Modules and ports in Verilog HDL
Modules and ports in Verilog HDLModules and ports in Verilog HDL
Modules and ports in Verilog HDL
 
IEEE 1149.1-2013 Addresses Challenges in Test Re-Use from IP to IC to Systems
IEEE 1149.1-2013 Addresses Challenges in Test Re-Use from IP to IC to SystemsIEEE 1149.1-2013 Addresses Challenges in Test Re-Use from IP to IC to Systems
IEEE 1149.1-2013 Addresses Challenges in Test Re-Use from IP to IC to Systems
 
Verilog HDL
Verilog HDLVerilog HDL
Verilog HDL
 
Design and Implementation of 64 Bit RISC Processor Using System.pdf
Design and Implementation of 64 Bit RISC Processor Using System.pdfDesign and Implementation of 64 Bit RISC Processor Using System.pdf
Design and Implementation of 64 Bit RISC Processor Using System.pdf
 
I04425457
I04425457I04425457
I04425457
 
32 bit ALU Chip Design using IBM 130nm process technology
32 bit ALU Chip Design using IBM 130nm process technology32 bit ALU Chip Design using IBM 130nm process technology
32 bit ALU Chip Design using IBM 130nm process technology
 
Standard cells library design
Standard cells library designStandard cells library design
Standard cells library design
 
VHDL CODES
VHDL CODES VHDL CODES
VHDL CODES
 
[嵌入式系統] MCS-51 實驗 - 使用 IAR (2)
[嵌入式系統] MCS-51 實驗 - 使用 IAR (2)[嵌入式系統] MCS-51 實驗 - 使用 IAR (2)
[嵌入式系統] MCS-51 實驗 - 使用 IAR (2)
 
Micro lec note2 (1)
Micro lec note2 (1)Micro lec note2 (1)
Micro lec note2 (1)
 
Micro lec note2
Micro lec note2Micro lec note2
Micro lec note2
 
[IJET-V1I3P17] Authors :Prof. U. R. More. S. R. Adhav
[IJET-V1I3P17] Authors :Prof. U. R. More. S. R. Adhav[IJET-V1I3P17] Authors :Prof. U. R. More. S. R. Adhav
[IJET-V1I3P17] Authors :Prof. U. R. More. S. R. Adhav
 

Similar to Lab 2_5

Unit 1
Unit 1Unit 1
Unit 1siddr
 
Italian deft 7 manual 290
Italian deft 7 manual 290Italian deft 7 manual 290
Italian deft 7 manual 290mstrom62
 
Introduction to freebsd_6_kernel_hacking
Introduction to freebsd_6_kernel_hackingIntroduction to freebsd_6_kernel_hacking
Introduction to freebsd_6_kernel_hackingSusant Sahani
 
Data structure week 1
Data structure week 1Data structure week 1
Data structure week 1karmuhtam
 
LOSS_C11- Programming Linux 20221006.pdf
LOSS_C11- Programming Linux 20221006.pdfLOSS_C11- Programming Linux 20221006.pdf
LOSS_C11- Programming Linux 20221006.pdfThninh2
 
Virtual platform
Virtual platformVirtual platform
Virtual platformsean chen
 
Unix system programming
Unix system programmingUnix system programming
Unix system programmingSyed Mustafa
 
Intermediate code optimization Unit-4.pdf
Intermediate code optimization Unit-4.pdfIntermediate code optimization Unit-4.pdf
Intermediate code optimization Unit-4.pdfHimanshu883663
 
Basics of c Nisarg Patel
Basics of c Nisarg PatelBasics of c Nisarg Patel
Basics of c Nisarg PatelTechNGyan
 
Unit 2
Unit 2Unit 2
Unit 2siddr
 
INTRODUCTION TO VHDL
INTRODUCTION    TO    VHDLINTRODUCTION    TO    VHDL
INTRODUCTION TO VHDLkarthikpunuru
 
Basic structure of c programming
Basic structure of c programmingBasic structure of c programming
Basic structure of c programmingTejaswiB4
 
Basic structure of c programming
Basic structure of c programmingBasic structure of c programming
Basic structure of c programmingTejaswiB4
 
Unit 5 quesn b ans5
Unit 5 quesn b ans5Unit 5 quesn b ans5
Unit 5 quesn b ans5Sowri Rajan
 

Similar to Lab 2_5 (20)

Unit 1
Unit 1Unit 1
Unit 1
 
11i Logs
11i Logs11i Logs
11i Logs
 
Italian deft 7 manual 290
Italian deft 7 manual 290Italian deft 7 manual 290
Italian deft 7 manual 290
 
08 -functions
08  -functions08  -functions
08 -functions
 
Readme
ReadmeReadme
Readme
 
Introduction to freebsd_6_kernel_hacking
Introduction to freebsd_6_kernel_hackingIntroduction to freebsd_6_kernel_hacking
Introduction to freebsd_6_kernel_hacking
 
Data structure week 1
Data structure week 1Data structure week 1
Data structure week 1
 
LOSS_C11- Programming Linux 20221006.pdf
LOSS_C11- Programming Linux 20221006.pdfLOSS_C11- Programming Linux 20221006.pdf
LOSS_C11- Programming Linux 20221006.pdf
 
Virtual platform
Virtual platformVirtual platform
Virtual platform
 
Unix system programming
Unix system programmingUnix system programming
Unix system programming
 
Intermediate code optimization Unit-4.pdf
Intermediate code optimization Unit-4.pdfIntermediate code optimization Unit-4.pdf
Intermediate code optimization Unit-4.pdf
 
Basics of c Nisarg Patel
Basics of c Nisarg PatelBasics of c Nisarg Patel
Basics of c Nisarg Patel
 
Mc7404 np final
Mc7404 np finalMc7404 np final
Mc7404 np final
 
Unit 2
Unit 2Unit 2
Unit 2
 
Unit 1
Unit  1Unit  1
Unit 1
 
INTRODUCTION TO VHDL
INTRODUCTION    TO    VHDLINTRODUCTION    TO    VHDL
INTRODUCTION TO VHDL
 
Basic structure of c programming
Basic structure of c programmingBasic structure of c programming
Basic structure of c programming
 
Basic structure of c programming
Basic structure of c programmingBasic structure of c programming
Basic structure of c programming
 
Embedded C.pptx
Embedded C.pptxEmbedded C.pptx
Embedded C.pptx
 
Unit 5 quesn b ans5
Unit 5 quesn b ans5Unit 5 quesn b ans5
Unit 5 quesn b ans5
 

Lab 2_5

  • 1. Lab 2_5 EENG 3910: Project V - Digital Signal Processing System Design 9/21/2015 Joseph Chandler University of North Texas College of Engineering Electrical Engineering
  • 2. Introduction Lab 2_5 continuesthe studyof the TivaTM C SeriesEK-TM4C123GXL and CCS software.Lab2_5 's aspects consistof systemcontrols,timing,uartanddifferentmodules. Results and Discussions Problem 5 #include <stdint.h> Thisline containsthe headerfile forvariabledefinitions.The headerfile isalreadydefinedinthe CCS software.Examplesof the valuesare bitsize,precision,andsignedorunsignedintegers. #include <stdbool.h> Thisline containsthe headerfile forBooleandefinitions.The headerfile isalreadydefinedinthe CCS software.The file definitionsare usedforoperations,comparingvariables,andprogramcontrol flow. #include "inc/tm4c123gh6pm.h" Thisline containsthe headerfile forthe TM4C123GH6PM microcontroller.The headerfile ispart- specificandcontainsmacrosand definitionstosimplifyprogrammingthe peripheral'sregistersand interruptcontrol.Thisiscontainedinthe incdirectory. The .c file forthe TM4C123GH6PM microcontrollerisincludedinthe projectfolderfordirectaccess. #include "inc/hw_memmap.h" Thisline containsthe headerfile forthe TivaCSeriesdevice memorymapdefinitions.The headerfile containsmanyof the same definitionsusedfordirectregisteraccess.The headerfilecontainsmacros and definitionstosimplifyprogrammingthe peripheral'sregistersandinterruptcontrol.Thisis containedinthe incdirectory.The definitionsare usedbydriverlibraries andare hiddenfromthe programmer. #include "inc/hw_types.h" Thisline containsthe headerfile forcommontypesandmacros.The headerfile containsmanyof the same definitionsusedfordirectregisteraccess.Thisiscontainedinthe incdirectory.The definitionsare usedbydriverlibrariesandare hiddenfromthe programmer.The valuesare a wide varietyof general use for itemssuchas arithmetic,clocktiming,file recognition,anddevicerecognition. #include "inc/hw_gpio.h" Thisline contains the headerfile forcommontypesandmacros.The headerfile containsmanyof the same definitionsusedfordirectregisteraccess.Thisiscontainedinthe incdirectory.The definitionsare
  • 3. usedbydriverlibrariesandare hiddenfromthe programmer.The valuesare a wide varietyof general use for itemssuchas arithmetic,clocktiming,file recognition,anddevicerecognition. #include "driverlib/sysctl.h" Thisline containsthe headerfile forthe SystemControl APIdefinitionsandmacros.The headerfile isin the directory"driverlib"of the CCSsoftware.The driversprovideguidedcontrol of the peripheralsand allowsforquickapplication.Enablingperipheralsisanexampleof thiscontrol. #include "driverlib/interrupt.h" Thisline containsthe headerfile forthe SystemControl APIdefinitionsandmacros.The headerfile isin the directory"driverlib"of the CCSsoftware.The driversprovideguidedcontrol of the peripheralsand allowsforquickapplication.Enablingperipheralsisanexampleof thiscontrol. #include "driverlib/gpio.h" Thisline containsthe headerfile forGPIOAPIdefinitionsandmacros.The headerfile isinthe directory "driverlib"of the CCSsoftware.The driverprovidesasetof functionstocontrol the inputand output module. #include "driverlib/timer.h" Thisline containsthe headerfile forTimerAPIdefinitionsandmacros.The headerfile isinthe directory "driverlib"of the CCSsoftware.The driversprovide quickcontrol of the peripheralsandallowsforquick application.The timerAPIprovidesasetof functionsforusingthe timermodule. #include "driverlib/pin_map.h" Thisline containsthe headerfile forpin_mapAPIdefinitionsandmacros.The headerfile isinthe directory"driverlib"of the CCSsoftware.The driversprovidequickcontrol of the peripheralsandallows for quickapplication.The pin_map APIprovidesamapof the peripheral topinconfiguration. #include "driverlib/uart.h" Thisline containsthe headerfile forUART(Universal AsynchronousReceiver/Transmitter) API definitionsandmacros.The headerfile isinthe directory"driverlib"of the CCSsoftware.The drivers provide quickcontrol of the peripheralsandallowsforquickapplication.The UARTAPIprovidesasetof functionsforusingthe TIVA UART module. #include "utils/uartstdio.h" Thisline containsthe header file forUART.The header file isinthe directory"utils"of the CCS software.The utilityprovidesquickcontrol of the peripheralsandallowsforquickapplication. The file containsprototypesforthe UART console functions.Onbuildingthe project,the .cfile hadtobe added manuallytolinkthe filestogether. #define RED_LED GPIO_PIN_1
  • 4. Createsa constantfor pin1 inthe GPIO APImodule thatdisplaysthe red LED. #define BLUE_LED GPIO_PIN_2 Createsa constantfor pin2 inthe GPIO APImodule thatdisplaysthe blue LED. #define GREEN_LED GPIO_PIN_3 Createsa constantfor pin3 inthe GPIO APImodule thatdisplaysthe greenLED. #define NUM_BUTTONS 2 Createsa constantusedfor the twoswitchbuttons. #define LEFT_BUTTON GPIO_PIN_4 Createsa constantfor pin4 inthe GPIO APImodule forleftswitchbutton. #define RIGHT_BUTTON GPIO_PIN_0 Createsa constantfor pin0 inthe GPIO APImodule rightswitchbutton. #define NUM_DEBOUNCE_CHECKS 10 It checksbefore aswitchis debounced. Createsaconstantusedfor50msec debounce time. #define TIMER0_FREQ 2 Createsa constantusedfor frequencyinthe TimerAPImacrowitha value of 2. #define TIMER1_FREQ 200 Createsa constantusedfor frequencyinthe Timer APImacrowitha value of 200. #define UART0_BAUDRATE 115200 Createsa constantusedfor baudrate inthe UART API macro witha of value 115200 bps. #define NUM_DISP_TEXT_LINE 4 Createsa constantfor the numberof linesof textdisplayinthe characterpointer"disp_text"witha value of 4. void init_LEDs(void); Thisline declaresthe functionprototype "init_LEDs".Declarationatthispointgivesthe actual functiona global scope.Anyotherfunction,header,or.c file containedinthissource file isgivenaccesstothe functionandaccessible bythe function. void init_timer(void);
  • 5. Thisline declaresthe functionprototype " init_timer".Declarationatthispointgivesthe actual function a global scope.Anyotherfunction,header,or.cfile containedinthissource fileisgivenaccesstothe functionandaccessible bythe function. void init_UART(void); Thisline declaresthe functionprototype " init_UART".Declarationatthispointgivesthe actual function a global scope.Anyotherfunction,header,or.cfile containedinthissource fileisgivenaccesstothe functionandaccessible bythe function. void init_buttons(void); Thisline declaresthe functionprototype " init_buttons".Declarationatthispointgivesthe actual functionaglobal scope.Anyotherfunction,header,or.cfile containedinthissource fileisgivenaccess to the functionandaccessible bythe function. void set_button_states(void); Thisline declaresthe functionprototype " set_button_states ".Declarationatthispointgivesthe actual functionaglobal scope.Anyotherfunction,header,or.cfile containedinthissource fileisgivenaccess to the functionandaccessible bythe function. void Timer0_ISR(void); Thisline declaresthe functionprototype " Timer0_ISR".Declarationat thispointgivesthe actual functionaglobal scope.Anyotherfunction,header,or.cfile containedinthissource fileisgivenaccess to the functionandaccessible bythe function. void Timer1_ISR(void); Thisline declaresthe functionprototype " Timer1_ISR".Declarationat thispointgivesthe actual functionaglobal scope.Anyotherfunction,header,or.cfile containedinthissource fileisgiven access to the functionandaccessible bythe function. extern void UARTStdioIntHandler(void); Thisline declaresafunctionprototype of type "extern".Thisinformsthe microprocessorthatitneedsto access a functionthatexistsoutsideof thissource file.The uartstdio.cfileisincludedinthe project folderfordirectaccess.The uartstdio.cfile hasadditional functionsforthe UARTconsole.Thisparticular functionhandlesinterruptsfromthe UART.The UART has a transmitandreceive bufferthatis usedfor data transfersbetweenthe microprocessorandthe puttyconsole. uint32_t sys_clock; Createsan unsigned32-bitglobal variable forthe systemclock. uint8_t cur_LED = RED_LED;
  • 6. Createsan unsigned8-bitglobal variable forthe systemclock. const char *disp_text[NUM_DISP_TEXT_LINE] = { "n", "UART and LED Demon", "H: help, R: red, G: green, B: blue.n", "> " }; Thisline createsa pointer fora systemmessage communicated tothe userviaputtyconsole. volatile uint8_t raw_button_states[NUM_DEBOUNCE_CHECKS]; Createsan unsigned8-bitglobal arrayfordebounce. volatile uint32_t raw_button_states_index=0; Createsan unsigned32-bitglobal variable forinitializing index pointerof state. volatile uint8_t button_states=0; Createsan unsigned8-bitglobal variable forinitializingdebounced state. int main(void){ The main processcallsandacts on variables,macros,definitions,andothersystemfunctions. uint32_t i; Createsan unsigned32-bitvariable forloops. unsigned char user_cmd; Createsan unsignedcharactervariable foruserinput. uint8_t saved_button_states=0, cur_button_states; SysCtlClockSet(SYSCTL_SYSDIV_5|SYSCTL_USE_PLL|SYSCTL_XTAL_16MHZ|SYSCTL_OSC_MAIN); SystemControl ClockSetsetsthe clockingof the device.Osc_Mainconfiguresthe oscillatorsource. XTAL_16MHZ usesa 16 MHZ crystal clock. USE_PLL is a phase lockedloopat400MHZ. SYSDIV_5 divides the clock bythe numberspecifiedgiving control of the frequency. sys_clock = SysCtlClockGet(); Thisline retrievesthe processorclockrate andassignsit toa variable. init_LEDs(); InitializesLEDconfigurationandenables by calling the function definition.
  • 7. init_buttons(); Initializesbuttonsconfigurationandenables by calling the function definition. init_UART(); InitializesUARTconfigurationandenables by calling the function definition. init_timer(); InitializesTimerconfigurationandenables by calling the function definition. IntMasterEnable(); ThisNVICAPIfunctionenablesinterruptsfromthe microprocessortointerruptcontroller. TimerEnable(TIMER0_BASE, TIMER_A); ThisTIMER API functionenablesoperationof the timer module. TimerEnable(TIMER1_BASE, TIMER_A); ThisTIMER API functionenablesoperationof the timer module. for(i=0; i<NUM_DISP_TEXT_LINE; i++) Thisline isa for loopto displayprogrammessage onconsole. UARTprintf(disp_text[i]); Thisfunctionprintsthe message onthe console. while(1) { The while loopprovidesacontinuousloopwhensetto"1". if(UARTRxBytesAvail()) If the UART has available userinput. user_cmd = UARTgetc(); Thisline retrievesthe userinputandstoresitina variable. else user_cmd = 0; Else,the usercommandvariable issetto 0. switch(user_cmd){
  • 8. Switchcase for the userinputdata. case 'r': Switchcase for red. case ' ': Switchcase for empty. case 'H': Switchcase for H. case 'h': Switchcase for h. for(i=0; i<NUM_DISP_TEXT_LINE; i++) Switchcase display forlines87-90 is a for looptodisplayconsole message touserviaputtyconsole. UARTprintf(disp_text[i]); Thisfunctionprintsthe message onthe puttyconsole. break; Switchcase break. case 'R': Switchcase for redled. case 'r': Switchcase for redled. cur_LED = RED_LED; Storesthe red ledincurrentledvariable. UARTprintf("n> "); Thisfunctionprintsa newline witha> on the console. break; Switchcase break. case 'B':
  • 9. Switchcase for blue led. case 'b': Switchcase for blue led. cur_LED = BLUE_LED; Storesthe blue ledincurrentledvariable. UARTprintf("n> "); Thisfunctionprintsa newline witha> on the console. break; Switchcase break. case 'G': Switchcase for greenled. case 'g': Switchcase for greenled. cur_LED = GREEN_LED; Storesthe greenledincurrentledvariable. UARTprintf("n> "); Thisfunctionprintsa newline witha> on the console. break; Switchcase break. // Check button states. cur_button_states = button_states; if(saved_button_states != cur_button_states){ if((~saved_button_states & LEFT_BUTTON) && (cur_button_states & LEFT_BUTTON)) { UARTprintf("Left button pushed down.n> "); } if((saved_button_states & LEFT_BUTTON) && (~cur_button_states & LEFT_BUTTON)) { UARTprintf("Left button released.n> "); } if((~saved_button_states & RIGHT_BUTTON) && (cur_button_states & RIGHT_BUTTON)) {
  • 10. UARTprintf("Right button pushed down.n> "); } if((saved_button_states & RIGHT_BUTTON) && (~cur_button_states & RIGHT_BUTTON)) { UARTprintf("Right button released.n> "); } if(cur_button_states == (LEFT_BUTTON | RIGHT_BUTTON)) { UARTprintf("Both buttons held down.n> "); } saved_button_states = cur_button_states; } *The programcomparesincomingdatato saveddata. Whenthe data is notthe same,a nestedIF statement ANDsall entriesof the array to configure the switchbuttonoutputdisplayonthe UART. void init_LEDs(void) User-definedfunctiondefinitionforinitializingLEDs.The functionreturnsavalue of 0. SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF); The SystemControl APIfunctionenablesthe GPIOportF peripheral. GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3); The GPIO APIfunction configurespins1,2, and3 of portF for use as GPIO outputs. void init_timer(void) User-definedfunctiondefinitionforinitializingTimer.The functionreturnsavalue of 0. SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER0); The SystemControl APIfunction enablesthe timer0peripheral. SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER1); The SystemControl APIfunctionenablesthe timer1peripheral. TimerConfigure(TIMER0_BASE, TIMER_CFG_PERIODIC); The TimerAPI functionconfiguresthe timerasa 32-bitfull-widthperiodictimer. TimerLoadSet(TIMER0_BASE, TIMER_A, sys_clock/TIMER0_FREQ -1); The TimerAPI functionspecifiesthe base addressforconfiguration,the correctname fora full-width timer,andthe load value specifiedbyuser-definedconstants. TimerConfigure(TIMER1_BASE, TIMER_CFG_PERIODIC);
  • 11. The TimerAPI functionconfiguresthe timerasa 32-bitfull-widthperiodictimer. TimerLoadSet(TIMER1_BASE, TIMER_A, sys_clock/TIMER0_FREQ -1); The TimerAPI functionspecifiesthe base addressforconfiguration,the correctname fora full-width timer,andthe load value specifiedbyuser-definedconstants. IntRegister(INT_TIMER0A, Timer0_ISR); The NVICAPIfunctionregistersthe "TIMER0_ISR"functiontobe calledwhenthe "TIMER0A"interruptis enabled. IntEnable(INT_TIMER0A); The NVICAPIfunctionenables"TIMER0A"asa full-widthtimer tobe usedforthe interruptfunction process. TimerIntEnable(TIMER0_BASE, TIMER_TIMA_TIMEOUT); The TimerAPI functionenablesthe specifictimermodule(TIMER0_Base) forthe timer interruptsource. The bit maskof the interruptsource tobe enabledis"TIMER_TIMA_TIMEOUT". IntRegister(INT_TIMER1A, Timer1_ISR); The NVICAPIfunctionregistersthe "TIMER1_ISR"functiontobe calledwhenthe "TIMER0A"interruptis enabled. IntEnable(INT_TIMER1A); The NVICAPIfunctionenables"TIMER1A"asa full-widthtimer tobe usedforthe interruptfunction process. TimerIntEnable(TIMER1_BASE, TIMER_TIMA_TIMEOUT); The TimerAPI functionenablesthe specifictimermodule(TIMER1_Base) forthe timerinterruptsource. The bit maskof the interruptsource tobe enabledis"TIMER_TIMA_TIMEOUT". void init_UART(void) User-definedfunctiondefinitionforinitializingUART.The functionreturnsavalue of 0. SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0); The SystemControl APIfunctionenablesthe UART0 peripheral. SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA); The SystemControl APIfunctionenablesthe GPIOA peripheral.
  • 12. GPIOPinConfigure(GPIO_PA0_U0RX); The GPIO APIfunctionconfiguresthe alternate functionof aGPIO pin.GPIOPort A's pinmux is configuredforthe UART peripheral.Pin0is configuredforthe UARTreceiverbuffer. GPIOPinConfigure(GPIO_PA1_U0TX); The GPIO APIfunctionconfiguresthe alternate functionof aGPIO pin.GPIOPort A's pinmux is configuredforthe UART0 peripheral.Pin1isconfiguredforthe UART transmitterbuffer. GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1); The GPIO APIfunctionconfigurespinsforuse bythe UART peripheral.GPIOPort A will be the peripheral usedforUART communication.Pins0and1 of port A are available. IntRegister(INT_UART0, UARTStdioIntHandler); The NVICAPIfunctionregistersthe "UARTStdioIntHandler"functiontobe calledwhenthe "UART0" interruptisenabled. UARTStdioConfig(0, UART0_BAUDRATE, sys_clock); The UART driverfunctionconfiguresthe UARTforinput/output.UARTPort0 isthe base that will be used.The user-definedconstant"UART0_BAUDRATE"isthe bitrate forthe UART and the user-defined constant "sys_clock"isthe frequencyusedforthe source clockof the UART module. void Timer0_ISR(void) User-definedfunctiondefinitionforinterrupthandler.The functionreturnsavalue of 0. TimerIntClear(TIMER0_BASE, TIMER_TIMA_TIMEOUT); The TimerAPI functionclearsthe timerinterruptsources.TIMER0 isthe base specifiedand "TIMER_TIMA_TIMEOUT" isthe bitmaskfor the interruptsource cleared. if(GPIOPinRead(GPIO_PORTF_BASE, GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3)) { If the GPIOAPIfunctionreadspins1,2, or 3 fromport F. GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3, 0); The GPIO APIfunctionwritesa0 to pins1,2, or 3. else { Else the GPIO APIfunction... GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3, cur_LED); Writesthe value of the variable "cur_LED" to the correct pin.
  • 13. void Timer1_ISR(void) User-definedfunctiondefinitionforinterrupthandler.The functionreturnsavalue of 0. TimerIntClear(TIMER1_BASE, TIMER_TIMA_TIMEOUT); The TimerAPI functionclearsthe timerinterruptsources.TIMER1 isthe base specifiedand "TIMER_TIMA_TIMEOUT" isthe bitmaskfor the interruptsource cleared. set_button_states(); void init_buttons(void) User-definedfunctiondefinitionfor switchbuttons. uint32_t i Createsan unsigned32-bitlocal index variable. SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF); The SystemControl APIfunctionenablesthe GPIO peripheral portF. HWREG(GPIO_PORTF_BASE + GPIO_O_LOCK) = GPIO_LOCK_KEY; Unlock port F from NMI as GPIO input pin.
  • 14. HWREG(GPIO_PORTF_BASE + GPIO_O_CR) |= 0x01; Configure port F base to enable pins 0 and 4. HWREG(GPIO_PORTF_BASE + GPIO_O_LOCK) = 0; Relock port F for permanent configuration. GPIODirModeSet(GPIO_PORTF_BASE, LEFT_BUTTON|RIGHT_BUTTON, GPIO_DIR_MODE_IN); The GPIO APIfunctionconfigurespins0and4 of portF for use as GPIO inputs. GPIOPadConfigSet(GPIO_PORTF_BASE, LEFT_BUTTON|RIGHT_BUTTON, GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_STD_WPU); The GPIO APIfunctionconfigures pins0and4 of portF for weak pull-upbuttontype. for(i=0; i<NUM_DEBOUNCE_CHECKS; i++) raw_button_states[i] = 0; The for loopmaintainsbounce statusfromuserinterface. void set_button_states(void) User-definedfunctiondefinitionforbuttonstates. uint32_t i Createsan unsigned32-bitlocal index variable. uint8_t states = LEFT_BUTTON|RIGHT_BUTTON; Createsan unsigned8-bitlocal GPIOportF pinnumber variable. raw_button_states[raw_button_states_index] = ~ GPIOPinRead(GPIO_PORTF_BASE, LEFT_BUTTON|RIGHT_BUTTON); GPIO APIfunctionreadspins0 and4 from portF and storesstate in volatile memory. if(raw_button_states_index >= NUM_DEBOUNCE_CHECKS-1) raw_button_states_index = 0; If the functionreads alarger index thanthe (debouncer - 1) checksfor, itstarts from0 again. else raw_button_states_index ++; else the functionreadsasmallerindex andincrements. for(i=0; i<NUM_DEBOUNCE_CHECKS; i++) states = states & raw_button_states[i];
  • 15. A forloop compares raw buttonstate values andcurrent switchbutton values. button_states = states; Updatesthe leftand rightswitchbuttonstates. Problem 6 cur_button_states = button_states; if(saved_button_states != cur_button_states){ if((~saved_button_states & LEFT_BUTTON) && (cur_button_states & LEFT_BUTTON)) { UARTprintf("Left button pushed down.n> "); GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3, 2); } } if((saved_button_states & LEFT_BUTTON) && (~cur_button_states & LEFT_BUTTON)) { UARTprintf("Left button released.n> "); } if((~saved_button_states & RIGHT_BUTTON) && (cur_button_states & RIGHT_BUTTON)) { UARTprintf("Right button pushed down.n> "); } if((saved_button_states & RIGHT_BUTTON) && (~cur_button_states & RIGHT_BUTTON)) { UARTprintf("Right button released.n> "); GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3, 4); } if(cur_button_states == (LEFT_BUTTON | RIGHT_BUTTON)) { UARTprintf("Both buttons held down.n> "); GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3, 8); } saved_button_states = cur_button_states; } // Timer0 interrupt service routine void Timer0_ISR(void) { // Clear the timer interrupt. TimerIntClear(TIMER0_BASE, TIMER_TIMA_TIMEOUT); // Blink blue LED. // Read the current state of GPIO pins and write back the opposite state. if(GPIOPinRead(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, 0);
  • 16. Summary and Conclusions The Tiva C SeriesTM4C123G microcontrollerhasattainedbetterprecision,durability,power management,andinterrupt control.32-bitarchitecture andunaligneddataaccessdeliversafast processingenvironment.These improvementssetanew tone formicro processingandcreative environments. References TexasInstruments.(2014). TivaWarePeripheral Driver Library: User'sGuide. Austin,Texas:TI.