Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //*****************************************************************************
- // UART 1
- //*****************************************************************************
- #include <stdbool.h>
- #include <stdint.h>
- #include "inc/hw_memmap.h"
- #include "driverlib/gpio.h"
- #include "driverlib/pin_map.h"
- #include "driverlib/sysctl.h"
- #include "driverlib/uart.h"
- #include <math.h>
- #define GPIO_PINS_ALL GPIO_PIN_0|GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3|GPIO_PIN_4|GPIO_PIN_5|GPIO_PIN_6|GPIO_PIN_7
- //*****************************************************************************
- // Configure the UART and perform reads and writes using polled I/O.
- //*****************************************************************************
- int
- main(void)
- {
- char cThisChar;
- int p;
- int i=0;
- int j=0;
- // Set the clocking to run directly from the external crystal/oscillator.
- // TODO: The SYSCTL_XTAL_ value must be changed to match the value of the
- // crystal on your board.
- SysCtlClockSet (SYSCTL_SYSDIV_1 | SYSCTL_USE_OSC | SYSCTL_OSC_MAIN | SYSCTL_XTAL_8MHZ);
- // Enable the peripherals used by this example.
- // The UART itself needs to be enabled, as well as the GPIO port
- // containing the pins that will be used.
- SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0);
- SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);
- SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOC);
- GPIOPinTypeGPIOOutput(GPIO_PORTB_BASE, GPIO_PINS_ALL);
- GPIOPinTypeGPIOOutput(GPIO_PORTC_BASE, GPIO_PINS_ALL);
- // Configure the GPIO pin muxing for the UART function.
- // This is only necessary if your part supports GPIO pin function muxing.
- // Study the data sheet to see which functions are allocated per pin.
- // TODO: change this to select the port/pin you are using
- //
- GPIOPinConfigure(GPIO_PA0_U0RX);
- GPIOPinConfigure(GPIO_PA1_U0TX);
- // Since GPIO A0 and A1 are used for the UART function, they must be
- // configured for use as a peripheral function (instead of GPIO).
- // TODO: change this to match the port/pin you are using
- GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1);
- // Configure the UART for 115,200, 8-N-1 operation.
- // This function uses SysCtlClockGet() to get the system clock
- // frequency. This could be also be a variable or hard coded value
- // instead of a function call.
- UARTConfigSetExpClk(UART0_BASE, SysCtlClockGet(), 115200,
- (UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE |
- UART_CONFIG_PAR_NONE));
- // Put a character to show start of example. This will display on the
- // terminal.
- UARTCharPut(UART0_BASE, '>');
- // Enter a loop to read characters from the UART, and write them back
- // (echo). When a line end is received, the loop terminates.
- //
- do
- {
- // Read a character using the blocking read function. This function
- // will not return until a character is available.
- cThisChar = UARTCharGet(UART0_BASE);
- // Write the same character using the blocking write function. This
- // function will not return until there was space in the FIFO and
- // the character is written.
- if( (cThisChar != '\n') && (cThisChar != '\r') ){
- if(cThisChar == "B")
- {
- cThisChar = UARTCharGet(UART0_BASE);
- for(i=0; i<=10; i++)
- {
- if(cThisChar == i)
- {
- cThisChar = UARTCharGet(UART0_BASE);
- if(cThisChar == "+") GPIOPinWrite(GPIO_PORTA_BASE, 0xFF, pow(2,i));
- else GPIOPinWrite(GPIO_PORTA_BASE, 0xFF, 0);
- }
- }
- }
- else if(cThisChar == "C")
- {
- cThisChar = UARTCharGet(UART0_BASE);
- for(j=0; j<=10; j++)
- {
- if(cThisChar == j)
- {
- cThisChar = UARTCharGet(UART0_BASE);
- if (cThisChar == "+") GPIOPinWrite(GPIO_PORTA_BASE, 0xFF, pow(2,j));
- else GPIOPinWrite(GPIO_PORTA_BASE, 0xFF, 0);
- }
- }
- }
- // echo to terminal
- UARTCharPut(UART0_BASE, cThisChar);
- }else{
- // send a new line
- //
- UARTCharPut(UART0_BASE, '\n');
- UARTCharPut(UART0_BASE, '\r');
- UARTCharPut(UART0_BASE, '>');
- }
- }
- while(1);
- return(0);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement