Sie sind auf Seite 1von 2

/*

* LEDRegisterWrite.c
*
* This module is used to interface the LED shift register on PortB
*
* Author: Paul Westhoff ME218A FAll 2017
*/

// the common headers for C99 types


#include <stdint.h>
#include <stdbool.h>

// the headers to access the GPIO subsystem


#include "inc/hw_memmap.h"
#include "inc/hw_types.h"
#include "inc/hw_gpio.h"
#include "inc/hw_sysctl.h"

// the headers to access the TivaWare Library


#include "driverlib/sysctl.h"
#include "driverlib/pin_map.h"
#include "driverlib/gpio.h"
#include "driverlib/timer.h"
#include "driverlib/interrupt.h"

#include "termio.h"

#include "BITDEFS.H"
#include "ES_Port.h"

// readability defines
#define DATA BIT0HI //GPIO_PIN_0
#define DATA_HI BIT0HI
#define DATA_LO BIT0LO

#define SCLK BIT1HI //GPIO_PIN_1


#define SCLK_HI BIT1HI
#define SCLK_LO BIT1LO

#define RCLK BIT2HI //GPIO_PIN_2


#define RCLK_LO BIT2LO
#define RCLK_HI BIT2HI

#define GET_MSB_IN_LSB(x) ((x & 0x8000) >> 15)

// an image of the last 16 bits written to the shift register


static uint16_t LocalRegisterImage = 0;

// Get the current register being output


uint16_t LED_GetCurrentRegister(void)
{
return LocalRegisterImage;
}

// Outputs16 new bits


void LED_Write(uint16_t NewValue)
{
LocalRegisterImage = NewValue; // save a local copy

// Lower the register clock


HWREG(GPIO_PORTB_BASE + (GPIO_O_DATA + ALL_BITS)) &= RCLK_LO;

static uint8_t bitCount;


static uint8_t mostSigBit = 15;
static uint16_t output;

// Shift out the data while pulsing the shift clock


for (bitCount = 0; (bitCount <= mostSigBit); bitCount++)
{
// Test MSB of NewValue and output to Pin0
output = GET_MSB_IN_LSB(NewValue);

if (output)
{
HWREG(GPIO_PORTB_BASE + (GPIO_O_DATA + ALL_BITS)) |= DATA_HI;
}
else
{
HWREG(GPIO_PORTB_BASE + (GPIO_O_DATA + ALL_BITS)) &= DATA_LO;
}

// Pulse shift clock


HWREG(GPIO_PORTB_BASE + (GPIO_O_DATA + ALL_BITS)) |= SCLK_HI;
HWREG(GPIO_PORTB_BASE + (GPIO_O_DATA + ALL_BITS)) &= SCLK_LO;

// Shift NewValue left 1 bit


NewValue = NewValue << 1;
}

// Raise the register clock to latch the new data


HWREG(GPIO_PORTB_BASE + (GPIO_O_DATA + ALL_BITS)) |= RCLK_HI;
}

Das könnte Ihnen auch gefallen