Presentation is loading. Please wait.

Presentation is loading. Please wait.

13-1 Bard, Gerstlauer, Valvano, Erez, Telang, Yerraballi EE 319K Introduction to Embedded Systems Lecture 13: 2-D Arrays, Bitmaps, Sprites, Structs, Lab.

Similar presentations


Presentation on theme: "13-1 Bard, Gerstlauer, Valvano, Erez, Telang, Yerraballi EE 319K Introduction to Embedded Systems Lecture 13: 2-D Arrays, Bitmaps, Sprites, Structs, Lab."— Presentation transcript:

1 13-1 Bard, Gerstlauer, Valvano, Erez, Telang, Yerraballi EE 319K Introduction to Embedded Systems Lecture 13: 2-D Arrays, Bitmaps, Sprites, Structs, Lab 10

2 13-2 Agenda  Recap  Lab9  UART, Interrupts  FIFO Queues  Race Condition, Critical section  Agenda  Software design  2-D array  Bitmaps  Structs  Lab 10 Bard, Gerstlauer, Valvano, Erez, Telang, Yerraballi

3 13-3 Software Design  Modular programming  Make it easier to understand oEach screen is a complete story without scrolling  Maximize the number of modules  Minimize the interdependency oBandwidth of data passed from one to another oControl coupling: actions in one cause effects in another oShared variables (very bad) Book Section 5.2 Bard, Gerstlauer, Valvano, Erez, Telang, Yerraballi

4 13-4 Software Design  Design for test  Consider how it will be tested while designing  Module has three files oHeader: What the module does oCode: How it works oTest: A main program used to test the module  Manage resources  LCD graphics  Time (processor cycles) oA fun game requires careful control of time  Input/Output oSwitches, slide pot, DAC, LCD Bard, Gerstlauer, Valvano, Erez, Telang, Yerraballi

5 13-5 Callbacks Bard, Gerstlauer, Valvano, Yerraballi // ***************** Timer0_Init **************** // Activate Timer0 interrupts to run user task periodically // Inputs: task is a pointer to a user function // period in units (1/clockfreq) // Outputs: none void Timer0_Init(void(*task)(void), unsigned long period){long sr; sr = StartCritical(); SYSCTL_RCGCTimer_R |= 0x01; // 0) activate timer0 PeriodicTask = task; // user function TIMER0_CTL_R &= ~TIMER_CTL_TAEN; // 1) disable timer0A during setup // 2) configure for 32-bit timer mode TIMER0_CFG_R = TIMER_CFG_32_BIT_TIMER; // 3) configure for periodic mode, default down-count settings TIMER0_TAMR_R = TIMER_TAMR_TAMR_PERIOD; TIMER0_TAILR_R = period-1; // 4) reload value // 5) clear timer0A timeout flag TIMER0_ICR_R = TIMER_ICR_TATOCINT; TIMER0_IMR_R |= TIMER_IMR_TATOIM;// 6) arm timeout interrupt NVIC_PRI4_R = (NVIC_PRI4_R&0x00FFFFFF)|0x ; // 7) priority 2 NVIC_EN0_R = NVIC_EN0_INT19; // 8) enable interrupt 19 in NVIC TIMER0_CTL_R |= TIMER_CTL_TAEN; // 9) enable timer0A EndCritical(sr); } void UserTask(void){ static int i = 0; LEDS = COLORWHEEL[i&(WHEELSIZE-1)]; i = i + 1; } … Timer0_Init(&UserTask, );// initialize timer0 (1 Hz)

6 D Array or Matrix  What: 2 rows and 3 columns, 8 bits each  unsigned char M[2][3];  Why:  Images  Maps  How: (C uses row major)  C code to access M[i][j] = 5;  Write this in assembly (R0=i, R1=j) i = row j = column n= # of columns Base+n*i+j Base+2*(n*i+j) Base+4*(n*i+j) Num of bytes/element Bard, Gerstlauer, Valvano, Erez, Telang, Yerraballi

7 D Array or Matrix  What: 6 rows and 7 columns  short Connect4[6][7];  Why:  Images  Maps  How: (row major)  Write C code to set array values to 0  Write in assembly Base+2*(7*i+j) Bard, Gerstlauer, Valvano, Erez, Telang, Yerraballi j i

8 D Array or Matrix  Assuming C[6][7] 0 means free 1 means me -1 means you // check the rows for(i=0;i<6;i++){ for(j=0;j<4;j++){ if((C[i][j]==1) &&(C[i][j+1]==1) &&(C[i][j+2]==1) &&(C[i][j+3]==1)){ Iwin(); } Bard, Gerstlauer, Valvano, Erez, Telang, Yerraballi j i

9 13-9 Nokia 5110 Graphics Format LCD is 48 rows, 84 columns, 1 bits/pixel Row 0 Row 48 Column 0 Column 84

