Description

The seven-segment display module initializes the synchronous serial communications subsystem to talk to the two shift registers that power the seven-segment displays. The main writing function takes a number to write and which display to write to (MORALE, TOWRP, or BOTH.) It then uses the serial port to write that number out to the commanded display(s). Most of the complications, such as making sure that writing to one shift register does not blank the other display, are handled in hardware, keeping this module relatively simple. The bit patterns to display all possible hexadecimal characters are provided as pre-processor defines, so the user need only pass in the provided define to get the desired number displayed (an additional function for converting between numbers and the provided defines is provided to automate this process.)

Pseudo-Code

initSeg7:
    Set this processor to be the master
    Based on how we drew the schematic, things will be easier with LSB first
    Set the baud rate to the slowest possible
    The shift register samples lo-hi, so mode 3 is the one for us
    Since we have two slaves, we need to manually control the SS line
    We'll also use bidirectional mode to save a pin (and since we can)
    We therefore need to set the data directions of the unused pins to be outputs
    Enable the SPI system
    Send a first message so that the flag gets set (clear both displays)
dispNum:
    If the previous transmission has completed
        If we are supposed to send to the TOWRP Display only
            Lower the MORALE slave select line
            Raise the TOWRP slave select line
            Put the number in the data register
            Return SUCC_DISP
        Else if we are supposed to send to the MORALE Display only
            Lower the TOWRP slave select line
            Raise the MORALE slave select line
            Put the number in the data register
            Return SUCC_DISP
        Else if we are supposed to send to both displays
            Raise the TOWRP slave select line
            Raise the MORALE slave select line
            Put the number in the data register
            Return SUCC_DISP
        Else (invalid display parameter), return FAIL_DISP
    Else return FAIL_DISP
convNum:
    Given an integer between -15 and 15, return the corresponding bit-code for dispNum