Exemplo n.º 1
0
Arquivo: main.c Projeto: ryanlamo/lab5
int main(void) {
    WDTCTL = WDTPW | WDTHOLD;

    player = initPlayer();

    initSPI();
    LCDinit();
    LCDclear();

    RenewGame();

    printPlayer(player);


    init_timer();
    init_buttons();
   __enable_interrupt();


    while(1)
    {

    	if (player==0xC7)
    	{

    		TACTL &= ~TAIE;
    		LCDclear();
    		cursorToLineOne();
    		writeString("YOU");
    		cursorToLineTwo();
    		writeString("WON!");
    		gamedone = 1;
    		_delay_cycles(1000000);

   	    }


    	if (CountTimer >=4)
    	{
    		TACTL &= ~TAIE;
    		LCDclear();
    		cursorToLineOne();
    		writeString("Game");
    		cursorToLineTwo();
    		writeString("Over");
    		gamedone = 1;
    		_delay_cycles(1000000);

    	}

    }

	
	return 0;
}
Exemplo n.º 2
0
void clearScreen()
{
	cursorToLineOne();
	writeString(clear);
	cursorToLineTwo();
	writeString(clear);
}
Exemplo n.º 3
0
void cursorToLineTwo() {
	cursorToLineOne();
	int i;
	for (i = 0; i < 40; i++) {
		writeCommandByte(0x14);
	}
}
Exemplo n.º 4
0
void scrollString(char * string1, char * string2, int message1Length,
		int message2Length) {
	int i = 0;

	while (1) {

		if (i % message1Length + LCD_WIDTH<= message1Length) {
			writeString((string1 + i % message1Length), LCD_WIDTH);

		} else {
			writeString(string1 + i % message1Length,
					message1Length - i % message1Length);
			writeString(string1, i % message1Length);
		}
		cursorToLineTwo();

		if (i % message2Length + LCD_WIDTH <= message2Length) {
			writeString((string2 + i % message2Length), LCD_WIDTH);

		} else {
			writeString(string2 + i % message2Length,
					message2Length - i % message2Length);
			writeString(string2, i % message2Length);
		}
		cursorToLineOne();
		//resets the cursor
		i++;
	}

}
Exemplo n.º 5
0
unsigned char gameOver(unsigned char  player)
{
	clearPlayer(player);
	cursorToLineOne();
	writeString(game);
	cursorToLineTwo();
	writeString(over);
	return initPlayer();
}
Exemplo n.º 6
0
unsigned char youWon(unsigned char player)
{
	clearPlayer(player);
	cursorToLineOne();
	writeString(you);
	cursorToLineTwo();
	writeString(won);

	return initPlayer();
}
Exemplo n.º 7
0
int main(void){
	WDTCTL = WDTPW | WDTHOLD;
			char message[] = "ECE 382 is my favorite class! ";
			char message2[]= "I got 99 problems... but a git ain't one. ";
			initSPI();
			LCDinit();
			LCDclear();
			cursorToLineOne();
			scrollString(message,message2);
			while (1){};
}
Exemplo n.º 8
0
int main(void)
{
        WDTCTL = (WDTPW|WDTHOLD);


        player = initPlayer(); //debugging: had player defined twice, caused * to jump around alot
        initSPI();
        LCDinit();
        LCDclear();
        printPlayer(player);
        init_timer();
        init_buttons();
        __enable_interrupt();


        while(1)
        {
        	 if(player == 0xC7){
        	                    TACTL &= ~TAIE;
        	                    LCDclear();
        	                    cursorToLineOne();
        	                    writeString("YOU");
        	                    cursorToLineTwo();
        	                    writeString("WON!");
        	                    gameover = 1;
        	                    _delay_cycles(100000);
        	            }
        	            if(timerCount >= 4){
        	                    TACTL &= ~TAIE;
        	                    LCDclear();
        	                    cursorToLineOne();
        	                    writeString("Game");
        	                    cursorToLineTwo();
        	                    writeString("Over!");
        	                    gameover = 1;
        	                    _delay_cycles(100000);
        	            }
        }

        return 0;
}
Exemplo n.º 9
0
/*Author: Travis Schriner
 * Date 21 Oct 2013
 * Description: This program interacts with the
 * LCD in the geekbox and allows me to write to it
 *
 */
int main(void) {
    WDTCTL = WDTPW | WDTHOLD;	// Stop watchdog timer
	
    initSPI();
    LCDinit();
    LCDclear();

    char *topMessage = "ECE382 is my Favorite Class!";
    char *prompt = "Message?";
    char *promptKey = "Press123";
    char *message1 = "This is message 1 fool!";
    char *message2 = "This is message 2 fool!";
    char *message3 = "This is message 3 fool!";



    cursorToLineOne();
    writeString(prompt);
    cursorToLineTwo();
    writeString(promptKey);


    configureP1PinAsButton(BIT1|BIT2|BIT3);         // configure pins 1, 2, and 3 as buttons

       P1DIR |= BIT0|BIT6;                             // set launchpad LEDs to output

           char buttons[] = {BIT1, BIT2, BIT3};
           char pressedButton = pollP1Buttons(buttons, 3);

           switch (pressedButton) {
               case BIT1:

            	   waitForP1ButtonRelease(BIT1);
            	   scrollString(topMessage, message1);

                   break;
               case BIT2:

            	   waitForP1ButtonRelease(BIT2);
            	   scrollString(topMessage, message2);
                   break;
               case BIT3:

            	   waitForP1ButtonRelease(BIT3);
            	   scrollString(topMessage, message3);

                   break;
           }
 while(1){

 }
}
Exemplo n.º 10
0
/*
 * main.c
 */
int main(void) {
	WDTCTL = WDTPW | WDTHOLD;	// Stop watchdog timer


	//Create strings of text to output to the user
	char * requiredMsg = "ECE382 is my favorite class! ";
	char * prompt = "Message?";
	char * promptKey = "Press123";

	char * message1 = "Learn from yesterday... ";

	char * message2 = "Live for today... ";

	char * message3 = "Hope for tomorrow. ";


	//SPI initialization function
	initSPI();

	// LCD initialization function
	LCDinit();

	//Clear the LCD screen
	LCDclr();

	//Position the cursor to write the prompt to the user.
	cursorToLineOne();
	writeString(prompt);

	cursorToLineTwo();
	writeString(promptKey);

	int buttonPushed = 0;
	//A different value is returned depending on which button is pushed.
	buttonPushed = pollButton();

	//Move the selected message to the screen
	if (buttonPushed == 1) {
		scrollString(requiredMsg, message1);
	}

	if (buttonPushed == 2) {
		scrollString(requiredMsg, message2);
	}

	if (buttonPushed == 3) {
		scrollString(requiredMsg, message3);
	}

	return 0;
}
Exemplo n.º 11
0
//courtesy of C2C Steinmiller...
void scrollString(char *string1, char *string2) {
        unsigned int i = 0;

        char *count1 = string1, *count2 = string2;

        while (1) {
                cursorToLineOne();
                char *currentChar = count1;

                for (i = 0; i < 8; i++) {
                     writeDataByte(*currentChar);        //send data in the string to be written

                     currentChar++;

                     if (*currentChar == 0)
                           currentChar = string1;
                }
                count1++;

                if (*count1 == 0) {
                     count1 = string1;
                }

                cursorToLineTwo();
                char *currentChar2 = count2;
                for (i = 0; i < 8; i++) {
                      writeDataByte(*currentChar2);        //send data in the string to be written

                      currentChar2++;

                      if (*currentChar2 == 0)
                      currentChar2 = string2;
                }
                count2++;

                if (*count2 == 0) {
                    count2 = string2;
                }

                __delay_cycles(600000);

                LCDclear();
        }
}
Exemplo n.º 12
0
Arquivo: main.c Projeto: Jsrazz/Lab4
/*Author C2C Rasmussen
 * Date Oct 28 13
 *
 *  Implements the program
 * main.c
 */
