0% found this document useful (0 votes)
32 views1 page

Shift Register Code in C Implementation

This document contains function definitions for initializing and operating a shift register connected to a Tiva microcontroller. The SR_Init function initializes port B to output the shift register's serial input, shift clock, and register clock signals. The SR_GetCurrentRegister function returns the last value written to the shift register. The SR_Write function writes an 8-bit value to the shift register most significant bit first by masking and shifting the value onto the serial input pin while pulsing the shift and register clocks.

Uploaded by

api-340729449
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
32 views1 page

Shift Register Code in C Implementation

This document contains function definitions for initializing and operating a shift register connected to a Tiva microcontroller. The SR_Init function initializes port B to output the shift register's serial input, shift clock, and register clock signals. The SR_GetCurrentRegister function returns the last value written to the shift register. The SR_Write function writes an 8-bit value to the shift register most significant bit first by masking and shifting the value onto the serial input pin while pulsing the shift and register clocks.

Uploaded by

api-340729449
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

// Initialize the hardware running the shift register

// Tiva Port B Pins 0-2 will be set to output


// Pin 0 to Serial input, Pin 1 to Shift Clock, Pin 2 to Register clock
// Takes: nothing
// Returns: nothing
void SR_Init(void)
{
Initialize Port B
Enable clock on Port B
Set Port B Pins 0-2 to digital output
}
// Allow external programs to determine the last value written to the shift regi
ster
// Takes: nothing
// Returns uint8_t Last_Write: last value written to register
uint8_t SR_GetCurrentRegister(void)
{
Return value of last write to register
}
// Write an input value to the shift register as a binary number
// MSB of input will appear at Q7 of the shift register
// LSB of input will appear at Q0 of the shift register
// Takes: uint8_t NewValue: the value to be written to the shift register
// Returns: nothing
void SR_Write(uint8_t NewValue)
{
Update Last_Write
Create mask with only 7th bit HI
set the register clock low
compare the input against a mask and write the MSB to the register
Pulse the shift clock
shift mask to check next most significant bit
shift the register
}

You might also like