Professional Documents
Culture Documents
Module
SR_HillAndMotor.c
Description
This module acts as the low level interface to a write to the Shift Register
2 that controls output to the Flag motor, Mario motor, and Hill lights/
The flag motor and the mario motor are interfaced with the ControlSM. The Hill
lights are controlled by the ScoringSM
Notes
History
When Who What/Why
-------------- --- --------
10/18/18 19:55 pma First version
****************************************************************************/
//Defining all bits
#define ALL_BITS (0xff << 2)
#include "BITDEFS.H"
#include "SR_HillAndMotor.h"
// readability defines
//
********************************************************************************
*****************
//
********************************************************************************
******************************
//*********************************MODULE
DEFINES***********************************************
// an image of the last 8 bits written to the shift register
static uint8_t LocalRegisterImage = 0;
//**********************Module
Functions***********************************************
//SR_Write will not be a module function here, but a public function
/****************************************************************************
Function
SR_HillAndMotor_Init
Parameters
Nothing
Returns
Nothing
Description
A function to initialize the shift register. One of the state machine calls this
function to initialize SR2
The data and sclk lines start from low and the RCLK starts from high
Notes
Author
****************************************************************************/
// set up the ports by enabling the peripheral clock, waiting for the
// peripheral to be ready and setting the direction
HWREG(SYSCTL_RCGCGPIO) |= HillAndMotor_SR_DATA_PORT_HI; //Port enable for
DATA
HWREG(SYSCTL_RCGCGPIO) |= HillAndMotor_SR_SCLK_PORT_HI; //Port enable for
SCLK
HWREG(SYSCTL_RCGCGPIO) |= HillAndMotor_SR_RCLK_PORT_HI; //Port enable for
RCLK
//Not required -- Sample the button port pin and use it to initialize
LastButtonState
//LastPinState = HWREG(LEAF_GPIO_BASE + (GPIO_O_DATA + ALL_BITS)) &
LEAF_SENSOR_PIN_HI;
// start with the data & sclk lines low and the RCLK line high
HWREG(HillAndMotor_SR_DATA_GPIO_BASE + (GPIO_O_DATA + ALL_BITS)) &=
HillAndMotor_SR_DATA_PIN_LOW;
HWREG(HillAndMotor_SR_SCLK_GPIO_BASE + (GPIO_O_DATA + ALL_BITS)) &=
HillAndMotor_SR_SCLK_PIN_LOW;
HWREG(HillAndMotor_SR_RCLK_GPIO_BASE + (GPIO_O_DATA + ALL_BITS)) |=
HillAndMotor_SR_RCLK_PIN_HI;
Parameters
Returns
uint8_t
Description
This function gives the last provided value to the shift register
Notes
Author
****************************************************************************/
// Create your own function header comment
uint8_t SR_HillAndMotor_GetCurrentRegister(void)
{
return LocalRegisterImage;
}
/****************************************************************************
Function
SR_HillAndMotor_Write()
Parameters
uint8_t NewValue
Returns
Nothing
Description
Writes to the shift register
Notes
Author
****************************************************************************/
//pulsing SCLK
HWREG(HillAndMotor_SR_SCLK_GPIO_BASE + (GPIO_O_DATA + ALL_BITS)) |=
HillAndMotor_SR_SCLK_PIN_HI;
HWREG(HillAndMotor_SR_SCLK_GPIO_BASE + (GPIO_O_DATA + ALL_BITS)) &=
HillAndMotor_SR_SCLK_PIN_LOW;