int main(void) {
	WDTCTL = WDTPW | WDTHOLD;	// Stop watchdog timer

	//stores strings in an arrays (idea from C2C Mordan)

	char string1[] = {'E','C','E',' ','3', '8', '2',' ','i','s',' ','m','y',' ','f','a','v','o','r','i','t','e',' ','c','l','a','s','s','!',' ',' '};

	char message[] = {'P','R','E','S','S',' ','K','E','Y',' ',' '}; // 11 in length
	char message1[] = {'w','a','z','z','u','p'}; // 6 in length
	char message2[] = {'h','o','w',' ','d','o',' ','y','o','u', ' ','d','o','?',' ',' '}; // 16 in length
	char message3[] = {'f','a','l','c','o','n',' ','p','u','n','c','h',' ',' '}; // 14 in length

	initSPI();
	LCDinit();
	LCDclear();

		while(1){
	cursorToLineOne();
	createString(message, 11);

	scrollLCD(message, 11);



	configureP1PinAsButton(BIT1|BIT2|BIT3);         // configure pins 1, 2, and 3 as buttons

	P1DIR |= BIT0|BIT6;                             // set launchpad LEDs to output

	while (1) {
		char buttons[] = {BIT1, BIT2, BIT3};
		char pressedButton = pollP1Buttons(buttons, 3);

		switch (pressedButton) {
		case BIT1:							// detects if Bit1 is enabled
			P1OUT ^= BIT0|BIT6;
			waitForP1ButtonRelease(BIT1);

			while(1){
			cursorToLineOne();						//passes new message
			createString(string1, 31);
			cursorToLineTwo();
			createString(message1, 6 );
			scrollLCD(string1, 31);
			scrollLCD(message1, 6);
			}
			// do something in response
			break;


		case BIT2:

			P1OUT ^= BIT0|BIT6;
			waitForP1ButtonRelease(BIT2);
			// do something in response

			while(1){
			cursorToLineOne();
			createString(string1, 31);
			cursorToLineTwo();
			createString(message2, 16 );
			scrollLCD(string1, 31);
			scrollLCD(message2, 16);
			}
			break;


		case BIT3:
			// toggle LEDs and wait for release
			P1OUT ^= BIT0|BIT6;
			waitForP1ButtonRelease(BIT3);


			while(1){
			cursorToLineOne();
			createString(string1, 31);
			cursorToLineTwo();
			createString(message3, 14 );
			scrollLCD(string1, 31);
			scrollLCD(message3, 14);
			}
			break;
		}
	}

		}

}
Exemplo n.º 13
0
int main(void) {
	WDTCTL = WDTPW | WDTHOLD;	// Stop watchdog timer
	char * endMessageTop = "You am  ";
	char * endMessageBottomLose = "lose    ";
	char * endMessageBottomWin = "Not lose";
	char * deadMessage = "Dead    ";
	unsigned char player;
	unsigned char mines[NUM_MINES];

	while (1) {
		timer = 0;
		button = 0;
		player = initPlayer();
		initProgram();
		printPlayer(player);
		generateMines(mines);

		//run while none of the end-game situations have occurred
		while ((timer < 4) && !didPlayerWin(player)
				&& !didPlayerHitMine(player, mines)) {

			if (button) {
				switch (button) {
				case BIT0:
					player = movePlayer(player, RIGHT);
					break;
				case BIT1:
					player = movePlayer(player, LEFT);
					break;
				case BIT2:
					player = movePlayer(player, UP);
					break;
				case BIT3:
					player = movePlayer(player, DOWN);
					break;
				}
				button = 0;
			}
		}

		//if the timer hits 2 seconds, or if the player hits a mine, the game is over
		if (timer == 4 || didPlayerHitMine(player, mines)) {

			//displays a special message if the player lost due to hitting a mine
			if (didPlayerHitMine(player, mines)) {
				cursorToLineOne();
				writeString(deadMessage, 8);
				_delay_cycles(500000);
			}
			button = 0;

			//displays game over message
			cursorToLineOne();
			writeString(endMessageTop, 8);
			cursorToLineTwo();
			writeString(endMessageBottomLose, 8);
		}
		//if the player hits 0xC7 they win, display the win message
		else if (didPlayerWin(player)) {
			button = 0;
			cursorToLineOne();
			writeString(endMessageTop, 8);
			cursorToLineTwo();
			writeString(endMessageBottomWin, 8);
		}

		// Waits for a button input and then resets the game
		while (button != 0) {
		}
	}
}