Local Energia Libraries


Ports provides support for accessing entire digital ports with single operations. This allows you to read and write multi-bit patterns in one step.

portMode(port, mode)

Puts the port, which can be one of PORTA, PORTB, PORTC, PORTD, PORTE, or PORTF, into the mode. The modes are the same as for pinMode, INPUT, OUTPUT, INPUT_PULLUP, and INPUT_PULLDOWN.

You can freely mix calls to portMode and pinMode to put the pins of a single port into any mixture of supported modes.

portWrite(port, value)

Writes the 8-bit value to the port in a single operation. This will only affect those pins that are configured to be outputs.

uint8_t portRead(port)

Returns the values of all the pins of the port packed into an 8-bit unsigned integer. As usual, bit 0 contains the value from pin 0, bit 1 from pin 1, and so on.

The values read will be those sensed by any pins that are configured to be inputs and will simply be the values written to any bits that are configured as outputs.


This library supports variable rate pulse-width modulation on those pins that support it. On the TM4C123G PWM is supported by almost all pins. The exceptions are PA0-PA5 and PE0-PE3. There are some variations in support. In particular, ports C and D are better at handling long PWM periods and high resolutions.

A PWM signal is defined by three parameters, the period (or frequency) of the signal, the resolution of the signal, and the duty cycle. The signal repeats after each period which is divided up into resolution time intervals. The output is high for duty intervals and low for resolution-duty intervals. The time interval is some multiple of 12.5nS chosen to give the correct period.

PWMConfig(pin, frequency, resolution, duty)

Puts the pin into PWM mode if it is supported on that pin. Sets the frequency (given in Hz), resolution, and initial duty cycle of the signal, and turns the PWM on. It is fine to call this repeatedly for a single pin though you need to not call it more than once per PWM period.


Enables pulse output on a pin configured for PWM. Leaves frequency, resolution, and duty cycle unaltered.


Disables pulse output on a pin configured for PWM. Leaves frequency, resolution, and duty cycle unaltered.

PWMSetDuty(pin, duty)

Changes the duty cycle of the PWM signal on pin. Leaves frequency, duty cycle, and on/off state unaltered. You can call this any time you want though changes will not take effect until the next PWM cycle.

PWMSetTime(pin, duty)

A deprecated synonym for PWMSetDuty. I changed the name because I thought SetDuty made more sense.


Physics 245