Professional Documents
Culture Documents
Objective:
To become experimentally familiar with the basic layout of the TM4C123GH6PM microcontroller, and to
learn how to interface with LEDs and switches on different ports.
Simulation Procedure:
Run Mode Clock Gating Control Register 2 (RCGC2):
This register controls the clock gating logic in normal Run mode. Each bit controls a clock enable for a
given interface, function, or module. If set, the module receives a clock and functions. Otherwise, the
module is unclocked and disabled.
Bit/Field Description
0 Port A Clock Gating Control
1 Port B Clock Gating Control
2 Port C Clock Gating Control
3 Port D Clock Gating Control
4 Port E Clock Gating Control
5 Port F Clock Gating Control
A value of 1 in the specified bit enables the clock for the specified port.
A value of 0 in the specified bit disables the clock for the specified port.
The GPIOLOCK register enables write access to the GPIOCR register. Writing 0x4C4F.434B to the
GPIOLOCK register unlocks the GPIOCR register. The value of the GPIOCR register determines which bits
of the GPIOAFSEL, GPIOPUR, GPIOPDR, and GPIODEN registers are committed when a write to these
registers is performed. Writing any other value to the GPIOLOCK register re-enables the locked state.
Reading the GPIOLOCK register returns the lock status rather than the 32-bit value that was previously
written.
The GPIODIR register is the data direction register. Setting a bit in the GPIODIR register configures the
corresponding pin to be an output, while clearing a bit configures the corresponding pin to be an input.
All bits are cleared by a reset, meaning all GPIO pins are inputs by default.
Value Description
0 Corresponding pin is an input
1 Corresponding pin is an output
The GPIOAMSEL register controls isolation circuits to the analog side of a unified I/O pad. Because the
GPIOs may be driven by a 5-V source and affect analog operation, analog circuitry requires isolation
from the pins when they are not used in their analog function.
Value Description
0 The analog function of the pin is disabled, the isolation is enabled,
and the pin is capable of digital functions
1 The analog function of the pin is enabled, the isolation is disabled,
and the pin is capable of analog functions
GPIO_PORTD_AMSEL_R &= ~(0x09); // Disable analog functions on pins PD0 and PD3 of Port D
The GPIOAFSEL register is the mode control select register. If a bit is clear, the pin is used as a GPIO and
is controlled by the GPIO registers. Setting a bit in this register configures the corresponding GPIO line to
be controlled by an associated peripheral. Several possible peripheral functions are multiplexed on each
GPIO. The GPIO Port Control (GPIOPCTL) register is used to select one of the possible functions.
Value Description
0 The associated pin functions as a GPIO and is controlled by the GPIO
registers
1 The associated pin functions as a peripheral signal and is controlled
by the alternate hardware function
The GPIOPCTL register is used in conjunction with the GPIOAFSEL register and selects the specific
peripheral signal for each GPIO pin when using the alternate function mode.
Each of the four bits represent the Mux Control for the corresponding pin. When a bit is set in the
GPIOAFSEL register, the corresponding GPIO signal is controlled by an associated peripheral. The
GPIOPCTL register selects one out of a set of peripheral functions for each GPIO, providing additional
flexibility in signal definition.
Value Description
0 The digital functions for the corresponding pin are disabled
1 The digital functions for the corresponding pin are enabled
The GPIOPUR register is the pull-up control register. When a bit is set, a weak pull-up resistor on the
corresponding GPIO signal is enabled.
Value Description
0 The corresponding pin's weak pull-up resistor is disabled
1 The corresponding pin's weak pull-up resistor is enabled
GPIO_PORTF_PUR_R = 0x11; // Enable pull-up resistor for PF0 and PF4 (switches)
Exercise 1:
To toggle the onboard LED (R or B or G) on Port F and observe the resulting waveform in debug mode.
Code:
#include "tm4c123gh6pm.h"
#include <stdint.h>
Code:
#include "tm4c123gh6pm.h"
#include <stdint.h>
Outputs:
1 1 R (0x02)
0 1 G (0x08)
1 0 B (0x04)
0 0 W (0x0E)
Code:
#include "tm4c123gh6pm.h"
#include <stdint.h>
int main(void){
PortF_Init(); // make PF1 out (PF1 built-in LED)
while(1){
Switch=GPIO_PORTF_DATA_R&0x11;
if(Switch==0x11)
GPIO_PORTF_DATA_R = 0x02; // Both SW1 and SW2 are not toggled - Red
else if(Switch==0x01)
GPIO_PORTF_DATA_R = 0x08; // SW1 Toggled; SW2 not toggled
else if(Switch==0x10)
GPIO_PORTF_DATA_R = 0x04; // SW2 Toggled; SW1 not toggled
else if(Switch==0x00)
GPIO_PORTF_DATA_R = 0x0E; // Both SW1 and SW2 are toggled - White
else
GPIO_PORTF_DATA_R = 0x00;
Delay();
}
}
Outputs:
Condition 1: LED on PF1 glows when both SW1 and SW2 are not toggled
Condition 2: LED on PF3 glows when SW1 is toggled and SW2 is not toggled
Condition 3: LED on PF2 glows when SW1 is not toggled and SW2 is toggled
Condition 4: LEDs on PF1, PF2 and PF3 glow when both SW1 and SW2 are toggled
Exercise 4:
To control external LEDs on Port D using the onboard Switches SW1 and SW2 on Port D and observe the
resulting waveforms in debug mode.
1 1 NO (0x00)
0 1 Port D3 (0x08)
1 0 Port D0 (0x01)
Code:
#include "tm4c123gh6pm.h"
#include <stdint.h>
int main(void)
{
PortF_Init();
PortD_Init();
while(1)
{
Switch=GPIO_PORTF_DATA_R&0x11;
if(Switch==0x11)
GPIO_PORTD_DATA_R = 0x00;
else if (Switch==0x01)
GPIO_PORTD_DATA_R = 0x08;
else if (Switch==0x10)
GPIO_PORTD_DATA_R = 0x01;
else if (Switch==0x00)
GPIO_PORTD_DATA_R = 0x09;
else
GPIO_PORTD_DATA_R = 0x00;
}
}
Outputs:
Condition 1: No LED glows when both SW1 and SW2 are not toggled
Condition 2: LED on PD3 glows when SW1 is toggled and SW2 is not toggled
Condition 3: LED on PD0 glows when SW1 is not toggled and SW2 is toggled
Condition 4: Both LEDs on PD0 and PD3 glow when both SW1 and SW2 are toggled
Conclusion:
In this experiment, we have learnt about the basic layout of the TM4C123GH6PM microcontroller, the
uses of various GPIO resistors to perform basic operations, and how to interface with switches and LEDs
on different ports.