10 13-10 BMP File Format SmallEnemy sprites are 16-color, 16 pixels wide by 10 pixels high Alien sprites are 16-color, 32 pixels wide by 20 pixels high  Sprites as objects moving across screen Bard, Gerstlauer, Valvano, Erez, Telang, Yerraballi

11 13-11 BMP File Format F F FFFFFFFFFF FFFFFFFFFFFF FFF FFFF FFF F F F F F F The raw data from BMP file to illustrate how the image is stored (0s replaced with spaces). LCD_DrawBMP(SmallEnemy10pointA,50,100); Placed at x=50, y=100 Bard, Gerstlauer, Valvano, Erez, Telang, Yerraballi 16 wide, 10 high

12 13-12 BMP File Format const unsigned char Enemy10Point1[] = { 0x42,0x4D,0xC6,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x76,0x00,0x00,0x00,0x28,0x00, 0x00,0x00,0x10,0x00,0x00,0x00,0x0A,0x00,0x00,0x00,0x01,0x00,0x04,0x00,0x00,0x00, 0x00,0x00,0x50,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0x00,0x00,0x80, 0x00,0x00,0x00,0x80,0x80,0x00,0x80,0x00,0x00,0x00,0x80,0x00,0x80,0x00,0x80,0x80, 0x00,0x00,0x80,0x80,0x80,0x00,0xC0,0xC0,0xC0,0x00,0x00,0x00,0xFF,0x00,0x00,0xFF, 0x00,0x00,0x00,0xFF,0xFF,0x00,0xFF,0x00,0x00,0x00,0xFF,0x00,0xFF,0x00,0xFF,0xFF, 0x00,0x00,0xFF,0xFF,0xFF,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x0F,0x00,0x00,0x00,0x00,0xF0,0x00, 0x00,0x00,0xF0,0x00,0x00,0x0F,0x00,0x00, 0x00,0x0F,0xFF,0xFF,0xFF,0xFF,0xF0,0x00, 0x00,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x00, 0x00,0xFF,0xF0,0xFF,0xFF,0x0F,0xFF,0x00, 0x00,0xF0,0xFF,0xFF,0xFF,0xFF,0x0F,0x00, 0x00,0xF0,0x0F,0x00,0x00,0xF0,0x0F,0x00, 0x00,0x00,0xF0,0x00,0x00,0x0F,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0xFF }; Example BMP file written as C constant  Header (w x h)  Pixel data Bard, Gerstlauer, Valvano, Erez, Telang, Yerraballi We can use either 24-bit BMP or 4-bit BMP

13 13-13 BMP Header Format

14 13-14 Structure Definition  One object  Collection of data  Data has dissimilar types or meanings struct State { unsigned long x; // x coordinate unsigned long y; // y coordinate const unsigned char *image; // ptr->image long life; // 0=dead, 1=alive }; typedef struct State STyp; a new type Bard, Gerstlauer, Valvano, Erez, Telang, Yerraballi

15 13-15 Structure Creation  Put in RAM if data changes  Initialized at run time, before main() STyp Enemy[18]={ {0,10, SmallEnemy30PointA,1}, {20,10, SmallEnemy30PointA,1}, {40,10, SmallEnemy30PointA,1}, {60,10, SmallEnemy30PointA,1}, {80,10, SmallEnemy30PointA,1}, {100,10, SmallEnemy30PointA,1}, … {100,30, SmallEnemy10PointA,1} }; the new type Bard, Gerstlauer, Valvano, Erez, Telang, Yerraballi

16 13-16 Structure Creation  Put in RAM if data changes  Run-time initialization inside main() STyp Enemy[18]; void Init(void){ int i; for(i=0;i<6;i++){ Enemy[i].x = 20*i; Enemy[i].y = 10; Enemy[i].image = SmallEnemy30PointA; Enemy[i].life = 1; } Bard, Gerstlauer, Valvano, Erez, Telang, Yerraballi

17 13-17 Structure Example  Student database  Set of student records  Structure definition struct Student { char Initials[2]; short id; struct Student *teammate; }; typedef struct Student SType; Bard, Gerstlauer, Valvano, Erez, Telang, Yerraballi

18 13-18 Arrays of Structures  Pointers to specific elements  Array of structure creation #define XYpt &class[0] #define ABpt &class[1] #define RSpt &class[2]... SType class[6] = { {{'X','Y'},123, RSpt}, // XY {{'A','B'}, 23, RYpt}, // AB {{'R','S'}, 11, XYpt}, // RS... {{'R','Y'},2457, ABpt}}; // RY Bard, Gerstlauer, Valvano, Erez, Telang, Yerraballi

19 13-19 Arrays of Structures  Traverse array  Add features  Seating chart  Write a function to place a student into seat Write code to navigate through the class array and print all student records in the following format: FI-LI : id (team-mate_id) SType seatChart[5][24]; //2-D array Bard, Gerstlauer, Valvano, Erez, Telang, Yerraballi

20 13-20 Timer 2A Periodic interrupt Bard, Gerstlauer, Valvano, Erez, Telang, Yerraballi Resolution: bus period Precision: 32 bits Max period: 53 sec (80 MHz) 0) activate timer2 clock 1) disable timer2A 2) Precision to 32 bits 3) periodic mode 4) TAILR value 5) clock resolution 6) clear timeout flag 7) arm timeout 8) priority 4 9) enable in NVIC 10) enable timer2A

