Skip to content

Instantly share code, notes, and snippets.

@detik19
Created February 12, 2019 22:52
Show Gist options
  • Save detik19/0508aad5e7159fc177e95146212c4afc to your computer and use it in GitHub Desktop.
Save detik19/0508aad5e7159fc177e95146212c4afc to your computer and use it in GitHub Desktop.
RGB Blink
/*
* main.c
*
* Created on: 13 Feb 2019
* Author: tedy.saputro
*/
#include <stdio.h>
#include <stdint.h>
#include <stdbool.h>
#include "inc/hw_types.h"
#include "inc/hw_memmap.h"
#include "driverlib/sysctl.h"
#include "driverlib/gpio.h"
/*
* Function Name: setup()
* Input: none
* Output: none
* Description: Set crystal frequency and enable GPIO Peripherals
* Example Call: setup();
*/
void setup(void)
{
SysCtlClockSet(SYSCTL_SYSDIV_4|SYSCTL_USE_PLL|SYSCTL_XTAL_16MHZ|SYSCTL_OSC_MAIN);
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);
}
/*
* Function Name: led_pin_config()
* Input: none
* Output: none
* Description: Set PORTF Pin 1, Pin 2, Pin 3 as output. On this pin Red, Blue and Green LEDs are connected.
* Example Call: led_pin_config();
*/
void led_pin_config(void)
{
GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3);
}
int main(void)
{
uint8_t ui8LED = 2;
setup();
led_pin_config();
while(1)
{
// Turn on the LED
GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3, ui8LED);
// Delay for a bit
SysCtlDelay(20000000);
// Cycle through Red, Green and Blue LEDs
if (ui8LED == 8)
{
ui8LED = 2;
}
else
{
ui8LED = ui8LED*2;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment