Presentation is loading. Please wait.

Presentation is loading. Please wait.

You Asked for It… Design Using the Z-World. Next Week In DIG II  Timers and counters  Watchdog timers  UART (Universal asynchronous receiver / transmitter)

Similar presentations


Presentation on theme: "You Asked for It… Design Using the Z-World. Next Week In DIG II  Timers and counters  Watchdog timers  UART (Universal asynchronous receiver / transmitter)"— Presentation transcript:

1 You Asked for It… Design Using the Z-World

2 Next Week In DIG II  Timers and counters  Watchdog timers  UART (Universal asynchronous receiver / transmitter)  Pulse width modulators  LCD controllers  Keypad controllers  Stepper motor controllers  Analog to digital converters  Real time clocks Chapter 4: Standard Single Purpose Processors: Peripherals

3 Dig-Off  This is a wacky – multiple choice – fill in the blanks – prove the following theorem – gimme the correct answer or else – type trivia game show, that is mostly on class material. You will be divided into groups, and each will have a buzzer. As soon as you think you know the answer, buzz in. Get it right, get base number of points for that question. Get it wrong, you lose that many points. The question, now twice the value, is up for grabs, until it is correctly answered or skipped. Note that some questions may have more than one correct answer, in which case, you need to identify ALL of them.  During each round, each group will have a screw. If you think the others do not know the answer to a question, buzz in first, and “screw” the group of your choice. If that group misses the question, they lose points. If they get it right, however, they get the points, and YOU lose the points, um…then you are screwed...  There are also special “impossible questions” worth 10 points. These are eligible for screw (except one), and hence make perfect opportunity to screw other groups.  After each round, the group with the lowest score, will ask for one team member from another group to be joined into their group. The other group then asks a member of the first group to join them. The team member lost to another group cannot be transferred back until the next round.  5% (or a suitable portion) of the final score of the winning group will be added to their final grade.

4 This Week in Dig II  Actual design example using Z-world  Buzzer design for Dr. Polikar’s semester-end Dig-Off! review Game Show  Specs:  There will be four buzzers  The system will continuously listen for any buzzer pressing activity  As soon as one of the buzzers is pressed, the actual buzzer on for 1 second when the button is pressed all other buzzers are disabled, an LED corresponding to that buzzer turns on the LCD displays group name / number The active LED and LCD retain current information for 10 s. then reset  When any of the buttons are pressed, reset entire system.

5 Buzz-In ! // BUZZ-IN.c // Application polls four switches to determine which one is pressed first. // When a "winner" is detected, a light corresponding to the successful switch // is activated; the other switches are disabled, and the buzzer is sounded for 1s. // SW2 controls led D2. // SW3 controls led D3. // SW4 controls led D4. // SW5 controls led D5. #use lcd2l.lib #use vdriver.lib main(){ int state,found,bcount,lcount; found=bcount=lcount=0; outport(CS1,0);// Clear LEDs (D2- D5) outport(CS1+1,0);// Note: CS1 is predefined to be address 0x4000 outport(CS1+2,0);// Each LED is then addressed at 0x4000, 4001, etc. outport(CS1+3,0); outport(CS1+4,0);// At 0x4004 is the buzzer. Turn off the buzzer. VdInit();// initialize the virtual driver lc_init();// initialize the LCD lc_pos(0,0);// Move LCD cursor to the 0,0 location (1st row, 1st column) lc_printf(" System Ready");// Display " System Ready" on the LCD display lc_pos(1,0);// Move LCD cursor to the 1,0 location (2nd row, 1st column) lc_printf("Polikar's Buzz-In 1.0");

6 for(;;){// endless loop hitwd(); runwatch();// This code uses the watchdog timer facility, resetting timer at each pass. costate{// Start costate: everything within the costate loop is executed "at the // same time" (sort of) waitfor(DelayMs(1L));// Wait for 1 milisecond. So, all of the following will be // repeated every 1ms. state = ~inport(CS2+1);// Get the pushbutton values SW2-SW5 by querying // address 0x4041 (i.e., CS2+1) // All switches are located at the address 0x4040. // One additional 8 bit address bit used as a mask, // controls individual switches. 0-3 actual switches, // 4-7 for external switches, controlled by the jumper. if ((!found)&&( state & 0x10 )){// External switch ESW2 pressed...we find this out by // masking all bits except bit b4, which corresponds to // ESW2 lc_init();// initialize the LCD lc_pos(0,0);// Move LCD cursor to the (0,0) (1st row, 1st column) lc_printf(" Player One"); outport( CS1, 1 );// Turn on D2 (first LED) found=1;// Set flag to 1. } if ((!found)&&( state & 0x20 )){// ESW3 pressed (second switch)... outport( CS1+1, 1 );// Turn on D3 (second LED) lc_init(); lc_pos(0,0); lc_printf(" Player Two"); found=1; } Buzz-In !

7 if ((!found)&&( state & 0x40 )){// ESW4 pressed... outport( CS1+2, 1 );// Turn on D4 lc_init();lc_pos(0,0); lc_printf(" Player Three"); found=1; } if ((!found)&&( state & 0x80 )){// ESW5 pressed... outport( CS1+3, 1 );// Turn on D5 lc_init(); lc_pos(0,0); lc_printf(" Player Four"); found=1; } // This is where we control the buzzer time out and round time out. If none of // the reset buttons (ESW2-5) are pressed (see below), the program runs the buzzer // for 1 second (10x100ms, obtained through the bcount counter). The round // times out after 10 seconds (100x100ms, obtained through the lcount counter) if (found==1){ bcount=bcount+1; lcount=lcount+1; // At each millisecond wait (see above), the counts are // incremented by one. if (bcount == 1) outport(CS1+4,1); // When the flag is up (found==1), turn on the buzzer waitfor(DelayMs(100L));// Wait for 100 ms. if (bcount == 10) outport (CS1+4, 0); // When bcount reaches 10 (which means, 1000 ms has // elapsed), turn off the buzzer if (lcount > 100) {// When lcount reaches 100, (which means 10000 ms = 10 seconds), found = 0;// remove the flag and... outport(CS1,0);//... turn off everything outport(CS1+1,0); outport(CS1+2,0); outport(CS1+3,0); outport(CS1+4,0); lc_init(); lc_pos(0,0);//Reinitialized the LCD lc_printf(" System Ready"); found=bcount=lcount=0; }

8 // Alternatively, keep checking the four pushbuttons on the board (actual // switches, SW2-5, not ESW2-5). If any one of them is pressed, then the entire // system is to be resetted for the next round of play. if ((state & 0x01)||(state & 0x02)||(state & 0x04)||(state & 0x08)) { found =bcount=lcount= 0; outport(CS1,0);//turn off everything outport(CS1+1,0); outport(CS1+2,0); outport(CS1+3,0); outport(CS1+4,0); lc_init(); lc_pos(0,0); lc_printf(" System Ready"); } // End if top button hit } // End if found == 1 lc_pos(3,0); // Move cursor offscreen } // End costate }


Download ppt "You Asked for It… Design Using the Z-World. Next Week In DIG II  Timers and counters  Watchdog timers  UART (Universal asynchronous receiver / transmitter)"

Similar presentations


Ads by Google