C32 main Module

Files:

Interface:

Function: main
Arguments: None.
Returns: None.
Description:Intializes Ports, SPI, AD. Runs in infinite loop to detect SPI communications and check battery level.

Function: InitPorts
Arguments: None.
Returns: None.
Description:Intializes Ports on the C32
Enable the shift register outputs
T0 = Shift Clock
T1 = Storage Clock
T2 = Serial Input

Function: InitSPI
Arguments: None.
Returns: None.
Description:Intializes SPI on C32.

Function: Checkbattery
Arguments: Character representing the timer number
Returns: Integer representing the battery level(0-1023).
Description:Reads the voltage across the resistor network on the AD pin.

Function: ClockLEDState
Arguments: Character array representing the bytes to shift in.
Returns: None.
Description:Clocks data in the LEDs array through the shift register. Enables digits to display on the 7-segment.

Function: DisplayState
Arguments: Character array representing the bytes to shift in.
Returns: None.
Description:Maps desired segment digit to the data to shift in the register and populates LED array. Calls ClockLEDState to display data.

Pseudo-Code:

 
void main(void)
   Intialize Ports, SPI, AD
   Forever
      Check Battery
      Check SPI flag via interrupt
    
  
void InitPorts(void)
   Enable the shift register outputs
      T0 = Shift Clock
      T1 = Storage Clock
      T2 = Serial Input
	  

void InitSPI(void)
   Set baud rate to /256
   Set phase to mode 3
   Make slave
   Enable interrupts
   Enable SPI 

    
int Checkbattery(void)
   Read AD level of the battery pin
  
void DisplayState(char)
   Segment-to-byte mapping
   Shift in 'dot' bit if desired digit is greater than 9
   Store shift bits for displaying the appropriate digits
   Output data to shift register
        
void ClockLEDState(char [])
   For each bit
      Put data on pin 2 
      Clock data
   Enable data on the storage register
   

Interrupts:

void interrupt _Vec_SPI HandleSPI(void) SPI interrupt response routine Check SPISR to see if data was received then write to SPIDR to clear Set SPI_Data_Received to YES