21 13-21 INTERRUPT VECTORS Lab 7 Lab 8 Lab 9 77 total Bard, Gerstlauer, Valvano, Yerraballi

22 13-22 Timer 2A Periodic interrupt unsigned long TimerCount; void Timer2_Init(unsigned long period){ unsigned long volatile delay; SYSCTL_RCGCTIMER_R |= 0x04; // 0) activate timer2 delay = SYSCTL_RCGCTIMER_R; TimerCount = 0; TIMER2_CTL_R = 0x ; // 1) disable timer2A TIMER2_CFG_R = 0x ; // 2) 32-bit mode TIMER2_TAMR_R = 0x ; // 3) periodic mode TIMER2_TAILR_R = period-1; // 4) reload value TIMER2_TAPR_R = 0; // 5) clock resolution TIMER2_ICR_R = 0x ; // 6) clear timeout flag TIMER2_IMR_R = 0x ; // 7) arm timeout NVIC_PRI5_R = (NVIC_PRI5_R&0x00FFFFFF)|0x ; // 8) priority 4 NVIC_EN0_R = 1<<23; // 9) enable IRQ 23 in TIMER2_CTL_R = 0x ; // 10) enable timer2A } Output sound at kHz Bard, Gerstlauer, Valvano, Yerraballi Max is 53 sec

23 13-23 Timer 2A plays sounds // trigger is Timer2A Time-Out Interrupt // set periodically TATORIS set on rollover void Timer2A_Handler(void){ TIMER2_ICR_R = 0x ; // acknowledge TimerCount++; // run some background stuff here } void Timer2A_Stop(void){ TIMER2_CTL_R &= ~0x ; // disable } void Timer2A_Start(void){ TIMER2_CTL_R |= 0x ; // enable } Ack Stuff Output sounds here Call to stop sound Call to start sound TATORIS Bard, Gerstlauer, Valvano, Erez, Telang, Yerraballi

24 13-24 Lab 10 – Connect Four  There must be at least one button and one slide pot.  The colored pieces must move on the LCD.  There must be sounds appropriate for the game.  The score should be displayed on the screen (but it could be displayed before or after the game action).  At least two interrupt ISRs must used in an appropriate manner.  The game must have a man versus machine mode. Bard, Gerstlauer, Valvano, Erez, Telang, Yerraballi

25 13-25 Lab10 – Space Invaders, Pipe Dreams …  There must be at least one button and one slide pot.  There must be at least three images on the LCD display that move.  There must be sounds appropriate for the game.  The score should be displayed on the screen (but it could be displayed before or after the game action).  At least two interrupt ISRs must used in an appropriate manner.  The game must have a “time” aspect to it (For e.g., if you don’t move a sprite within a certain time it could be killed). Contrast with ConnectFour which is a taking “turns” game  The game must be both simple to learn and fun to play. Bard, Gerstlauer, Valvano, Erez, Telang, Yerraballi

26 13-26 Lab 10 – Grading  The TAs will sort into groups and certify requirements  Show game to TA on Tuesday 12/2 by 7pm  Wonderful group will have max of 100 points  Supreme group will have a max of 120 points  Lab 10 will be graded subjectively by other students  During class on Wednesday 12/3  One team member demonstrates  The other team member scores other games  Can’t compete unless both members are present  Groups of one are checked out by the TA (Max Score 80)  Games are rank-ordered by peers  Superfinals Friday 12/5 at 2pm (Room TBD) Bard, Gerstlauer, Valvano, Erez, Telang, Yerraballi

27 13-27 Lab 10 – Grading  Wonderful group  80 if 0 th to 49 th percentile  90 if 50 th to 74 th percentile  100 if 75 th to 100 th percentile  Supreme  100 if 0 th to 49 th percentile  110 if 50 th to 74 th percentile  120 if 75 th to 100 th percentile  TA certification is due 7pm 12/2/2014  Late checkouts are handled by the TA in the usual way. All late checkouts must be completed by Friday 3pm./ Bard, Gerstlauer, Valvano, Erez, Telang, Yerraballi

28 13-28 Game Engine – Data Flow Bard, Gerstlauer, Valvano, Erez, Telang, Yerraballi

29 13-29 Game Engine – Flowchart Bard, Gerstlauer, Valvano, Erez, Telang, Yerraballi


Download ppt "13-1 Bard, Gerstlauer, Valvano, Erez, Telang, Yerraballi EE 319K Introduction to Embedded Systems Lecture 13: 2-D Arrays, Bitmaps, Sprites, Structs, Lab."

Similar presentations


Ads by Google