Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*********************************************************************************
- * ECE 362 - Mini-Project C Source File - Fall 2012
- **********************************************************************************
- **********************************************************************************
- *
- * Team ID: 16
- *
- * Project Name: < chess >
- *
- * Team Members:
- * Name: Mark Luzarowski Signature:________________________________
- * Mail: [email protected]
- * Name: Micheal Standiford Signature:________________________________
- * Mail: [email protected]
- * Name: Mark Sears Signature:________________________________
- * Mail: [email protected]
- * Name: That other guy Signature:________________________________
- * Mail: [email protected]
- *
- * Team Positions:
- *
- * Team/Doc Leader: < Mark Luzarowski > Signature: ______________________
- *
- * Software Leader: < Mark Luzarowski > Signature: ______________________
- *
- * Interface Leader: < Micheal Standiford > Signature: ______________________
- *
- * Peripheral Leader: < Micheal Standiford > Signature: ______________________
- *
- *
- * Academic Honesty Statement: In signing above, we hereby certify that we
- * are the individuals who created this HC(S)12 source file and that we have
- * not copied the work of any other student (past or present) while completing
- * it. We understand that if we fail to honor this agreement, we will receive
- * a grade of ZERO and be subject to possible disciplinary action.
- *
- **********************************************************************************
- * Project Purpose
- **********************************************************************************
- * The objective of this Mini-Project is to create a game board the can as a multi-
- * game base; games planned so far are chess and checkers. The board itself will
- * function as a "learning board" of sorts for any game programmed into it.
- *
- **********************************************************************************
- * Project-specific Success Criteria
- **********************************************************************************
- * 1. Piece tracking & movement analysis
- *
- * 2. Time & turn tracking
- *
- * 3. User-side game editing
- *
- **********************************************************************************
- * Change Log
- **********************************************************************************
- * Date code started: November 13, 2012
- *
- * Update history:
- *
- * Date: November 13, 2012
- * Name: Mark Luzarowski
- * Update: Added generalized functions for LCD communications.
- * Added initializations skeleton.
- * -------------------------------------------------------------------------------
- * Date:
- * Name:
- * Update:
- *
- ***********************************************************************************
- **********************************************************************************/
- #include <hidef.h> // common defines and macros
- #include "derivative.h" // derivative-specific definitions
- #include <mc9s12c32.h> // 9S12 register & port defines
- //Dictionary defines
- #define LCD_RS PTT_PTT2 //NOT FINAL
- #define LCD_CLK PTT_PTT4 //NOT FINAL
- #define RPG_A PTT_PTT5
- #define RPG_B PTT_PTT6
- #define shiny_button PTT_PTT7
- //Debug defines
- #define TOP_BTN PTAD_PTAD7 //top pushbutton
- #define BTM_BTN PTAD_PTAD6 //bottom pushbutton
- //#define SEL_BTN PTAD_PTAD5
- // All funtions after main should be initialiezed here
- char inchar(void);
- void outchar(char);
- void LCD_Delay(int);
- void LCD_Cursor_Position(int);
- void LCD_Send_Byte(char, int);
- void LCD_Display(int);
- void bco(char);
- void LCD_Timer(void);
- void LED_Out(void);
- void LED_Convert(void);
- void Chess_Locations(int);
- //debug
- int new_TOP_BTN = 0;
- int new_BTM_BTN = 0;
- int scroller = 0;
- int bcnt = 0;
- int rightcount = 0;
- int leftcount = 0;
- int rightturn = 0; //set true if one tick of right turn detected
- int leftturn = 0; //set true if one tick of left turn detected
- /*int new_RPGA = 0;
- int new_RPGB = 0;
- int old_RPGA = 0;
- int old_RPGB = 0;
- */
- int new_shiny_button = 0;
- int prev_shiny_button = 0;
- //Global variable declarations
- int tin = 0; // SCI transmit display buffer IN pointer
- int tout = 0; // SCI transmit display buffer OUT pointer
- int tsize = 10; // size of transmit buffer
- char tbuf[10]; // SCI transmit display buffer
- char LineOffset = 0x00;
- int P1mins = 20;
- int P1secs = 0;
- int P2mins = 20;
- int P2secs = 0;
- int PlayerToggle = 0;
- int timerup = 0;
- int timeExpired = 0;
- int HallMatrix[8][8];
- int ChessMatrix[8][8];
- unsigned char LEDOutData[8];
- int en1 = 0;
- int en2 = 0;
- //ASCII character constants
- char ASCII_CR = 0x0D; //Return
- char ASCII_LF = 0x0A; //Lifefeed
- //LCD specific constants
- char LCD_LINE1 = 0x80; //LCD line #1
- char LCD_LINE2 = 0xC0; //LCD line #2
- char LCD_ON = 0x0F; //LCD turn on instruction
- char LCD_CLEAR = 0x01; //LCD clear instruction
- char LCD_2LINE = 0x38; //LCD use both lines instruction
- char LCD_CURSOR = 0xFE; //LCD cursor move instruction
- /***********************************************************************
- Initializations
- ***********************************************************************/
- void initializations(void) {
- // Set the PLL speed (bus clock = 24 MHz)
- CLKSEL = CLKSEL & 0x80; // disengage PLL from system
- PLLCTL = PLLCTL | 0x40; // turn on PLL
- SYNR = 0x02; // set PLL multiplier
- REFDV = 0; // set PLL divider
- while (!(CRGFLG & 0x08)){ }
- CLKSEL = CLKSEL | 0x80; // engage PLL
- // Disable watchdog timer (COPCTL register)
- COPCTL = 0x40; // COP off; RTI and COP stopped in BDM-mode
- // Initialize asynchronous serial port (SCI) for 9600 baud, no interrupts
- SCIBDH = 0x00; // set baud rate to 9600
- SCIBDL = 0x9C; // 24,000,000 / 16 / 156 = 9600 (approx) dec=26
- SCICR1 = 0x00; // $9C = 156
- SCICR2 = 0x0C; // initialize SCI for program-driven operation
- DDRB = 0x10; // set PB4 for output mode
- PORTB = 0x10; // assert DTR pin on COM port
- //RTI Initialization (2.048ms)
- CRGINT = CRGINT | 0x80; //RTI enabled
- RTICTL = 0x1F; //
- //SPI Initialization (6MHz)
- SPICR1 = 0x52; //SPI control register #1
- //[Bit 7] SPIE = 0 | SPI interrupts disabled
- //[Bit 6] SPE = 1 | SPI enabled
- //[Bit 5] SPTIE = 0 | SPI transmit empty interrupt disabled
- //[Bit 4] MSTR = 1 | Master mode
- //[Bit 3] CPOL = 0 | Active low clock (SCK) - idles low
- //[Bit 2] CPHA = 0 | Data sampled at odd edges of SCK
- //[Bit 1] SSOE = 1 | Slave select output enable
- //[Bit 0] LSBFE = 0 | Data transferred most significant bit first
- SPICR2 = 0x00;
- SPIBR = 0x01; //Baud rate register
- //[Bit 6-4] SPPRx = 000 | Baud rate pre-selection bits
- //[Bit 2-0] SPRx = 001 | Baud rate selection bits
- //SPI rate = BusClock / [(SPPR + 1) * 2^(SPR + 1)]
- //TIM Initialization (10ms)
- TSCR1_TEN = 1; //TIM enable
- TIOS_IOS7 = 1; //Output compare on ch7
- TSCR2_TCRE = 1; //TCNT reset when OC7 occurs
- TSCR2_PR2 = 1; //24MHz / 16 = 1.5MHz
- TSCR2_PR1 = 0;
- TSCR2_PR0 = 0;
- TC7 = 15000; //15000 / 1.5MHz = 10ms
- TIE_C7I = 0; //TIM interrupts disabled
- //PMW Initialization
- PWME = 0x01; //PMW enable
- PWMPOL = 0x01; //PWM polarity select (active high)
- PWMPER0 = 0xFF; //period
- PWMDTY0 = 0xFF; //duty
- PWMPRCLK = 0x04; //24MHz/4 = 6MHz
- PWMCLK = 0x01;
- PWMSCLA = 75;
- PWMSCLB = 0;
- MODRR = 0x01;
- PWMCAE = 0;
- //Port Initializations
- //ATDDIEN = 0xC0; //program PAD7 and PAD6 pins as digital inputs
- ATDDIEN = 0xE0;
- DDRT = 0x1F; // 00011111 T5, T6, T7 are inputs from the shiny button
- PTT = 0;
- //LCD Initializations
- LCD_CLK = 1;
- LCD_Send_Byte(LCD_ON, 1);
- LCD_Send_Byte(LCD_2LINE, 1);
- LCD_Send_Byte(LCD_CLEAR, 1);
- LCD_Delay(1);
- LCD_Display(0);
- }
- /***********************************************************************
- Main
- ***********************************************************************/
- void main(void) {
- DisableInterrupts;
- initializations();
- EnableInterrupts;
- for(;;) {
- //debug btn code
- if ((BTM_BTN == 1) && (new_BTM_BTN == 1)) {
- scroller = (scroller + 1) % 3;
- LCD_Display(scroller);
- Chess_Locations(0);
- LED_Convert();
- outchar('b');
- new_BTM_BTN = 0;
- }
- if ((TOP_BTN == 1) && (new_TOP_BTN == 1)) {
- scroller = 4; //lock at GAME TIMER MODE
- TIE_C7I = 1; //enable TIM interrupts
- outchar('t');
- new_TOP_BTN = 0;
- }
- if ((new_shiny_button == 1)) {
- outchar('s');
- new_shiny_button = 0;
- if(scroller == 4) //if the game is already going
- PlayerToggle = !PlayerToggle; // toggle the active player
- else if(scroller == 3)
- {
- scroller = 1;
- LCD_Display(scroller);
- } else if(scroller == 2)
- {
- scroller = 3; //edit start time mode
- LCD_Display(scroller);
- } else if(scroller == 1)
- {
- PlayerToggle = 0;
- scroller = 4; //start the game
- TIE_C7I = 1; //enable TIM interrupts
- }
- //enter the game menu
- else if(scroller == 0)
- {
- outchar('0');
- scroller = 1; //lock at GAME TIMER MODE
- LCD_Display(scroller);
- }
- }
- if (timerup == 1) {
- LCD_Timer();
- timerup = 0;
- }
- if(rightturn)
- {
- outchar('r');
- rightturn = 0;
- if(scroller != 4)
- {
- if(scroller == 1)
- scroller = 2;
- else if(scroller ==2)
- scroller = 1;
- if(scroller == 3)
- {
- P1mins++;
- P2mins++;
- }
- LCD_Display(scroller);
- Chess_Locations(0);
- LED_Convert();
- }
- }
- if(leftturn)
- {
- outchar('l');
- leftturn = 0;
- if(scroller != 4)
- {
- if(scroller == 1)
- scroller = 2;
- else if(scroller ==2)
- scroller = 1;
- if(scroller == 3)
- {
- P1mins--;
- P2mins--;
- }
- LCD_Display(scroller);
- }
- }
- _FEED_COP(); /* feeds the dog */
- } /* loop forever */
- /* please make sure that you never leave main */
- }
- /*********************************************************************************
- * Chess Control Functions
- **********************************************************************************
- **********************************************************************************
- * Name: Chess_Locations
- * Description: Manages vitual piece location map.
- * [->] (global): ChessMatrix: Map of the board.
- * 00 = empty space
- * X1 = pawn
- * X2 = rook
- * X3 = knight
- * X4 = bishop
- * X5 = Queen
- * X6 = King
- * 1X = White piece
- * 2X = Black piece
- * (int): Mode: Mode of map.
- * 0 = Initialization for new game.
- * 1 = Standard
- * [<-] (void): [void]
- *********************************************************************************/
- void Chess_Locations(int Mode) {
- if (Mode == 0) {
- ChessMatrix[0][0] = 12;
- ChessMatrix[0][1] = 13;
- ChessMatrix[0][2] = 14;
- ChessMatrix[0][3] = 15;
- ChessMatrix[0][4] = 16;
- ChessMatrix[0][5] = 14;
- ChessMatrix[0][6] = 13;
- ChessMatrix[0][7] = 12;
- ChessMatrix[1][0] = 11;
- ChessMatrix[1][1] = 11;
- ChessMatrix[1][2] = 11;
- ChessMatrix[1][3] = 11;
- ChessMatrix[1][4] = 11;
- ChessMatrix[1][5] = 11;
- ChessMatrix[1][6] = 11;
- ChessMatrix[1][7] = 11;
- ChessMatrix[2][0] = 0;
- ChessMatrix[2][1] = 0;
- ChessMatrix[2][2] = 0;
- ChessMatrix[2][3] = 0;
- ChessMatrix[2][4] = 0;
- ChessMatrix[2][5] = 0;
- ChessMatrix[2][6] = 0;
- ChessMatrix[2][7] = 0;
- ChessMatrix[3][0] = 0;
- ChessMatrix[3][1] = 0;
- ChessMatrix[3][2] = 0;
- ChessMatrix[3][3] = 0;
- ChessMatrix[3][4] = 0;
- ChessMatrix[3][5] = 0;
- ChessMatrix[3][6] = 0;
- ChessMatrix[3][7] = 0;
- ChessMatrix[4][0] = 0;
- ChessMatrix[4][1] = 0;
- ChessMatrix[4][2] = 0;
- ChessMatrix[4][3] = 0;
- ChessMatrix[4][4] = 0;
- ChessMatrix[4][5] = 0;
- ChessMatrix[4][6] = 0;
- ChessMatrix[4][7] = 0;
- ChessMatrix[5][0] = 0;
- ChessMatrix[5][1] = 0;
- ChessMatrix[5][2] = 0;
- ChessMatrix[5][3] = 0;
- ChessMatrix[5][4] = 0;
- ChessMatrix[5][5] = 0;
- ChessMatrix[5][6] = 0;
- ChessMatrix[5][7] = 0;
- ChessMatrix[6][0] = 21;
- ChessMatrix[6][1] = 21;
- ChessMatrix[6][2] = 21;
- ChessMatrix[6][3] = 21;
- ChessMatrix[6][4] = 21;
- ChessMatrix[6][5] = 21;
- ChessMatrix[6][6] = 21;
- ChessMatrix[6][7] = 21;
- ChessMatrix[7][0] = 22;
- ChessMatrix[7][1] = 23;
- ChessMatrix[7][2] = 24;
- ChessMatrix[7][3] = 26;
- ChessMatrix[7][4] = 25;
- ChessMatrix[7][5] = 24;
- ChessMatrix[7][6] = 23;
- ChessMatrix[7][7] = 22;
- }
- if (Mode == 1) { //Update locations map
- }
- return;
- }
- /*********************************************************************************
- * LED Matrix Functions
- **********************************************************************************
- **********************************************************************************
- * Name: LED_Out
- * Description: Shifts out the updated LED matrix data.
- * [->] (global): datas
- * [<-] (void): [void]
- *********************************************************************************/
- void LED_Out(void) {
- int i = 0;
- for (i = 0; i < 8; i++) {
- while (SPISR_SPTEF == 0) {
- //Loop until SPISR data register is empty
- }
- SPIDR = LEDOutData[i]; //Put data into SPISR data register
- LCD_Delay(0); //Call a delay for shifting out
- //enable daisy chain disable LCD
- }
- return;
- }
- /*********************************************************************************
- * Name: LED_Convert
- * Description: Converts chess data to LED data.
- * [->] (global): datas
- * [<-] (void): [void]
- *********************************************************************************/
- void LED_Convert(void) {
- int i = 0;
- int j = 0;
- int k = 0;
- int temp = 1;
- for (i = 0; i < 8; i++) { //Chess column loop
- LEDOutData[i] = 0; //Clear of former data.
- for (j = 0; j < 8; j++) { //Chess row loop
- if (ChessMatrix[i][j] != 0) { //if piece exists on tile
- temp = 1;
- for (k = 0; k < j; k++) { //shifting data calculation
- temp = temp * 2;
- }
- LEDOutData[i] += temp;
- }
- }
- }
- return;
- }
- /*********************************************************************************
- * Hall Sensor Functions
- **********************************************************************************
- **********************************************************************************
- * Name: HALL_Input
- * Description: Collects magnet connection data.
- * [->] (global): datas
- * [<-] (void): [void]
- *********************************************************************************/
- void HALL_Input(void) {
- int i = 0;
- int j = 0;
- for (i = 0; i < 8; i++) {
- for (j = 0; j < 8; j++) {
- //write to HallMatrix[][]
- }
- }
- return;
- }
- /*********************************************************************************
- * LCD Specific Functions
- **********************************************************************************
- **********************************************************************************
- * Name: LCD_Timer
- * Description: Refreshes the chess timer.
- * [->] (global): P1mins: Player 1 minutes remaining
- * P1secs: Player 1 seconds remaining
- * P2mins: Player 2 minutes remaining
- * P2secs: Player 2 seconds remaining
- * [<-] (void): [void]
- *********************************************************************************/
- void LCD_Timer(void) {
- int t1 = 0;
- int t2 = 0;
- LineOffset = 0x00;
- LCD_Send_Byte(LCD_CLEAR, 1); //Instruction mode
- LCD_Cursor_Position(1);
- LCD_Send_Byte('W',0);
- LCD_Cursor_Position(1);
- LCD_Send_Byte('h',0);
- LCD_Cursor_Position(1);
- LCD_Send_Byte('i',0);
- LCD_Cursor_Position(1);
- LCD_Send_Byte('t',0);
- LCD_Cursor_Position(1);
- LCD_Send_Byte('e',0);
- LCD_Cursor_Position(1);
- LCD_Send_Byte(':',0);
- LCD_Cursor_Position(1);
- LCD_Send_Byte(' ',0);
- LCD_Cursor_Position(1);
- LCD_Send_Byte(' ',0);
- LCD_Cursor_Position(1);
- LCD_Send_Byte(' ',0);
- LCD_Cursor_Position(1);
- LCD_Send_Byte(' ',0);
- t2 = P1mins % 10;
- t1 = P1mins / 10;
- LCD_Cursor_Position(1);
- LCD_Send_Byte(t1 + 0x30,0);
- LCD_Cursor_Position(1);
- LCD_Send_Byte(t2 + 0x30,0);
- LCD_Cursor_Position(1);
- LCD_Send_Byte(':',0);
- t2 = P1secs % 10;
- t1 = P1secs / 10;
- LCD_Cursor_Position(1);
- LCD_Send_Byte(t1 + 0x30,0);
- LCD_Cursor_Position(1);
- LCD_Send_Byte(t2 + 0x30,0);
- //-----------------------
- LineOffset = 0x00;
- LCD_Cursor_Position(2);
- LCD_Send_Byte('B',0);
- LCD_Cursor_Position(2);
- LCD_Send_Byte('l',0);
- LCD_Cursor_Position(2);
- LCD_Send_Byte('a',0);
- LCD_Cursor_Position(2);
- LCD_Send_Byte('c',0);
- LCD_Cursor_Position(2);
- LCD_Send_Byte('k',0);
- LCD_Cursor_Position(2);
- LCD_Send_Byte(':',0);
- LCD_Cursor_Position(2);
- LCD_Send_Byte(' ',0);
- LCD_Cursor_Position(2);
- LCD_Send_Byte(' ',0);
- LCD_Cursor_Position(2);
- LCD_Send_Byte(' ',0);
- LCD_Cursor_Position(2);
- LCD_Send_Byte(' ',0);
- t2 = P2mins % 10;
- t1 = P2mins / 10;
- LCD_Cursor_Position(2);
- LCD_Send_Byte(t1 + 0x30,0);
- LCD_Cursor_Position(2);
- LCD_Send_Byte(t2 + 0x30,0);
- LCD_Cursor_Position(2);
- LCD_Send_Byte(':',0);
- t2 = P2secs % 10;
- t1 = P2secs / 10;
- LCD_Cursor_Position(2);
- LCD_Send_Byte(t1 + 0x30,0);
- LCD_Cursor_Position(2);
- LCD_Send_Byte(t2 + 0x30,0);
- LCD_Cursor_Position(2);
- LCD_Send_Byte(' ',0);
- return;
- }
- /*********************************************************************************
- * Name: LCD_Delay
- * Description: Creates a delay of ~2ms or ~30cy using ASM NOPs.
- * [->] (int): mode: Operational mode of the function.
- * 0 = Short wait mode (~30cy)
- * 1 = Long wait mode (~25,000cy) = (~2ms)
- * [<-] (void): [void]
- *********************************************************************************/
- void LCD_Delay(int mode) {
- int i = 0; //Wait loop counter
- //Mode check
- if (mode == 0) {
- mode = 3;
- } else {
- mode = 2500;
- }
- //Wait generation loop
- for (i = 0; i <= mode; i++) {
- asm {
- nop
- nop
- nop
- nop
- nop
- nop
- nop
- nop
- nop
- nop
- }
- }
- return;
- }
- /*********************************************************************************
- * Name: LCD_Cursor_Position
- * Description: Moves the LCD Cursor vertically and horizontally.
- * [->] (int): LineNumber: Declares the line number the cursor is to be moved to
- * 1 = Cursor to be moved to line #1
- * 2 = Cursor to be moved to line #2
- * [<-] (void): [void]
- *********************************************************************************/
- void LCD_Cursor_Position(int LineNumber) {
- LCD_Send_Byte(LCD_CURSOR, 1);
- if (LineNumber == 1) {
- LCD_Send_Byte((LCD_LINE1 + LineOffset), 1); //Instruction mode
- } else {
- LCD_Send_Byte((LCD_LINE2 + LineOffset), 1); //Instruction mode
- }
- LineOffset = LineOffset + 0x01;
- return;
- }
- /*********************************************************************************
- * Name: LCD_Send_Byte
- * Description: Sends character or instruction through respective shift register.
- * [->] (uchar): data: The byte of data to be sent through the shift register
- * (int): mode: Operational mode of the function,
- * 0 = Normal sending mode
- * 1 = Instruction sending mode
- * [<-] (void): [void]
- *********************************************************************************/
- void LCD_Send_Byte(char data, int mode) {
- if (mode == 1) {
- LCD_RS = 0; //Register select line low
- }
- while (SPISR_SPTEF == 0) {
- //Loop until SPISR data register is empty
- }
- SPIDR = data; //Put data into SPISR data register
- LCD_Delay(0); //Call a 30cy delay so that data can shift out
- LCD_CLK = 0; //this may be some other clock i don't know
- LCD_CLK = 1;
- LCD_Delay(1); //Call a 2ms delay so LCD can respond
- if (mode == 1) {
- LCD_RS = 1; //Register select line high. This is the default.
- }
- return;
- }
- /*********************************************************************************
- * Name: LCD_Display
- * Description: Displays some text on the chosen LCD.
- * [->] (int): MsgType: The pre-rendered message to print to the LCD.
- * 0 = "Press the shiny|button to start!"
- * 1 = " --OPTION-- | >Start chess"
- * 2 = " --OPTION-- |< Edit timer"
- * 3 = " --PAUSED-- |Press to resume"
- * [<-] (void): [void]
- *********************************************************************************/
- void LCD_Display(int MsgType) {
- LineOffset = 0x00;
- LCD_Send_Byte(LCD_CLEAR, 1); //Instruction mode
- if (MsgType == 0) {
- LCD_Cursor_Position(1);
- LCD_Send_Byte('P',0);
- LCD_Cursor_Position(1);
- LCD_Send_Byte('r',0);
- LCD_Cursor_Position(1);
- LCD_Send_Byte('e',0);
- LCD_Cursor_Position(1);
- LCD_Send_Byte('s',0);
- LCD_Cursor_Position(1);
- LCD_Send_Byte('s',0);
- LCD_Cursor_Position(1);
- LCD_Send_Byte(' ',0);
- LCD_Cursor_Position(1);
- LCD_Send_Byte('t',0);
- LCD_Cursor_Position(1);
- LCD_Send_Byte('h',0);
- LCD_Cursor_Position(1);
- LCD_Send_Byte('e',0);
- LCD_Cursor_Position(1);
- LCD_Send_Byte(' ',0);
- LCD_Cursor_Position(1);
- LCD_Send_Byte('s',0);
- LCD_Cursor_Position(1);
- LCD_Send_Byte('h',0);
- LCD_Cursor_Position(1);
- LCD_Send_Byte('i',0);
- LCD_Cursor_Position(1);
- LCD_Send_Byte('n',0);
- LCD_Cursor_Position(1);
- LCD_Send_Byte('y',0);
- LineOffset = 0x00;
- LCD_Cursor_Position(2);
- LCD_Send_Byte('b',0);
- LCD_Cursor_Position(2);
- LCD_Send_Byte('u',0);
- LCD_Cursor_Position(2);
- LCD_Send_Byte('t',0);
- LCD_Cursor_Position(2);
- LCD_Send_Byte('t',0);
- LCD_Cursor_Position(2);
- LCD_Send_Byte('o',0);
- LCD_Cursor_Position(2);
- LCD_Send_Byte('n',0);
- LCD_Cursor_Position(2);
- LCD_Send_Byte(' ',0);
- LCD_Cursor_Position(2);
- LCD_Send_Byte('t',0);
- LCD_Cursor_Position(2);
- LCD_Send_Byte('o',0);
- LCD_Cursor_Position(2);
- LCD_Send_Byte(' ',0);
- LCD_Cursor_Position(2);
- LCD_Send_Byte('s',0);
- LCD_Cursor_Position(2);
- LCD_Send_Byte('t',0);
- LCD_Cursor_Position(2);
- LCD_Send_Byte('a',0);
- LCD_Cursor_Position(2);
- LCD_Send_Byte('r',0);
- LCD_Cursor_Position(2);
- LCD_Send_Byte('t',0);
- LCD_Cursor_Position(2);
- LCD_Send_Byte('!',0);
- } else if (MsgType == 1) {
- LCD_Cursor_Position(1);
- LCD_Send_Byte(' ',0);
- LCD_Cursor_Position(1);
- LCD_Send_Byte(' ',0);
- LCD_Cursor_Position(1);
- LCD_Send_Byte(' ',0);
- LCD_Cursor_Position(1);
- LCD_Send_Byte('-',0);
- LCD_Cursor_Position(1);
- LCD_Send_Byte('-',0);
- LCD_Cursor_Position(1);
- LCD_Send_Byte('O',0);
- LCD_Cursor_Position(1);
- LCD_Send_Byte('P',0);
- LCD_Cursor_Position(1);
- LCD_Send_Byte('T',0);
- LCD_Cursor_Position(1);
- LCD_Send_Byte('I',0);
- LCD_Cursor_Position(1);
- LCD_Send_Byte('O',0);
- LCD_Cursor_Position(1);
- LCD_Send_Byte('N',0);
- LCD_Cursor_Position(1);
- LCD_Send_Byte('-',0);
- LCD_Cursor_Position(1);
- LCD_Send_Byte('-',0);
- LineOffset = 0x00;
- LCD_Cursor_Position(2);
- LCD_Send_Byte(' ',0);
- LCD_Cursor_Position(2);
- LCD_Send_Byte(0x7E,0);
- LCD_Cursor_Position(2);
- LCD_Send_Byte('S',0);
- LCD_Cursor_Position(2);
- LCD_Send_Byte('t',0);
- LCD_Cursor_Position(2);
- LCD_Send_Byte('a',0);
- LCD_Cursor_Position(2);
- LCD_Send_Byte('r',0);
- LCD_Cursor_Position(2);
- LCD_Send_Byte('t',0);
- LCD_Cursor_Position(2);
- LCD_Send_Byte(' ',0);
- LCD_Cursor_Position(2);
- LCD_Send_Byte('c',0);
- LCD_Cursor_Position(2);
- LCD_Send_Byte('h',0);
- LCD_Cursor_Position(2);
- LCD_Send_Byte('e',0);
- LCD_Cursor_Position(2);
- LCD_Send_Byte('s',0);
- LCD_Cursor_Position(2);
- LCD_Send_Byte('s',0);
- LCD_Cursor_Position(2);
- LCD_Send_Byte(' ',0);
- LCD_Cursor_Position(2);
- LCD_Send_Byte(' ',0);
- LCD_Cursor_Position(2);
- LCD_Send_Byte(' ',0);
- } else if (MsgType == 2) {
- LCD_Cursor_Position(1);
- LCD_Send_Byte(' ',0);
- LCD_Cursor_Position(1);
- LCD_Send_Byte(' ',0);
- LCD_Cursor_Position(1);
- LCD_Send_Byte(' ',0);
- LCD_Cursor_Position(1);
- LCD_Send_Byte('-',0);
- LCD_Cursor_Position(1);
- LCD_Send_Byte('-',0);
- LCD_Cursor_Position(1);
- LCD_Send_Byte('O',0);
- LCD_Cursor_Position(1);
- LCD_Send_Byte('P',0);
- LCD_Cursor_Position(1);
- LCD_Send_Byte('T',0);
- LCD_Cursor_Position(1);
- LCD_Send_Byte('I',0);
- LCD_Cursor_Position(1);
- LCD_Send_Byte('O',0);
- LCD_Cursor_Position(1);
- LCD_Send_Byte('N',0);
- LCD_Cursor_Position(1);
- LCD_Send_Byte('-',0);
- LCD_Cursor_Position(1);
- LCD_Send_Byte('-',0);
- LineOffset = 0x00;
- LCD_Cursor_Position(2);
- LCD_Send_Byte(0x7F,0);
- LCD_Cursor_Position(2);
- LCD_Send_Byte(' ',0);
- LCD_Cursor_Position(2);
- LCD_Send_Byte('E',0);
- LCD_Cursor_Position(2);
- LCD_Send_Byte('d',0);
- LCD_Cursor_Position(2);
- LCD_Send_Byte('i',0);
- LCD_Cursor_Position(2);
- LCD_Send_Byte('t',0);
- LCD_Cursor_Position(2);
- LCD_Send_Byte(' ',0);
- LCD_Cursor_Position(2);
- LCD_Send_Byte('T',0);
- LCD_Cursor_Position(2);
- LCD_Send_Byte('i',0);
- LCD_Cursor_Position(2);
- LCD_Send_Byte('m',0);
- LCD_Cursor_Position(2);
- LCD_Send_Byte('e',0);
- LCD_Cursor_Position(2);
- LCD_Send_Byte('r',0);
- LCD_Cursor_Position(2);
- LCD_Send_Byte(' ',0);
- LCD_Cursor_Position(2);
- LCD_Send_Byte(' ',0);
- LCD_Cursor_Position(2);
- LCD_Send_Byte(' ',0);
- LCD_Cursor_Position(2);
- LCD_Send_Byte(' ',0);
- } else if (MsgType == 3) {
- LCD_Timer();
- }
- }
- /*********************************************************************************
- * Interrupt Functions
- **********************************************************************************
- **********************************************************************************
- * Name: RTI_ISR
- * Description: Interrupt at 2.048ms intervals. Checks pushbutton states.
- * [->] (*): (*)
- * [<-] (void): [void]
- *********************************************************************************/
- interrupt 7 void RTI_ISR(void)
- {
- CRGFLG = CRGFLG | 0x80;
- /*if(PTAD_PTAD7 == 0 && prevpb == 1) //active low, 1 is unpressed, 0 is pressed
- leftpb = 1;
- if(PTAD_PTAD6 == 0 && prevpb == 1)
- rghtpb = 1;
- prevpb = PTAD_PTAD6 & PTAD_PTAD7;*/
- //debug
- if ((TOP_BTN == 0) && (new_TOP_BTN == 0)) {
- new_TOP_BTN = 1;
- }
- if ((BTM_BTN == 0) && (new_BTM_BTN == 0)) {
- new_BTM_BTN = 1;
- }
- if(shiny_button == 1 && prev_shiny_button ==0)
- {
- new_shiny_button = 1;
- }
- prev_shiny_button = shiny_button;
- if(RPG_A == 1)
- {
- rightcount++;
- if(leftcount > 3)
- leftturn = 1;
- leftcount = 0;
- }
- if(RPG_B ==1)
- {
- leftcount++;
- if(rightcount > 3)
- rightturn = 1;
- rightcount = 0;
- }
- /*if ((RPG_A == 1) && (en2 == 0))
- {
- en1 == 1;
- }
- if (RPG_A == 1 && old_RPGB == 0) {
- new_RPGA = 1;
- }
- if (RPG_B == 1 && old_RPGA == 0) {
- new_RPGB = 1;
- }
- old_RPGA = RPG_A;
- old_RPGB = RPG_B;
- */
- }
- /**********************************************************************************
- * Name: TIM_ISR
- * Description: TIM RTI at xms for x
- * [->] (*): (*)
- * [<-] (void): [void]
- **********************************************************************************/
- interrupt 15 void TIM_ISR( void)
- {
- TFLG1 = TFLG1 | 0x80;
- bcnt++;
- if (bcnt == 100) {
- if (PlayerToggle == 0) {
- if (P1secs == 0) {
- P1mins--;
- P1secs = 59;
- if(P1mins <= 0 && P1secs <= 0) {
- P1mins = 0;
- P1secs = 0;
- timeExpired = 1;
- }
- } else {
- P1secs--;
- }
- } else {
- if (P2secs == 0) {
- P2mins--;
- P2secs = 59;
- if(P2mins <= 0 && P2secs <= 0) {
- P2mins = 0;
- P2secs = 0;
- timeExpired = 1;
- }
- } else {
- P2secs--;
- }
- }
- timerup = 1;
- bcnt = 0;
- }
- }
- /**********************************************************************************
- * Name: SCI_ISR
- * Description: SCI RTI for character data transfer to radial buffer.
- * [->] (*): (*)
- * [<-] (void): [void]
- **********************************************************************************/
- interrupt 20 void SCI_ISR( void)
- {
- SCISR1_TDRE; //Read status flag to ready data register
- if (tin == tout) {
- SCICR2 = SCICR2 & 0x7F;
- } else {
- SCIDRL = tbuf[tout];
- tout = (tout + 1) % tsize;
- }
- }
- /*********************************************************************************
- * Character I/O Library Routines
- **********************************************************************************
- **********************************************************************************
- * Name: inchar
- * Description: Inputs ASCII character from SCI serial port and returns it.
- * [->] (void): [void]
- * [<-] (char): ASCII value from Teraterm .
- *********************************************************************************/
- char inchar(void) {
- /* receives character from the terminal channel */
- while (!(SCISR1 & 0x20)); /* wait for input */
- return SCIDRL;
- }
- /*********************************************************************************
- * Name: outchar
- * Description: Outputs ASCII character to the SCI serial port.
- * [->] (char): ASCII value.
- * [<-] (void): [void]
- *********************************************************************************/
- void outchar(char ch) {
- /* sends a character to the terminal channel */
- while (!(SCISR1 & 0x80)); /* wait for output buffer empty */
- SCIDRL = ch;
- }
- /**********************************************************************************
- * Name: bco
- * Description: Outputs character data in radial buffer to serial.
- * [->] (*): (*)
- * [<-] (void): [void]
- **********************************************************************************/
- void bco(char input)
- {
- while(((tin + 1) % tsize) == tout) {}
- tbuf[tin] = input;
- tin = (tin + 1) % tsize;
- SCICR2 = SCICR2 | 0x80;
- }
- /*********************************************************************************
- * ECE 362 - Mini-Project C Source File - Fall 2012
- *********************************************************************************/
Advertisement
Add Comment
Please, Sign In to add comment