C Code
#include <hidef.h> /* common defines and macros */
#include <mc9s12e128.h> /* derivative information */
#include <S12E128bits.h>
#include <stdio.h>
#include "XBee.h"
#include "helm_display.h"
// helm_display.c
/* runs:
- 7 segment display
- team indicator (2 LEDs)
- goal indicator (2 LEDs)
- Stand Down indicator (1 LED)
/*
/* also needs to have test code
to test the 7 segment
*/
/* #Defines for indicator LEDs */
#define AFFIL_RED_HI BIT0HI
#define AFFIL_RED_LO BIT0LO
#define AFFIL_BLUE_HI BIT1HI
#define AFFIL_BLUE_LO BIT1LO
#define STAND_DOWN_HI BIT2HI
#define STAND_DOWN_LO BIT2LO
#define BASE_RED_HI BIT3HI
#define BASE_RED_LO BIT3LO
#define BASE_BLUE_HI BIT4HI
#define BASE_BLUE_LO BIT4LO
#define PLAYING_GAME 21
#define ENGAGEMENT_OVER 22
#define STANDING_DOWN 23
// ----------------------------------------
// --- Code
// ----------------------------------------
void test_display(void)
{
static char key_press = 9;
InitDisplayPorts();
printf("testing the 7 segment display\r\n");
while(1)
{
printf("waiting for hit....\r");
if(kbhit())
{
key_press = getchar();
DisplayBoatNumber(key_press);
/*
} // end if
} //end while
} // end test_display
// ----------------------------------------
// --- Helpers
// ----------------------------------------
void InitDisplayPorts(void)
{
// 7 segment
DDRT = 0xFF; // port T is all outputs
PTT = 0x00; // clear them all to begin with
// LEDs
DDRU = 0xFF; // Set port U as outputs for the indicator LEDs
PTU = 0x00; // Clear all of port U (off) to begin
//PTU |= STAND_DOWN_HI; // Start game with Stand Down LED on to indicate waiting for iButton
}
/* to uppercase
if(key_press <= 'z' && key_press >= 'a')
key_press += 'A' - 'a';
*/
/**********************/
/* LED stuff */
/**********************/
void Set_Affiliation(char color)
{
switch( color)
{
case RED:
PTU |= AFFIL_RED_HI; // Turn on Red
PTU &= AFFIL_BLUE_LO; // Turn off Blue
break;
case BLUE:
PTU |= AFFIL_BLUE_HI; // Turn on Blue
PTU &= AFFIL_RED_LO; // Turn off Red
break;
case ALL_OFF:
PTU &= (AFFIL_BLUE_LO & AFFIL_RED_LO); // Turn off Blue and Red
break;
case ALL_ON:
PTU |= (AFFIL_RED_HI | AFFIL_BLUE_HI); // Turn on Red and Blue
break;
default:
printf("unhandled case in Set_Affiliation\r\n");
break;
}
return;
}
void Set_Base(char color)
{
switch( color)
{
case RED:
PTU |= BASE_RED_HI; // Turn on Red
PTU &= BASE_BLUE_LO; // Turn off Blue
break;
case BLUE:
PTU |= BASE_BLUE_HI; // Turn on Blue
PTU &= BASE_RED_LO; // Turn off Red
break;
case ALL_OFF:
PTU &= (BASE_BLUE_LO & BASE_RED_LO); // Turn off Blue and Red
break;
case ALL_ON:
PTU |= (BASE_RED_HI | BASE_BLUE_HI); // Turn on Red and Blue
break;
default:
printf("unhandled case in Set_Base\r\n");
break;
}
return;
}
void Set_Standdown_LED(char state)
{
switch(state)
{
case ALL_OFF:
PTU &= STAND_DOWN_LO; // Turn off Blue and Red
break;
case ALL_ON:
PTU |= STAND_DOWN_HI; // Turn on Red and Blue
break;
case PLAYING_GAME:
PTU |= STAND_DOWN_HI;
break;
default:
printf("unhandled case in Set_Standdown_LED\r\n");
break;
}
return;
}
// ----------------------------------------
// --- Display
// ----------------------------------------
void DisplayBoatNumber (char boat_number)
{
switch(boat_number)
{
case 0x00:
display_0();
printf("Boat 0\r\n");
break;
case 0x01:
display_1();
printf("Boat 1\r\n");
break;
case 0x02:
display_2();
printf("Boat 2\r\n");
break;
case 0x03:
display_3();
printf("Boat 3\r\n");
break;;
case 0x04:
display_4();
printf("Boat 4\r\n");
break;
case 0x05:
display_5();
printf("Boat 5\r\n");
break;
case 0x06:
display_6();
printf("Boat 6\r\n");
break;
case 0x07:
display_7();
printf("Boat 7\r\n");
break;
case 0x08:
display_8();
printf("Boat 8\r\n");
break;
case 0x09:
display_9();
printf("Boat 9\r\n");
break;
case 0x0A:
display_A();
printf("Boat A\r\n");
break;
case 0x0B:
display_B();
printf("Boat B\r\n");
break;
case 0x0C:
display_C();
printf("Boat C\r\n");
break;
case 0x0D:
display_D();
printf("Boat D\r\n");
break;
case 0x0E:
display_E();
printf("Boat E\r\n");
break;
case 0x0F:
display_F();
printf("Boat F\r\n");
break;
case 'p':
display_P();
printf("P \r\n");
break;
default:
PTT = 0xFF; // erase display
printf("can't display that\r\n");
break;
}
}
// number lookup:
void display_0 (void)
{
PTT = (bottom_center & bottom_left & bottom_right & top_left & top_center & top_right);
}
void display_1 (void)
{
PTT = (bottom_right & top_right);
}
void display_2 (void)
{
PTT = (top_center & top_right & middle & bottom_left & bottom_center);
}
void display_3 (void)
{
PTT = (top_center & middle & bottom_center & top_right & bottom_right);
}
void display_4 (void)
{
PTT = (top_left & middle & top_right & bottom_right);
}
void display_5 (void)
{
PTT = (top_center & top_left & middle & bottom_right & bottom_center);
}
void display_6 (void)
{
PTT = (top_center & top_left & bottom_left & middle & bottom_center & bottom_right);
}
void display_7 (void)
{
PTT = (top_center & top_right & bottom_right);
}
void display_8 (void)
{
PTT = (top_center & top_left & bottom_left & middle & bottom_center & bottom_right & top_right);
}
void display_9 (void)
{
PTT = ( top_left & top_center & top_right & middle & bottom_right);
}
void display_A (void)
{
PTT = ( bottom_left & top_left & top_center & top_right & bottom_right & middle);
}
void display_B (void)
{
PTT = ( top_left & bottom_left & bottom_center & bottom_right & middle);
}
void display_C (void)
{
PTT = ( top_center & top_left & bottom_left & bottom_center);
}
void display_D (void)
{
PTT = (top_right & bottom_right & bottom_center & bottom_left & middle);
}
void display_E (void)
{
PTT = (top_left & bottom_left & top_center & middle & bottom_center);
}
void display_F (void)
{
PTT = (top_center & top_left & middle & bottom_left);
}
void display_P (void)
{
PTT = (top_center & top_left & middle & bottom_left&top_right);
}