Skip to content

EricWardner/ECE382_Lab04

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

20 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ECE382_Lab04

alt text

<script src="./ECE382 - Lab 4 - C - Etch-a-Sketch and Pong _files/bootstrap.min.js"></script>

Prelab

Eric Wardner

Size Signed/Unsigned Type Min value Max value
8-bit unsigned char 0 or -128 255 or 127
8-bit signed signed char -128 127
16-bit unsigned unsigned short 0 65,535
16-bit signed short or int -32,768 32,767
32-bit unsigned unsigned long 0 4,294,967,295
32-bit signed long, signed long -2,147,483,648 2,147,483,647
64-bit unsigned unsigned long long 0 18,446,744,073,709,551,615
64-bit signed long long, signed long long -9,223,372,036,854,775,808 9,223,372,036,854,775,807

Fill in the following chart with the appropriate C code definitions.

Type Meaning C typedef declaration
int8 unsigned 8-bit value typedef char int8
sint8 signed 8-bit value typedef signed char sint8
int16 unsigned 16-bit value typedef unsigned short int16;
sint16 signed 16-bit value typedef short sint16
int32 unsigned 32-bit value typedef unsigned long int32
sint32 signed 32-bit value typedef long sint32
int64 unsigned 64-bit value typedef unsigned long long int64
sint64 signed 64-bit value typedef long long sint64

Calling/Return Convention

Examine the a, b, c, d, e variables in main, just after the call to the function func in line 16.

Iteration a b c d e
1st 0x000A 0x0009 0x0008 0x0007 0x0008
2nd 0x0010 0x000F 0x000E 0x000D 0x000E
3rd 0x0016 0x0015 0x0014 0x0013 0x0014
4th 0x001C 0x001B 0x001A 0x0019 0x001A
5th 0x0022 0x0021 0x0020 0x001F 0x0020

Parameter Value Sought
Starting address of func 0xC2C8
Ending address of func 0xC2FC
Register holding w R12
Register holding x R13
Register holding y R14
Register holding z R15
Register holding return value R12

What is the role of the extern directive in a .c file?

Declare without defining, it might be defined in another part of the program

What is the role of the .global directive in an .asm file (used in lines 28-32)?

So you can make symbol defined in one file and use it for/in others

##Lab Data

####Objectives There were three main objectives and 3 possible bonus objectives in this lab. ######Required Functionality

Create an "Etch-a-Sketch" on the MSP430 where the directional buttons control which direction the "brush" moves and the AUX button controls the brush's color (black or white).

Button Function
SW5/Up Move the cursor up 1 block
SW4/Down Move the cursor down 1 block
SW2/Left Move the cursor left 1 block
SW1/Right Move the cursor right 1 block
SW3/Aux Toggle the color of the paint brush

This functionality was accomplished with a small change in the following given code. The given code causes a block to be drawn on the screen and allows it to be moved around with the directional buttons.

while(1) {

	if (UP_BUTTON == 0) {
		while(UP_BUTTON == 0);
		if (y>=1) y=y-1;
		button_press = TRUE;
	} else if (DOWN_BUTTON == 0) {
		while(DOWN_BUTTON == 0);
		if (y<=6) y=y+1;
		button_press = TRUE;
	} else if (LEFT_BUTTON == 0) {
		while(LEFT_BUTTON == 0);
		if (x>=1) x=x-1;
		button_press = TRUE;
	} else if (RIGHT_BUTTON == 0) {
		while(RIGHT_BUTTON == 0);
		if (x<=10) x=x+1;
		button_press = TRUE;
	}
	if (button_press) {
		button_press = FALSE;
		clearDisplay();
		drawBlock(y,x);
	}
}

The key difference between the given code and the required funcitonality is the fact the the block gets cleared and redrawn with each button press, also the AUX button press is never detected. First, to get the paint brush functionality, the clear display in the if(button_press) was simply removed.

if (button_press) {
	button_press = FALSE;
	//clearDisplay();
	drawBlock(y,x);
}

Next, the more difficult part of the required functionality was utilizing the AUX button to change the color. This meant I had to change the asm file in addition to the C file, specifically the drawBlock function was changed to allow for the passing of a color true/false variable. In the asm drawBlock function R14 represented the "boolean" color variable and a jump was added to decide if 0xFF (black) or 0x00 (white) should be written as the color

	tst		R14
	jnz		drawBlack
	mov		#0x00, R13
continue:
	mov.w	#0x08, R5			; loop all 8 pixel columns
loopdB:
	call	#writeNokiaByte	
drawBlack:
	mov		#0xFF, R13
	jmp		continue

This completed the required functionality.

######B Functionality

The objective for B functionality was to create a moving block that bounced around the screen.

I began this functionality with my pong code from a past assignment here is the meat of the code

if(someBall->position.x >= SCREEN_WIDTH || someBall->position.x <= 0){
	someBall->velocity.x = -1*someBall->velocity.x;
}
if(someBall->position.y >= SCREEN_HEIGHT || someBall->position.y <= 0){
	someBall->velocity.y = -1*someBall->velocity.y;
}

someBall->position.x += someBall->velocity.x;
someBall->position.y += someBall->velocity.y;

this program simply increments the ball's x and y position based on a given velocity and detects wall hits.

My plan was to use the old code and implement it with the nokia.asm file to bounce the block around. To accomplish this I copied all of the files from the old pong code and added a clearDisplay and drawBlock call in pong's main.c file. The code in main looked as follows

while(1){
    moveBall(&myBall);
    clearDisplay();
    drawBlock(myBall.position.y, myBall.position.x, black);
    _delay_cycles(5333333);
}

Debugging: I had to add in the delay function to make the moving block visible It also took a few tries to get the size of the screen exactly right. Luckily my pong code worked really well so there wasn't too much work involved in implementing th LCD screen.

######A Functionality

The objective for A functionalty was to create and implementation of the pong game. My plan was to draw a bar as a paddle and edit the pong.c file to only bounce off the paddle on the left side of the screen. This was fairly straight-forward and I only had trouble making the bar large enough. Here is the code that I changed and added to get the paddle working. When the moving ball moves past the paddle the game end is signified by clearing the screen.

The buttons also had to be re-implemented to control the paddle (only in up daown direction) so some of the code from the required functionality was added back in.

I also had to pass the position of the paddle into the pong code so the ball would know when to bounce off the paddle.

I was able to partially complete A functionality, I could not get the paddle to change size!

######Bonus Functionality I was able to invert the colors by making a boolean color variable to be passed in which was similar to the paint brush toggle in the required functionality. The asm file had to be changed to allow for the new variable and jump accordingly. R14 was used for the new variable.

#######Lessons learned It is easy to go into coding with a plan and impelemnt the plan correctly but have your program not work becasue of little overlooked errors. I forgot to declare some global funcitons which took a while to figure out, I also didn't declare a new function properly at the beginning of a c file which was also hard. So advice to myself would be "learn C better"

Documentation: Dr. Coulston showed me what a .global was. I used my old pong code.

About

Pong msp430

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published