Vous êtes sur la page 1sur 3

EE712-Embedded System Design - Lab2

Parallel I/O and Basic Operations


Interface keys to parallel input pins for receiving operation code and operands. Interface LEDs
to parallel output pins. Program is a loop for reading the inputs and displaying the resulting
outputs.
For example, let there be 8 input pins X0, X1, .. X7 and 8 output pins Y0, Y1, .. Y7. Operation
code is given by X7 X6 and it is copied to Y7 Y6. Operand-1 is given by X3 X2 X1 and Operand-2
is given by X6 X5 X4. Output is displayed as Y6 Y5 Y4 Y3 Y2 Y1 Y0.
X7 X6 = 00. Copy. Y7 Y6 = X7 X6, Y5 Y4 Y3 = X5 X4 X3, Y2 Y1 Y0 = X2 X1 X0
X7 X6 = 01. Add. Y7 Y6 = X7 X6, Y5 Y4 Y3 Y2 Y1 Y0 = X2 X1 X0 + X5 X4 X3
X7 X6 = 10. Subtract. Y7 Y6 = X7 X6, Y5 Y4 Y3 Y2 Y1 Y0 = X2 X1 X0 - X5 X4 X3
X7 X6 = 11. Multiply. Y7 Y6 = X7 X6, Y5 Y4 Y3 Y2 Y1 Y0 = X2 X1 X0 x X5 X4 X3
Devise an appropriate observation table for verifying the operations.

Figure 1: Interface connectors on TM4C123 board


Pins to be used
X7X6X5X4X3X2X10 = PA7 PA6 PA5 PA4 PA3 PB5 PB4 PB3
Y7Y6Y5Y4Y3Y2Y1Y0 = PE4 PE3 PD2 PD1 PD0 PE2 PE1 PE0

NOTE
1. Include following header files in your main.c
#include "inc/hw_memmap.h" //Macros defining memory map of the device
#include "driverlib/sysctl.h" //Prototypes for the system control driver
#include "driverlib/gpio.h" //GPIO API
2. GPIOs on TM4C123 can be configured for 2mA, 4mA, 8mA drive strength. On reset,
GPIOs are default to 2mA drive strength. While interfacing LEDs, if the LED current is
more than 8mA then we cannot connect it directly to the microcontroller pin. It mat
damage the chip due to high current.
3. Use 7406 buffer to avoid accidental damage to microcontroller pins.

Figure 2: Use of 7406 buffer with TM4C123


4. 7406 requires Vcc = 5V which can be provided by VBUS pin on TM4C123.
Tips for using TivaWare API functions
You must have noticed in Exp.1 of blinking an LED that the hardware initialization is required
before accessing any pin on TM4C123. Observe hardware_init() function carefully. There are
following steps involved in hardware initialization:
1. Setting system CPU clock
SysCtlClockSet(SYSCTL_SYSDIV_5|SYSCTL_USE_PLL|SYSCTL_XTAL_16MHZ|SYSCTL_OSC_
MAIN);
2. Enable port to be used
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);
In this case, we are enabling Port A.

3. Set the pin type as input/output


GPIOPinTypeGPIOInput(GPIO_PORTB_BASE, GPIO_PIN_5|GPIO_PIN_4|GPIO_PIN_3);

There are some basic functions for reading a pin value and writing to a pin of TM4C123.
Following examples are included to help you understand these two function better:
1. int32_t GPIOPinRead(uint32_t ui32Port,uint8_t ui8Pins)
ui32Port is the base address of the GPIO port.
ui8Pins is the bit packet representation of the pin(s).
For example,
int32_t PinE7 = GPIOPinRead(GPIO_PORTA_BASE, GPIO_PIN_7);
Above statement reads pin 7 value of Port A and stores it in a variable PinE7.
Note that this function returns a bit-packed byte.
If Pin 7 is LOW then PinE7 = 0
If Pin 7 is HIGH then PinE7 = 128
2. void GPIOPinWrite(uint32_t ui32Port, uint8_t ui8Pins, uint8_t ui8Val)
Again, ui32Port is the base address of the GPIO port and ui8Pins is the bit packet
representation of the pin(s).
ui8Val is the value to write to the pin(s).
For example,
GPIOPinWrite(GPIO_PORTE_BASE, GPIO_PIN_4|GPIO_PIN_3, 24);
Above statement assigns HIGH value to Pin 3 and Pin 4 of Port E. (24)10=(00011000)2
For more information on API functions, Please refer TivaWare Peripheral Driver Library user
guide on lab webpage.
References
1. http://users.ece.utexas.edu/~valvano/Volume1/E-Book/C8_SwitchLED.htm
2. http://processors.wiki.ti.com/index.php/Introduction_to_the_TIRTOS_Kernel_Workshop

Vous aimerez peut-être aussi