Created
December 1, 2015 04:30
-
-
Save michaellin/9689afe4f1558b14bfde to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/***Helper module for writing to shift register connected to the LCD monitor***/ | |
// the common headers for C99 types | |
#include <stdio.h> | |
#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 "BITDEFS.H" | |
#include "termio.h" | |
// header for this module | |
#include "SR_for_LCD.h" | |
// A variable for the last 8 bits written to the shift register | |
static uint8_t ShiftRegisterImage; | |
// Define ALL_BITS offset variable | |
#define ALL_BITS (0xff<<2) | |
// Define index "i" | |
char i = 1; | |
/************************************************************** | |
Function: SR_Init_LCD | |
Takes: nothing | |
Returns: nothing | |
Purpose: initializes the Tiva pins that are used to control the shift register | |
/*************************************************************/ | |
void SR_Init_LCD(void){ | |
// Initialize port F | |
HWREG(SYSCTL_RCGCGPIO) |= SYSCTL_RCGCGPIO_R5 ; | |
while((HWREG(SYSCTL_PRGPIO) & SYSCTL_PRGPIO_R5) != SYSCTL_PRGPIO_R5); | |
// Initialize bit 0 | |
HWREG(GPIO_PORTF_BASE+GPIO_O_DEN) |= (GPIO_PIN_0); | |
HWREG(GPIO_PORTF_BASE+GPIO_O_DIR) |= (GPIO_PIN_0); | |
// Initialize bit 1 | |
HWREG(GPIO_PORTF_BASE+GPIO_O_DEN) |= (GPIO_PIN_1); | |
HWREG(GPIO_PORTF_BASE+GPIO_O_DIR) |= (GPIO_PIN_1); | |
// Initialize bit 2 | |
HWREG(GPIO_PORTF_BASE+GPIO_O_DEN) |= (GPIO_PIN_2); | |
HWREG(GPIO_PORTF_BASE+GPIO_O_DIR) |= (GPIO_PIN_2); | |
//Set Data Line Low | |
HWREG(GPIO_PORTF_BASE+(GPIO_O_DATA+ALL_BITS)) &= (BIT0LO); | |
//Set Shift Clock Low | |
HWREG(GPIO_PORTF_BASE+(GPIO_O_DATA+ALL_BITS)) &= (BIT1LO); | |
//Set Register Clock High | |
HWREG(GPIO_PORTF_BASE+(GPIO_O_DATA+ALL_BITS)) |= (BIT2HI); | |
} | |
/************************************************************** | |
Function: SR_Write_LCD | |
Takes: 8 bit integer | |
Returns: nothing | |
Purpose: writes input 8 bit integer to the 8 outputs (Q0-Q7) of the shift register | |
/*************************************************************/ | |
void SR_Write_LCD(uint8_t NewValue){ | |
ShiftRegisterImage = NewValue; | |
// Set STCP low | |
HWREG(GPIO_PORTF_BASE+(GPIO_O_DATA+ALL_BITS)) &= (BIT2LO); | |
// Shift data onto serial data line while pulsing shift clock | |
for(i=1;i<=8;i++){ | |
if ((NewValue & BIT0HI) == BIT0HI){ // This uses LSB shifting | |
HWREG(GPIO_PORTF_BASE+(GPIO_O_DATA+ALL_BITS)) |= (BIT0HI); | |
} | |
else { | |
HWREG(GPIO_PORTF_BASE+(GPIO_O_DATA+ALL_BITS)) &= (BIT0LO); | |
} | |
// Set SHCP hi | |
HWREG(GPIO_PORTF_BASE+(GPIO_O_DATA+ALL_BITS)) |= BIT1HI; | |
// Set SHCP low | |
HWREG(GPIO_PORTF_BASE+(GPIO_O_DATA+ALL_BITS)) &= BIT1LO; | |
// Shift NewValue right 1 bit | |
NewValue = NewValue>>1; | |
} | |
// Set STCP hi | |
HWREG(GPIO_PORTF_BASE+(GPIO_O_DATA+ALL_BITS)) |= BIT2HI; | |
} | |
/************************************************************** | |
Function: SR_GetCurrentRegister_LCD | |
Takes: nothing | |
Returns: 8 bit integer | |
Purpose: allows other modules to check the last integer that was written to the shift register | |
/*************************************************************/ | |
uint8_t SR_GetCurrentRegister_LCD(void){ | |
return ShiftRegisterImage; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment