Mission Control Code for Interactive Alarm Clock
Dependencies: 4DGL-uLCD-SE mbed
Revision 0:02b0b24dedd1, committed 2015-12-10
- Comitter:
- tshin7
- Date:
- Thu Dec 10 08:59:21 2015 +0000
- Commit message:
- MissionControlForAlarm
Changed in this revision
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/.hg_archival.txt Thu Dec 10 08:59:21 2015 +0000 @@ -0,0 +1,5 @@ +repo: 532cb55d61363066c283e28fb8b5bb5eb002c762 +node: eba4ed0263a4c48bacbdc216154478a1ebd63a42 +branch: default +latesttag: null +latesttagdistance: 3
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/4DGL-uLCD-SE.lib Thu Dec 10 08:59:21 2015 +0000 @@ -0,0 +1,1 @@ +http://developer.mbed.org/users/4180_1/code/4DGL-uLCD-SE/#e39a44de229a
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/city_landscape/city_landscape.cpp Thu Dec 10 08:59:21 2015 +0000 @@ -0,0 +1,95 @@ +#include "city_landscape_private.h" + +CITY city_record[MAX_NUM_CITY]; +int building_height[NUM_BUILDING]; + +// See the comments in city_landscape_public.h +void city_landscape_init(int num_city) { + int i; + int city_distance = (SIZE_X-CITY_TO_SCREEN_MARGIN*2)/num_city; + + // All interface for user should have error checking + ASSERT_P(num_city<=MAX_NUM_CITY,ERROR_CITY_NUMBER); + + //initialize the record of cities + for(i=0;i<MAX_NUM_CITY;i++){ + if(i<num_city){ + // See the definition of CITY structure in city_landscape.h + city_record[i].y = REVERSE_Y(LANDSCAPE_HEIGHT)-1; + city_record[i].x = i*city_distance + CITY_TO_SCREEN_MARGIN; + city_record[i].width = CITY_WIDTH; // the width is fix number + city_record[i].height = MAX_BUILDING_HEIGHT; // the height is fix number + city_record[i].status = EXIST; + } + else{ + city_record[i].status = DESTROYED; + } + } + + //initialize the height of the buildings + srand(1); + for(i=0;i<NUM_BUILDING;i++){ + building_height[i] = (rand() % MAX_BUILDING_HEIGHT*2/3)+MAX_BUILDING_HEIGHT/3; + } + + //draw city landscape on the screen + draw_cities(); + draw_landscape(); + +} + +CITY city_get_info(int index){ + // All interface for user should have error checking + ASSERT_P(index<MAX_NUM_CITY,ERROR_CITY_INDEX_GET_INFO); + + return city_record[index]; +} + +void city_destroy(int index){ + int j; + int city_x, city_y, building_x, building_y; + int height; + + // error checking. the index must smaller than its max. + ASSERT_P(index<MAX_NUM_CITY,ERROR_CITY_INDEX_DESTROY); + + // remove the record + city_record[index].status = DESTROYED; + + // use the background color to cover the city + city_x = city_record[index].x; + city_y = city_record[index].y; + for(j=0;j<NUM_BUILDING;j++){ + building_x = city_x+j*BUILDING_WIDTH; + building_y = city_y; + height = building_y-building_height[j]+1; + uLCD.filled_rectangle(building_x, building_y, building_x+BUILDING_WIDTH-1, height, BACKGROUND_COLOR); + } +} + +void draw_cities(void){ + int i,j; + int city_x, city_y, building_x, building_y; + int height; + + for(i=0;i<MAX_NUM_CITY;i++){ + + // draw each city + if(city_record[i].status==EXIST){ + city_x = city_record[i].x; + city_y = city_record[i].y; + + // draw each building + for(j=0;j<NUM_BUILDING;j++){ + building_x = city_x+j*BUILDING_WIDTH; + building_y = city_y; + height = building_y-building_height[j]+1; + uLCD.filled_rectangle(building_x, building_y, building_x+BUILDING_WIDTH-1, height, BUILDING_COLOR); + } + } + } +} + +void draw_landscape(void){ + uLCD.filled_rectangle(0, SIZE_Y-1, SIZE_X-1, REVERSE_Y(LANDSCAPE_HEIGHT), LANDSCAPE_COLOR); +} \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/city_landscape/city_landscape_private.h Thu Dec 10 08:59:21 2015 +0000 @@ -0,0 +1,39 @@ +#ifndef CITY_LANDSCAPE_PRIVATE_H +#define CITY_LANDSCAPE_PRIVATE_H + +#include "mbed.h" +#include "uLCD_4DGL.h" +#include "globals.h" +#include "city_landscape_public.h" + +//==== [private type] ==== +// N/A + + + +//==== [private function] ==== +// N/A + + + +//==== [private macros] ==== +// The bottom of the screen => y=127 +// Gut the landscape grow up from the bottom of the screen. It is awkward. +// Thus, we use a macro to reverse the coordinate for convenience. +#define REVERSE_Y(x) (SIZE_Y-(x)) + +//==== [private settings] ==== +// You could modify these settings, but try to keep them be used only inside city_landscape.cpp +// Here are the settings to define the looking of your city landscape +#define CITY_TO_SCREEN_MARGIN 25 // pixel on the screen +#define CITY_WIDTH 10 // pixel on the screen +#define BUILDING_WIDTH 2 // pixel on the screen +#define NUM_BUILDING (CITY_WIDTH/BUILDING_WIDTH) +#define BUILDING_COLOR 0x00FF00 +#define LANDSCAPE_COLOR 0xCCAA00 + + + + + +#endif //CITY_LANDSCAPE_PRIVATE_H \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/city_landscape/city_landscape_public.h Thu Dec 10 08:59:21 2015 +0000 @@ -0,0 +1,49 @@ +#ifndef CITY_LANDSCAPE_PUBLIC_H +#define CITY_LANDSCAPE_PUBLIC_H + +/// The enum define the status of a city +typedef enum { + EXIST=1, ///< The city will be shown on screen + DESTROYED=0 ///< The city won't be shown on screen +} CITY_STATUS; + +/// The structure to store the information of a city +typedef struct { + int x; ///< Bottom-left corner of the city. x coordinate on the screen. + int y; ///< Bottom-left corner of the city. y coordinate on the screen. + int width; ///< The width of the city. The shape of the city is an rectangle. + int height; ///< The height of the city + CITY_STATUS status; ///< See enum CITY_STATUS +} CITY; + +#define MAX_NUM_CITY 6 + +/** Call city_landscape_init() once at the begining of your code + @brief It initialize the city data structure and draw the cities. + @param num_city number of city to be draw. It must be less/equal to MAX_NUM_CITY. +*/ +void city_landscape_init(int num_city); + +/** Get the information of city + @param index The index in city_record. It must be smaller than MAX_NUM_CITY. + @return The structure of city information +*/ +CITY city_get_info(int index); + +/** Remove the city from its record and the screen + @param index The index in city_record. It must be smaller than MAX_NUM_CITY. +*/ +void city_destroy(int index); + +/** Draw all exist cities on the screen + @brief You might not need to use this function, but you could still use it if you want. +*/ +void draw_cities(void); + +/** Draw the landscape + @brief You might not need to use this function, but you could still use it if you want. +*/ +void draw_landscape(void); + + +#endif //CITY_LANDSCAPE_H \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/globals.h Thu Dec 10 08:59:21 2015 +0000 @@ -0,0 +1,35 @@ +#ifndef GLOBAL_H +#define GLOBAL_H + +// === [global object] === +extern uLCD_4DGL uLCD; + + +// === [global settings] === +#define BACKGROUND_COLOR 0x000000 //black +#define LANDSCAPE_HEIGHT 4 // number of pixel on the screen +#define MAX_BUILDING_HEIGHT 10 // number of pixel on the screen + + +// === [define the macro of error heandle function] === +// when the condition (c) is not true, assert the program and show error code +#define ASSERT_P(c,e) do { \ + if(!(c)){ \ + uLCD.printf("\nERROR:%d\n",e); \ + while(1); \ + } \ +} while (0) + + +// === [error code] === +#define ERROR_MISSILE_INDEX_GET_INFO -1 // make sure your code give the valid index for missile_get_info() +#define ERROR_MISSILE_INDEX_UPDATE_STATUS -2 // make sure your code give the valid index for missile_update_status() +#define ERROR_MISSILE_SPEED -3 // missile speed has to be between 1 and 8 +#define ERROR_MISSILE_INTERVAL -4 // missile interval has to be between 1 and 100 +// other missile error code ... +#define ERROR_CITY_NUMBER -11 // num_city in city_landscape_init() is larger than MAX_NUM_CITY +#define ERROR_CITY_INDEX_GET_INFO -12 // make sure your code give the valid index for city_get_info() +#define ERROR_CITY_INDEX_DESTROY -13 // make sure your code give the valid index for city_destroy() +// other player-missile error code ... + +#endif //GLOBAL_H \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Thu Dec 10 08:59:21 2015 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed/builds/cb3d968589d8 \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/missile/missile.cpp Thu Dec 10 08:59:21 2015 +0000 @@ -0,0 +1,121 @@ +#include "missile_private.h" + +MISSILE missile_record[MAX_NUM_MISSILE]; +int missile_tick=0; +int missile_interval = 10; +int missile_speed = 4; + +// See the comments in missile_public.h +void missile_generator(void){ + missile_tick++; + // only fire the missile at certain ticks + if((missile_tick % missile_interval)==0 || missile_tick==0){ + missile_create(); + } + + // update the missiles and draw them + missile_update_position(); +} + +// set missile speed (default speed is 4) +void set_missile_speed(int speed){ + ASSERT_P(speed>=1 && speed<=8,ERROR_MISSILE_SPEED); + if(speed>=1 && speed<=8){ + missile_speed = speed; + } +} + +// set missile interval (default interval is 10) +void set_missile_interval(int interval){ + ASSERT_P(interval>=1 && interval<=100,ERROR_MISSILE_INTERVAL); + if(interval>=1 && interval<=100){ + missile_interval = interval; + } +} + +// See the comments in missile_public.h +MISSILE missile_get_info(int index){ + // All interface for user should have error checking + ASSERT_P(index<MAX_NUM_MISSILE,ERROR_MISSILE_INDEX_GET_INFO); + + return missile_record[index]; +} + +// See the comments in missile_public.h +void missile_set_exploded(int index){ + // All interface for user should have error checking + ASSERT_P(index<MAX_NUM_MISSILE,ERROR_MISSILE_INDEX_UPDATE_STATUS); + + missile_record[index].status = MISSILE_EXPLODED; +} + +/** This function finds an empty slot of missile record, and active it. +*/ +void missile_create(void){ + int i; + for(i=0;i<MAX_NUM_MISSILE;i++){ + if(missile_record[i].status == MISSILE_DEACTIVE){ + missile_record[i].y = 0; + //each missile has its own tick + missile_record[i].tick = 0; + //set a random source for the missile + missile_record[i].source_x = rand() % SIZE_X; + //set a random target for the missile + missile_record[i].target_x = rand() % SIZE_X; + //the missile starts at its source + missile_record[i].x = missile_record[i].source_x; + missile_record[i].status = MISSILE_ACTIVE; + break; + } + } +} + +/** This function update the position of all missiles and draw them +*/ +void missile_update_position(void){ + int i; + //controls how fast the missile will move + int rate = missile_speed * 25; + //delta_x and delta_y account for the slope of the missile + double delta_x,delta_y; + for(i=0;i<MAX_NUM_MISSILE;i++){ + if(missile_record[i].status == MISSILE_ACTIVE){ + // update missile position + delta_y = 200/rate; + delta_x = (missile_record[i].target_x - missile_record[i].source_x)/rate; + missile_draw(missile_record[i], BACKGROUND_COLOR); + missile_record[i].y = (int)(delta_y*(missile_record[i].tick%rate)); + missile_record[i].x = (int)(missile_record[i].source_x + delta_x*(missile_record[i].tick%rate)); + // draw missile + missile_draw(missile_record[i], MISSILE_COLOR); + //update missile's internal tick + missile_record[i].tick++; + } + else if(missile_record[i].status == MISSILE_EXPLODED){ + // clear the missile on the screen + missile_draw(missile_record[i], BACKGROUND_COLOR); + + // we have done with this missile, remove it from record + missile_record[i].status = MISSILE_DEACTIVE; + //resets the missile's internal tick + missile_record[i].tick = 0; + } + + } +} + +/** This function draw a missile. + @param missile The missile to be drawn + @param color The color of the missile +*/ +void missile_draw(MISSILE missile, int color){ + int init_x,init_y,current_x,current_y; + + init_x = missile.source_x; + init_y = 0; + current_x = missile.x; + current_y = missile.y; + uLCD.line(init_x, init_y, current_x, current_y, color); +} + +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/missile/missile_private.h Thu Dec 10 08:59:21 2015 +0000 @@ -0,0 +1,22 @@ +#ifndef MISSILE_PRIVATE_H +#define MISSILE_PRIVATE_H + +#include "mbed.h" +#include "uLCD_4DGL.h" +#include "globals.h" +#include "missile_public.h" + +//==== [private settings] ==== +#define MISSILE_COLOR 0xFF0000 + +//==== [private type] ==== + + +//==== [private function] ==== +void missile_create(void); +void missile_update_position(void); +void missile_draw(MISSILE missile, int color); + +#endif //MISSILE_PRIVATE_H + +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/missile/missile_public.h Thu Dec 10 08:59:21 2015 +0000 @@ -0,0 +1,51 @@ +#ifndef MISSILE_PUBLIC_H +#define MISSILE_PUBLIC_H + +///The missile status +typedef enum { + MISSILE_EXPLODED=2,///<missile has been destroyed + MISSILE_ACTIVE=1,///<missile is active + MISSILE_DEACTIVE=0///<missile is no longer active +} MISSILE_STATUS; + + +/// The structure to store the information of a missile +typedef struct { + int x; ///< The x-coordinate of missile current position + int y; ///< The y-coordinate of missile current position + double source_x; ///< The x-coordinate of the missile's origin + double target_x; ///< The x-coordinate of the missile's target + int tick; ///< The missile's internal tick + MISSILE_STATUS status; ///< The missile status, see MISSILE_STATUS +} MISSILE; + +#define MAX_NUM_MISSILE 5 + +/** This function draw the missiles onto the screen + Call missile_generator() repeatedly in your game-loop. ex: main() +*/ +void missile_generator(void); + +/** The function set the status of missile to be MISSILE_EXPLODED + @param index The index in missile_record. It must be smaller than MAX_NUM_MISSILE. +*/ +void missile_set_exploded(int index); + +/** Get the information of a missile + @param index The index in missile_record. It must be smaller than MAX_NUM_MISSILE. + @return The structure of missile information +*/ +MISSILE missile_get_info(int index); + +/** Set the speed of missiles, Speed has range of 1-8 with 1 being fastest and 8 being slowest +*/ +void set_missile_speed(int speed); + +/** Set the interval that the missiles fire, interval has range of 1-100 with 1 being fired in + very quick succession and 100 being fired very slowly after one another +*/ +void set_missile_interval(int interval); + +void missile_draw(MISSILE missile, int color); + +#endif //MISSILE_PUBLIC_H \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/missionControl.cpp Thu Dec 10 08:59:21 2015 +0000 @@ -0,0 +1,231 @@ +#include "mbed.h" +#include "uLCD_4DGL.h" +#include "segment_display.h" +// Include header files for missile command project +#include "globals.h" +#include "city_landscape_public.h" +#include "missile_public.h" +#include "player.h" +// Platform initialization +Serial pc(USBTX,USBRX); +DigitalIn left_pb(p23); +DigitalIn right_pb(p21); +DigitalIn fire_pb(p22); +DigitalIn gameOn(p19); +DigitalOut gameWin(p20); +uLCD_4DGL uLCD(p28,p27,p29); +//Initialize variables +PLAYER_MISSILE missileArr [5]; +PLAYER player; +int radius = 10; +int missileCount = 5; +int d, w, l; +int s = 0; +int cityCount = 4; +int lives = 3; +//draw the anti missile +void player_missile_draw(PLAYER_MISSILE missile, int color) +{ + int init_x, init_y, current_x, current_y; + init_x = missile.source_x; + init_y = 96; + current_x = init_x; + current_y = missile.y; + uLCD.line(init_x, init_y, current_x, current_y, color); +} +// create the anti missile +void player_missile_create(void) +{ + int z; + for(z=0; z<5; z++) { + if(missileArr[z].status == PLAYER_MISSILE_DEACTIVE) { + missileArr[z].y = 96; + //each missile has its own tick + + //set a random source for the missile + missileArr[z].source_x = player.x + 5; + //set a random target for the missile + missileArr[z].origin_y = 96; + //the missile starts at its source + + missileArr[z].status = PLAYER_MISSILE_ACTIVE; + break; + } + } +} + +void player_missile_update_position(void) +{ + int b; + //controls how fast the missile will move + //delta_x and delta_y account for the slope of the missile + double delta_y; + for(b=0; b<5; b++) { + if(missileArr[b].status == PLAYER_MISSILE_ACTIVE) { + // update missile position + delta_y = 5; + missileArr[b].y = missileArr[b].y - delta_y; + // draw missile + player_missile_draw(missileArr[b], PLAYER_COLOR); + } + if(missileArr[b].y < 0) { + player_missile_draw(missileArr[b], BLACK_COLOR ); + missileArr[b].status = PLAYER_MISSILE_DEACTIVE; + } else if(missileArr[b].status == PLAYER_MISSILE_EXPLODED) { + // clear the missile on the screen + player_missile_draw(missileArr[b], BLACK_COLOR); + // we have done with this missile, remove it from record + missileArr[b].status = PLAYER_MISSILE_DEACTIVE; + //resets the missile's internal tick + missileCount = missileCount + 1; + } + } +} + +void player_set_exploded(int index) +{ + // Error check + ASSERT_P(index<MAX_NUM_MISSILE,ERROR_MISSILE_INDEX_UPDATE_STATUS); + + missileArr[index].status = PLAYER_MISSILE_EXPLODED; + missileCount = missileCount + 1; +} + + +int main() +{ + gameWin = false; + uLCD.locate(0, 0); + //uLCD.printf("Lvl:", level()); + //uLCD.printf("Score: %2d", s); + //uLCD.prinf("Missiles: ", + //uLCD.printf("Lives: ", + setup_sequence(); + seg_driver_initialize(); + // 2.show numbers + int i; + for(i=0; i<10; i++) { + seg_driver(i); + wait(0.2); + } + // Draw cities + city_landscape_init(4); + // Initialize the buttons + left_pb.mode(PullUp); // The variable left_pb will be zero when the pushbutton for moving the player left is pressed + right_pb.mode(PullUp); // The variable rightt_pb will be zero when the pushbutton for moving the player right is pressed + fire_pb.mode(PullUp); //the variable fire_pb will be zero when the pushbutton for firing a missile is pressed + + ///Begin the game loop + + player.x = 60; + player_draw(player.x,100); + while(1) { + if (gameOn==true) { + //print Score and Lives + uLCD.locate(0,0); + uLCD.color(0x00FF00); + uLCD.printf("Score: %2d \n", s); + uLCD.printf("Lives: %2d" , lives); + + missileCount = 5; + for(l = 0; l<5; l++) { + if(missileArr[l].status == PLAYER_MISSILE_ACTIVE) { + missileCount = missileCount - 1; + } + seg_driver(missileCount); + } + missile_generator(); /// updates all incoming missiles on the screen + if(left_pb == 0 && player.x>0) { + //Move player left + player_draw(player.x,100); + player_delete(player.x,100); + player.x = player.x - 10; + player_draw(player.x,100); + } + if(right_pb == 0 && player.x<110) { + //Move player right + player_draw(player.x,100); + player_delete(player.x,100); + player.x = player.x + 10; + player_draw(player.x,100); + } + if(fire_pb == 0) { + player_missile_create(); + } + player_missile_update_position(); + //missile-player collision + for ( int p=0; p<5; p++) { + MISSILE missile_record = missile_get_info(p); + int q,w, r, t; + q = player.x + 10; + w = 100; + r = player.x; + t = 96; + if((missile_record.x > r & missile_record.x<q) & (missile_record.y<w & missile_record.y>t & (missile_record.status==MISSILE_ACTIVE))) { + lives -= 1; + missile_set_exploded(p); + wait(1); + if(lives == 0) { + gameover(s); + break; + } + for(int j=0; j<11; j=j+3) { + uLCD.circle(missile_record.x, missile_record.y, j, YELLOW_COLOR); + uLCD.circle(missile_record.x, missile_record.y, j, BLACK_COLOR); + } + } + } + //missile-city collision + for ( int e=0; e<5; e++) { + MISSILE missile_record = missile_get_info(e); + for (int d = 0; d<5; d++) { + CITY city_record = city_get_info(d); + int f, g, h, i; + f = city_record.x + city_record.width; + g = city_record.y - city_record.height; + h = city_record.x; + i = city_record.y; + if((missile_record.x > h & missile_record.x<f) & (missile_record.y<i & missile_record.y>g) & (city_record.status == EXIST)) { + for(int j=0; j<11; j=j+3) { + uLCD.circle(missile_record.x, missile_record.y, j, YELLOW_COLOR); + uLCD.circle(missile_record.x, missile_record.y, j, BLACK_COLOR); + } + missile_set_exploded(e); + city_destroy(d); + cityCount = cityCount -1; + if(cityCount == 0) { + gameover(s); + } + break; + } + } + } + //missile-player_missile collision + for(d=0; d<5; d++) { + for(w=0; w<5; w++) { + MISSILE missile_record = missile_get_info(w); + double f; + f = (int)sqrt(pow((double)(missile_record.x-missileArr[d].source_x),2.0) + pow((double)(missile_record.y-missileArr[d].y),2.0)); + + if((f<radius) && (missile_record.status == MISSILE_ACTIVE) && (missileArr[d].status== PLAYER_MISSILE_ACTIVE)) { + for (int j=0; j< (radius+1); j = j+3) { + uLCD.circle(missile_record.x, missile_record.y, j, 0xFFFF00); + + } + for (int j=0; j<(radius+1); j=j+3) { + uLCD.circle(missile_record.x, missile_record.y, j, BLACK_COLOR); + + } + missile_set_exploded(w); + + player_set_exploded(d); + s= s+1; + if(s==3) { + gameWin = true; + } + } + } + } + } + } +} \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/player.cpp Thu Dec 10 08:59:21 2015 +0000 @@ -0,0 +1,54 @@ +#include "mbed.h" +#include "uLCD_4DGL.h" +#include "globals.h" +#include "player.h" + +//Initialize antimissile status +PLAYER_MISSILE_STATUS status; + + + + + +//Function to draw the player +void player_draw(int x, int y) { + uLCD.filled_rectangle(x, y, x+PLAYER_WIDTH, y+PLAYER_HEIGHT, 0xFFA500); + uLCD.filled_rectangle(x+PLAYER_DELTA, y-PLAYER_DELTA, x+PLAYER_WIDTH-PLAYER_DELTA, y+PLAYER_HEIGHT, 0xFF0000); + uLCD.filled_rectangle(x,y, x+PLAYER_WIDTH/4, y+2+PLAYER_HEIGHT, 0xFFA500); + uLCD.filled_rectangle(x+8, y, x+PLAYER_WIDTH, y+2+PLAYER_HEIGHT, 0xFFA500); +} + +//Function to delete player +void player_delete(int x, int y) { + uLCD.filled_rectangle(x, y, x+PLAYER_WIDTH, y+PLAYER_HEIGHT, BLACK_COLOR); + uLCD.filled_rectangle(x+PLAYER_DELTA, y-PLAYER_DELTA, x+PLAYER_WIDTH-PLAYER_DELTA, y+PLAYER_HEIGHT, BLACK_COLOR); + uLCD.filled_rectangle(x,y, x+PLAYER_WIDTH/4, y+2+PLAYER_HEIGHT, BLACK_COLOR); + uLCD.filled_rectangle(x+8, y, x+PLAYER_WIDTH, y+2+PLAYER_HEIGHT, BLACK_COLOR); +} + + +void gameover(int s) { + + while(1) { + uLCD.filled_rectangle(0, 0, 128, 128, 0x000000); + uLCD.locate(4, 5); + uLCD.printf("GAME OVER \n \n"); + uLCD.printf("YOUR SCORE WAS:%2d",s); + wait(1); + } + + } + + + + + + + + + + + + + +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/player.h Thu Dec 10 08:59:21 2015 +0000 @@ -0,0 +1,50 @@ +// Template of player header file +#ifndef PLAYER_H +#define PLAYER_H + +// Player settings +#define PLAYER_WIDTH 10 +#define PLAYER_HEIGHT 3 +#define PLAYER_DELTA 3 +#define PLAYER_COLOR 0x0000FF +#define BLACK_COLOR 0x000000 +#define YELLOW_COLOR 0xFFFF00 +#define GREEN_COLOR 0x00FF00 + + + + +typedef enum { + PLAYER_MISSILE_EXPLODED=2,///<missile has been destroyed + PLAYER_MISSILE_ACTIVE=1,///<missile is active + PLAYER_MISSILE_DEACTIVE=0///<missile is no longer active +} PLAYER_MISSILE_STATUS; +//Initialize ANTI-missile structure + +typedef struct { + int x; + int origin_y; ///< The x-coordinate of missile current position + int y; ///< The y-coordinate of missile current position + int source_x; + int source_y; + PLAYER_MISSILE_STATUS status; ///< The missile status, see MISSILE_STATUS + +} PLAYER_MISSILE; +//Initialize PLAYER structure +typedef struct { + int x; + int y; + int numMissile; + int lives; + + + } PLAYER; +//Declare functions +void player_missile_draw(PLAYER_MISSILE player_missile, int color); +void player_draw(int x, int y); +void player_delete(int x, int y); +void missile_start(int counter); +void player_set_exploded(int index); +void gameover(int s); + +#endif //PLAYER_H \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/segment_display/dig_out.s Thu Dec 10 08:59:21 2015 +0000 @@ -0,0 +1,332 @@ + AREA dig_out, CODE, READONLY +;--------------------OVERVIEW------------------------ +; This file contains ARM Assembly language functions to set +; designated pins to General Purpose Output. It uses +; the PINSELx Register to Set the Pin Function to GPIO. +; Then, it uses the FIOxDIR register to set the +; direction of the pin to output. It also contains functions +; to write a digital HIGH or LOW to these output pins. It uses +; the FIOxCLR AND FIOxSET registers to clear/set the +; port bits respectively. Refer to the Pinnames.h +; file to see which LPC1768 pins a given mbed module is +; connected to. Then, refer to Chapters 8 and 9 of the +; LPC1768 User Manual to acquire information on the GPIO +; registers and their addresses. +; +; Example: +; LED1 is on GPIO port 1 bit 18 according to Pinnames.h +; For this bit: -the PINSEL3 register determines its pin function +; -the FIO1DIR register determines its pin direction +; According to the LPC1768 User Manual: -PINSEL3 is located at 0x4002C00C +; -FIO1DIR is located at 0x2009C020 +; Now refer to the dig_out_LED1 function below to see the execution +;------------------------------------------------------ +; +; EXPORT FUNCTION LOCATION SO THAT C-COMPILER CAN LINK + EXPORT dig_out_LED1 +dig_out_LED1 +;========dig_out_LED1======== +; LED1 LOCATED AT PORT-1 PIN-18 + LDR R0, =0x4002C00C ; LOAD ADDRESS OF PINSEL3 REGISTER + MOV.W R1, #0x00040000 ; MOVE BIT MASK (FOR BIT 18) INTO TEMP REGISTER (0x40000 = 0x01 << 18) +; ; NOTE: THE ABOVE IS A 32-BIT INSTRUCTION BC OF ".W" QUALIFIER + LDR R2, =0x2009C020 ; LOAD ADDRESS OF FIO1DIR REGISTER + MOV R3, #0x30 ; FORM BITMASK FOR PINSEL3 REGISTER (clear appropriate bits) + B dig_out_exec ; CALL SUBROUTINE TO EXECUTE YOUR CHANGES +; +; +; +; EXPORT FUNCTION LOCATION SO THAT C-COMPILER CAN LINK + EXPORT LED1_write +LED1_write +;========LED1_write========= +; LED1 LOCATED AT PORT-1 PIN-18 + LDR R1, =0x2009C020 ; LOAD ADDRESS OF FIO1DIR (PORT 1 BASE REGISTER) + MOV.W R2, #0x040000 ; MOVE BIT MASK (FOR BIT 18) INTO TEMP REGISTER (0x40000 = 0x01 << 18) + B write_exec ; CALL SUBROUTINE TO EXECUTE YOUR CHANGES +; +; +; +; EXPORT FUNCTION LOCATION SO THAT C-COMPILER CAN LINK + EXPORT dig_out_LED2 +dig_out_LED2 +;========dig_out_LED2======== +; LED2 LOCATED AT PORT-1 PIN-20 + LDR R0, =0x4002C00C ; LOAD ADDRESS OF PINSEL3 REGISTER + LDR R1, =0x00100000 ; MOVE BIT MASK (FOR BIT 20) INTO TEMP REGISTER (0x100000 = 0x01 << 20) + LDR R2, =0x2009C020 ; LOAD ADDRESS OF FIO1DIR REGISTER + MOV.W R3, #0x300 ; FORM BITMASK FOR PINSEL3 REGISTER (clear appropriate bits) +; ; NOTE: THE ABOVE IS A 32-BIT INSTRUCTION BC OF ".W" QUALIFIER + B dig_out_exec ; CALL SUBROUTINE TO EXECUTE YOUR CHANGES +; +; +; +; EXPORT FUNCTION LOCATION SO THAT C-COMPILER CAN LINK + EXPORT LED2_write +LED2_write +;========LED2_write========= +; LED2 LOCATED AT PORT-1 PIN-20 + LDR R1, =0x2009C020 ; LOAD ADDRESS OF FIO1DIR (PORT 1 BASE REGISTER) + LDR R2, =0x0100000 ; MOVE BIT MASK (FOR BIT 20) INTO TEMP REGISTER (0x100000 = 0x01 << 20) + B write_exec ; CALL SUBROUTINE TO EXECUTE YOUR CHANGES +; +; +; +; EXPORT FUNCTION LOCATION SO THAT C-COMPILER CAN LINK + EXPORT dig_out_LED3 +dig_out_LED3 +;========dig_out_LED3======== +; LED3 LOCATED AT PORT-1 PIN-21 + LDR R0, =0x4002C00C ; LOAD ADDRESS OF PINSEL3 REGISTER + LDR R1, =0x00200000 ; MOVE BIT MASK (FOR BIT 21) INTO TEMP REGISTER (0x200000 = 0x01 << 21) + LDR R2, =0x2009C020 ; LOAD ADDRESS OF FIO1DIR REGISTER + MOV.W R3, #0xC00 ; FORM BITMASK FOR PINSEL3 REGISTER (clear appropriate bits) +; ; NOTE: THE ABOVE IS A 32-BIT INSTRUCTION BC OF ".W" QUALIFIER + B dig_out_exec ; CALL SUBROUTINE TO EXECUTE YOUR CHANGES +; +; +; +; EXPORT FUNCTION LOCATION SO THAT C-COMPILER CAN LINK + EXPORT LED3_write +LED3_write +;========LED3_write========= +; LED3 LOCATED AT PORT-1 PIN-21 + LDR R1, =0x2009C020 ; LOAD ADDRESS OF FIO1DIR (PORT 1 BASE REGISTER) + LDR R2, =0x0200000 ; MOVE BIT MASK (FOR BIT 21) INTO TEMP REGISTER (0x200000 = 0x01 << 21) + B write_exec ; CALL SUBROUTINE TO EXECUTE YOUR CHANGES +; +; +; +; EXPORT FUNCTION LOCATION SO THAT C-COMPILER CAN LINK + EXPORT dig_out_LED4 +dig_out_LED4 +;========dig_out_LED4======== +; LED4 LOCATED AT PORT-1 PIN-23 + LDR R0, =0x4002C00C ; LOAD ADDRESS OF PINSEL3 REGISTER + LDR R1, =0x00800000 ; MOVE BIT MASK (FOR BIT 23) INTO TEMP REGISTER (0x800000 = 0x01 << 23) + LDR R2, =0x2009C020 ; LOAD ADDRESS OF FIO1DIR REGISTER + MOV.W R3, #0xC000 ; FORM BITMASK FOR PINSEL3 REGISTER (clear appropriate bits) +; ; NOTE: THE ABOVE IS A 32-BIT INSTRUCTION BC OF ".W" QUALIFIER + B dig_out_exec ; CALL SUBROUTINE TO EXECUTE YOUR CHANGES +; +; +; +; EXPORT FUNCTION LOCATION SO THAT C-COMPILER CAN LINK + EXPORT LED4_write +LED4_write +;========LED4_write========= +; LED4 LOCATED AT PORT-1 PIN-23 + LDR R1, =0x2009C020 ; LOAD ADDRESS OF FIO1DIR (PORT 1 BASE REGISTER) + LDR R2, =0x0800000 ; MOVE BIT MASK (FOR BIT 21) INTO TEMP REGISTER (0x800000 = 0x01 << 23) + B write_exec ; CALL SUBROUTINE TO EXECUTE YOUR CHANGES +; +; +; +; EXPORT FUNCTION LOCATION SO THAT C-COMPILER CAN LINK + EXPORT dig_out_P11 +dig_out_P11 +;========dig_out_P11======== +; P11 LOCATED AT PORT-0 PIN-18 + LDR R0, =0x4002C004 ; LOAD ADDRESS OF PINSEL1 REGISTER + MOV.W R1, #0x00040000 ; MOVE BIT MASK (FOR BIT 18) INTO TEMP REGISTER (0x40000 = 0x01 << 18) +; ; NOTE: THE ABOVE IS A 32-BIT INSTRUCTION BC OF ".W" QUALIFIER + LDR R2, =0x2009C000 ; LOAD ADDRESS OF FIO0DIR0 REGISTER + MOV R3, #0x30 ; FORM BITMASK FOR PINSEL1 REGISTER (clear appropriate bits) + B dig_out_exec ; CALL SUBROUTINE TO EXECUTE YOUR CHANGES +; +; +; +; EXPORT FUNCTION LOCATION SO THAT C-COMPILER CAN LINK + EXPORT P11_write +P11_write +;========P11_write========= +; P11 LOCATED AT PORT-0 PIN-18 + LDR R1, =0x2009C000 ; LOAD ADDRESS OF FIO0DIR0 (PORT 0 BASE REGISTER) + MOV.W R2, #0x040000 ; MOVE BIT MASK (FOR BIT 18) INTO TEMP REGISTER (0x40000 = 0x01 << 18) + B write_exec ; CALL SUBROUTINE TO EXECUTE YOUR CHANGES +; +; +; +; EXPORT FUNCTION LOCATION SO THAT C-COMPILER CAN LINK + EXPORT dig_out_P12 +dig_out_P12 +;========dig_out_P12======== +; P12 LOCATED AT PORT-0 PIN-17 + LDR R0, =0x4002C004 ; LOAD ADDRESS OF PINSEL1 REGISTER + MOV.W R1, #0x00020000 ; MOVE BIT MASK (FOR BIT 17) INTO TEMP REGISTER (0x40000 = 0x01 << 18) +; ; NOTE: THE ABOVE IS A 32-BIT INSTRUCTION BC OF ".W" QUALIFIER + LDR R2, =0x2009C000 ; LOAD ADDRESS OF FIO0DIR0 REGISTER + MOV R3, #0xC ; FORM BITMASK FOR PINSEL1 REGISTER (clear appropriate bits) + B dig_out_exec ; CALL SUBROUTINE TO EXECUTE YOUR CHANGES +; +; +; +; EXPORT FUNCTION LOCATION SO THAT C-COMPILER CAN LINK + EXPORT P12_write +P12_write +;========P12_write========= +; P12 LOCATED AT PORT-0 PIN-17 + LDR R1, =0x2009C000 ; LOAD ADDRESS OF FIO0DIR0 (PORT 0 BASE REGISTER) + MOV.W R2, #0x020000 ; MOVE BIT MASK (FOR BIT 17) INTO TEMP REGISTER (0x40000 = 0x01 << 18) + B write_exec ; CALL SUBROUTINE TO EXECUTE YOUR CHANGES +; +; +; EXPORT FUNCTION LOCATION SO THAT C-COMPILER CAN LINK + EXPORT dig_out_P13 +dig_out_P13 +;========dig_out_P13======== +; P13 LOCATED AT PORT-0 PIN-15 + LDR R0, =0x4002C000 ; LOAD ADDRESS OF PINSEL0 REGISTER + MOV.W R1, #0x00008000 ; MOVE BIT MASK (FOR BIT 15) INTO TEMP REGISTER (0x08000 = 0x01 << 15) +; ; NOTE: THE ABOVE IS A 32-BIT INSTRUCTION BC OF ".W" QUALIFIER + LDR R2, =0x2009C000 ; LOAD ADDRESS OF FIO0DIR0 REGISTER + LDR R3, =0x70000000 ; FORM BITMASK FOR PINSEL0 REGISTER (clear appropriate bits) + B dig_out_exec ; CALL SUBROUTINE TO EXECUTE YOUR CHANGES +; +; +; +; EXPORT FUNCTION LOCATION SO THAT C-COMPILER CAN LINK + EXPORT P13_write +P13_write +;========P13_write========= +; P13 LOCATED AT PORT-0 PIN-15 + LDR R1, =0x2009C000 ; LOAD ADDRESS OF FIO0DIR0 (PORT 0 BASE REGISTER) + MOV.W R2, #0x008000 ; MOVE BIT MASK (FOR BIT 15) INTO TEMP REGISTER (0x08000 = 0x01 << 15) + B write_exec ; CALL SUBROUTINE TO EXECUTE YOUR CHANGES +; +; +; +; EXPORT FUNCTION LOCATION SO THAT C-COMPILER CAN LINK + EXPORT dig_out_P14 +dig_out_P14 +;========dig_out_P14======== +; P14 LOCATED AT PORT-0 PIN-16 + LDR R0, =0x4002C004 ; LOAD ADDRESS OF PINSEL1 REGISTER + MOV.W R1, #0x00010000 ; MOVE BIT MASK (FOR BIT 16) INTO TEMP REGISTER (0x10000 = 0x01 << 16) +; ; NOTE: THE ABOVE IS A 32-BIT INSTRUCTION BC OF ".W" QUALIFIER + LDR R2, =0x2009C000 ; LOAD ADDRESS OF FIO0DIR0 REGISTER + MOV R3, #0x03 ; FORM BITMASK FOR PINSEL0 REGISTER (clear appropriate bits) + B dig_out_exec ; CALL SUBROUTINE TO EXECUTE YOUR CHANGES +; +; +; +; EXPORT FUNCTION LOCATION SO THAT C-COMPILER CAN LINK + EXPORT P14_write +P14_write +;========P14_write========= +; P14 LOCATED AT PORT-0 PIN-16 + LDR R1, =0x2009C000 ; LOAD ADDRESS OF FIO0DIR0 (PORT 0 BASE REGISTER) + MOV.W R2, #0x010000 ; MOVE BIT MASK (FOR BIT 16) INTO TEMP REGISTER (0x10000 = 0x01 << 16) + B write_exec ; CALL SUBROUTINE TO EXECUTE YOUR CHANGES +; +; +; +; EXPORT FUNCTION LOCATION SO THAT C-COMPILER CAN LINK + EXPORT dig_out_P15 +dig_out_P15 +;========dig_out_P15======== +; P15 LOCATED AT PORT-0 PIN-23 + LDR R0, =0x4002C004 ; LOAD ADDRESS OF PINSEL1 REGISTER + LDR R1, =0x00800000 ; MOVE BIT MASK (FOR BIT 23) INTO TEMP REGISTER (0x800000 = 0x01 << 23) + LDR R2, =0x2009C000 ; LOAD ADDRESS OF FIO0DIR0 REGISTER + MOV.W R3, #0x7000 ; FORM BITMASK FOR PINSEL1 REGISTER (clear appropriate bits) +; ; NOTE: THE ABOVE IS A 32-BIT INSTRUCTION BC OF ".W" QUALIFIER + B dig_out_exec ; CALL SUBROUTINE TO EXECUTE YOUR CHANGES +; +; +; +; EXPORT FUNCTION LOCATION SO THAT C-COMPILER CAN LINK + EXPORT P15_write +P15_write +;========P15_write========= +; P15 LOCATED AT PORT-0 PIN-23 + LDR R1, =0x2009C000 ; LOAD ADDRESS OF FIO0DIR0 (PORT 0 BASE REGISTER) + MOV.W R2, #0x0800000 ; MOVE BIT MASK (FOR BIT 23) INTO TEMP REGISTER (0x800000 = 0x01 << 23) + B write_exec ; CALL SUBROUTINE TO EXECUTE YOUR CHANGES +; +; +; +; EXPORT FUNCTION LOCATION SO THAT C-COMPILER CAN LINK + EXPORT dig_out_P16 +dig_out_P16 +;========dig_out_P16======== +; P16 LOCATED AT PORT-0 PIN-24 + LDR R0, =0x4002C004 ; LOAD ADDRESS OF PINSEL1 REGISTER + LDR R1, =0x01000000 ; MOVE BIT MASK (FOR BIT 24) INTO TEMP REGISTER (0x1000000 = 0x01 << 24) + LDR R2, =0x2009C000 ; LOAD ADDRESS OF FIO0DIR0 REGISTER + MOV.W R3, #0x30000 ; FORM BITMASK FOR PINSEL1 REGISTER (clear appropriate bits) +; ; NOTE: THE ABOVE IS A 32-BIT INSTRUCTION BC OF ".W" QUALIFIER + B dig_out_exec ; CALL SUBROUTINE TO EXECUTE YOUR CHANGES +; +; +; +; EXPORT FUNCTION LOCATION SO THAT C-COMPILER CAN LINK + EXPORT P16_write +P16_write +;========P16_write========= +; P16 LOCATED AT PORT-0 PIN-24 + LDR R1, =0x2009C000 ; LOAD ADDRESS OF FIO0DIR0 (PORT 0 BASE REGISTER) + MOV.W R2, #0x1000000 ; MOVE BIT MASK (FOR BIT 23) INTO TEMP REGISTER (0x1000000 = 0x01 << 24) + B write_exec ; CALL SUBROUTINE TO EXECUTE YOUR CHANGES +; +; +; +; EXPORT FUNCTION LOCATION SO THAT C-COMPILER CAN LINK + EXPORT dig_out_P17 +dig_out_P17 +;========dig_out_P17======== +; P17 LOCATED AT PORT-0 PIN-25 + LDR R0, =0x4002C004 ; LOAD ADDRESS OF PINSEL1 REGISTER + MOV.W R1, #0x02000000 ; MOVE BIT MASK (FOR BIT 25) INTO TEMP REGISTER (0x40000 = 0x01 << 25) +; ; NOTE: THE ABOVE IS A 32-BIT INSTRUCTION BC OF ".W" QUALIFIER + LDR R2, =0x2009C000 ; LOAD ADDRESS OF FIO0DIR0 REGISTER + MOV R3, #0xC0000 ; FORM BITMASK FOR PINSEL1 REGISTER (clear appropriate bits) + B dig_out_exec ; CALL SUBROUTINE TO EXECUTE YOUR CHANGES +; +; +; +; EXPORT FUNCTION LOCATION SO THAT C-COMPILER CAN LINK + EXPORT P17_write +P17_write +;========P17_write========= +; P17 LOCATED AT PORT-0 PIN-25 + LDR R1, =0x2009C000 ; LOAD ADDRESS OF FIO0DIR0 (PORT 0 BASE REGISTER) + MOV.W R2, #0x2000000 ; MOVE BIT MASK (FOR BIT 25) INTO TEMP REGISTER (0x1000000 = 0x01 << 25) + B write_exec ; CALL SUBROUTINE TO EXECUTE YOUR CHANGES +; +; +; +dig_out_exec +;========dig_out_execution======== +; SET PIN FUNCTION TO GPIO + LDR R4, [R0] ; \ + BIC R4, R3 ; - APPLY BITMASK FOR PINSELx REGISTER (clear appropriate bits) + STR R4, [R0] ; STORE BITMASK IN PINSELx REGISTER +; +; SET UP GPIO PORT FOR OUTPUT DIRECTION (WITH SPECIFIED BITMASK IN REGISTER R2) + LDR R6, [R2] ; \ + ORR R6, R1 ; - ACQUIRE BITMASK FOR FIOxDIR REGISTER (1 = Output) + STR R6, [R2] ; STORE BITMASK IN FIOxDIR REGISTER +; +;RETURN TO MAIN + BX LR ; RETURN TO MAIN USING LINKER REGISTER +; +; +; +write_exec +;========write_execution========= +; CLEAR/SET BASED ON INPUT VALUE + CMP R0, #0 ; VALUE == 0 ? + ITE EQ ; (IF-THEN-ELSE) ON NEXT TWO INSTRUCTIONS USING "EQ" FLAG + STREQ R2, [R1,#0x1C] ; if==0, CLEAR LED1 BIT + STRNE R2, [R1,#0x18] ; if==1, SET LED1 BIT +; +; RETURN TO MAIN + BX LR ; RETURN TO MAIN USING LINKER REGISTER +; +; +; + ALIGN 4 ; make sure the file is ended with align 4 + NOP + NOP + END
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/segment_display/segment_display.h Thu Dec 10 08:59:21 2015 +0000 @@ -0,0 +1,9 @@ +#ifndef SEGMENT_DISPLAY_H +#define SEGMENT_DISPLAY_H + +//declare functions (assembly subroutines) +extern "C" void setup_sequence(void); +extern "C" void seg_driver_initialize(void); +extern "C" void seg_driver(int value); + +#endif //SEGMENT_DISPLAY_H \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/segment_display/segment_driver.s Thu Dec 10 08:59:21 2015 +0000 @@ -0,0 +1,183 @@ + AREA segment_driver, CODE, READONLY +;--------------------OVERVIEW------------------------ +; This file contains ARM Assembly language functions to +; drive a 7-segment LED Display (Kingbright SA03-11HDB). +; This library uses a switch statement on the input +; register (R0) to set or clear each corresponding lead +; of the display. NOTE: The 7 Segments of the LED display +; must be connected to pins p11 - p17 of the mbed digital +; I/O. For further help with understanding this file, +; please refer to files: +; dig_in.s +; dig_out.s +;------------------------------------------------------ +; Import function locations so that C compiler can find it and link + IMPORT dig_out_P11 + IMPORT P11_write + IMPORT dig_out_P12 + IMPORT P12_write + IMPORT dig_out_P13 + IMPORT P13_write + IMPORT dig_out_P14 + IMPORT P14_write + IMPORT dig_out_P15 + IMPORT P15_write + IMPORT dig_out_P16 + IMPORT P16_write + IMPORT dig_out_P17 + IMPORT P17_write +; Export function location so that C compiler can find it and link + EXPORT seg_driver_initialize +seg_driver_initialize ;CLEAR DISPLAY + PUSH {LR} + BL dig_out_P11 + BL dig_out_P12 + BL dig_out_P13 + BL dig_out_P14 + BL dig_out_P15 + BL dig_out_P16 + BL dig_out_P17 + MOV R0,#1 + BL P11_write + BL P12_write + BL P13_write + BL P14_write + BL P15_write + BL P16_write + BL P17_write + POP {LR} + BX LR + +; Export function location so that C compiler can find it and link + EXPORT seg_driver +seg_driver ;SWITCH STATEMENT + PUSH {LR} + ADR R2,switchpool + LDR PC,[R2,R0,LSL #2] + ALIGN +switchpool + DCD case0 + DCD case1 + DCD case2 + DCD case3 + DCD case4 + DCD case5 + DCD case6 + DCD case7 + DCD case8 + DCD case9 +case0 + MOV R0,#0 + BL P11_write + BL P12_write + BL P13_write + BL P14_write + BL P15_write + BL P16_write + MOV R0,#1 + BL P17_write + B end +case1 + MOV R0,#0 + BL P12_write + BL P13_write + MOV R0,#1 + BL P11_write + BL P14_write + BL P15_write + BL P16_write + BL P17_write + B end +case2 + MOV R0,#0 + BL P11_write + BL P12_write + BL P14_write + BL P15_write + BL P17_write + MOV R0,#1 + BL P13_write + BL P16_write + B end +case3 + MOV R0,#0 + BL P11_write + BL P12_write + BL P13_write + BL P14_write + BL P17_write + MOV R0,#1 + BL P15_write + BL P16_write + B end +case4 + MOV R0,#0 + BL P12_write + BL P13_write + BL P16_write + BL P17_write + MOV R0,#1 + BL P11_write + BL P14_write + BL P15_write + B end +case5 + MOV R0,#0 + BL P11_write + BL P13_write + BL P14_write + BL P16_write + BL P17_write + MOV R0,#1 + BL P12_write + BL P15_write + B end +case6 + MOV R0,#0 + BL P11_write + BL P13_write + BL P14_write + BL P15_write + BL P16_write + BL P17_write + MOV R0,#1 + BL P12_write + B end +case7 + MOV R0,#0 + BL P11_write + BL P12_write + BL P13_write + MOV R0,#1 + BL P14_write + BL P15_write + BL P16_write + BL P17_write + B end +case8 + MOV R0,#0 + BL P11_write + BL P12_write + BL P13_write + BL P14_write + BL P15_write + BL P16_write + BL P17_write + B end +case9 + MOV R0,#0 + BL P11_write + BL P12_write + BL P13_write + BL P16_write + BL P17_write + MOV R0,#1 + BL P14_write + BL P15_write + B end +end + POP {LR} + BX LR +; + END + \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/segment_display/setup.s Thu Dec 10 08:59:21 2015 +0000 @@ -0,0 +1,42 @@ + AREA setup, CODE, READONLY +;--------------------OVERVIEW------------------------ +; This file contains ARM Assembly language functions to +; initialize select registers/memory-locations in the +; LPC1768 to predetermined values. This startup sequence +; will be used to test the integrity of your program, and +; IT SHOULD NOT BE ALTERED BY ANY MEANS. Any student +; attempting to alter this file will be subject to academic +; dishonesty and any disciplinary actions pertaining +; thereto. +;------------------------------------------------------ +; Export function location so that C compiler can find it and link + EXPORT setup_sequence +setup_sequence + ;PUSH LINK REGISTER TO STACK + PUSH {LR} + + ;INIT PINSEL0 + LDR R0, =0x4002C000 ;LOAD ADDRESS OF PINSEL0 REGISTER + LDR R1, =0x40000000 ;LOAD BITMASK FOR PINSEL0 REGISTER + LDR R2, [R0] ;\ + ORR R2, R1 ;- APPLY BITMASK + STR R2, [R0] ;/ + + ;INIT PINSEL1 + LDR R0, =0x4002C004 ;LOAD ADDRESS OF PINSEL1 REGISTER + LDR R1, =0x00054015 ;LOAD BITMASK FOR PINSEL1 REGISTER + LDR R2, [R0] ;\ + ORR R2, R1 ;- APPLY BITMASK + STR R2, [R0] ;/ + + ;INIT PINSEL3 + LDR R0, =0x4002C00C ;LOAD ADDRESS OF PINSEL3 REGISTER + LDR R1, =0x00004510 ;LOAD BITMASK FOR PINSEL4 REGISTER + LDR R2, [R0] ;\ + ORR R2, R1 ;- APPLY BITMASK + STR R2, [R0] ;/ + + ;RETURN TO MAIN + POP {LR} + BX LR + END \ No newline at end of file