Unformatted text preview: Lecture #6 August 26, 2010 Today’s Class
Hand in Homework 5 Lab 1, part 2: Description Wait for slide switch, then loop 10 times
Light random LED combination random LED combination Wait for 1 second Check for correct reaction Keep track of correct and wrong results Remember it is due at beginning of class it is due at beginning of class Homework 6 due next class – on website
Pseudocode code for Lab 2 Pseudocode for Lab 1, part 2 Overview of Lab 2 CheckCheck-off for Lab 1, part 2 Notebook due, Lab 1 Quiz 2 next class Print the results St th Start another loop only after the slide switch has has been switched off and back on. RPILMS Timers and Interrupts
Lecture #6 2 August 26, 2010 Lecture #6 3 August 26, 2010 Lab 1, part 2 Pseudo-Code Pseudocompiler directives declare global variables function prototypes prototypes main function declare local variables configure ports 2 and 3 Initialize Timer0, including allowing interrupts, don’t start counting while (TRUE) turn off LEDs and buzzer if (slideswitch) ... end if (slideswitch) wait for slideswitch to be toggled off end while (TRUE) end main function Lab 1, part 2 Pseudo-Code Pseudoif (slideswitch) (slideswitch) start Timer 0 for 10 loops get random number repeat until it is different than previous number display correct combination of LEDs reset Interrupt_counts and Timer 0 contents wait 1 second check switches if correct, increment count end for loop clear LED output stop Timer 0 print results end if (slideswitch) (slideswitch) August 26, 2010 Lecture #6 4 August 26, 2010 Lecture #6 5 1 Lecture #6 August 26, 2010 Lab 1, part 2 Pseudo-Code PseudoInterrupt Service Routine increment Interrupt_counts End ISR Lab 2 – will be up soon on LMS LITEC Memory Memory
A series of color LEDs are flashed. The player must remember the sequence and then repeat it by remember the sequence and then repeat it by a sequence sequence of button presses. There is one button for each color LED The flashing rate is controlled by a speed adjustment. Not Not all of the game details are specified. It is your job to fill them in keeping basics of the game as stated. Within reason you can make small changes to the game Within reason, you can make small changes to the game statement statement if it improves the game. Justify your choices in your Game Report August 26, 2010 Lecture #6 6 August 26, 2010 Lecture #6 7 Quiz 2 -Timers
Configure Timer 0 and Timer 1 Set up any mode (fully understand mode and Set up any mode, (fully understand mode 0 and mode mode 1) T0 Mode 0 Bock Diagram 13 bit counting, mode 0 16 bit counting, mode 1 8 bit, mode 2, or two 8 bit counters, mode 3
(8 bits) bits) Count Count at a rate equal to the system clock or the (system clock) 12 Know that the timers are capable of counting external events Know how to start and stop the counting
August 26, 2010 Lecture #6 8 August 26, 2010 Lecture #6 9 2 Lecture #6 August 26, 2010 Timers
Given the clock frequency Timers
Know how to read and write the present count in a timer Calculate the count rate (i.e., counts per second) Calculate the time per counter overflow
1 1 seconds 4.5211 108 freq 22.1184 10 6 Hz count for Mode 1, 16 bits, total number of counts before overflow is : rate 216 65536 counts 0.045211s 65536counts 0.00296 s 2.96 ms for each overflow overflow overflow count for SYSCLK 12, use 22.1184 10 Hz 1.8432 10 6 Hz 12 for Mode 0, 13 bit, use 213 8192 counts
6 Example: clock frequency, 22.1184 MHz TL0 & TH0 for Timer 0 TL1 & TH1 for Timer 1 Example: unsigned int count; // count needs to be 16-bit variable 16count = TH0 * 256 + TL0; (or count = TH0<<8 + TL0;) (or Know which SFRs are used to configure the timers. CKCON TCON TMOD
Lecture #6 11 11 August 26, 2010 Lecture #6 10 August 26, 2010 CKCON: Clock Control Register TCON: Timer Control Register August 26, 2010 Lecture #6 12 August 26, 2010 Lecture #6 13 3 Lecture #6 August 26, 2010 TMOD – Timer Mode Register
Be able to configure either T0 or T1 Quiz 2 - Interrupts
Understand what an interrupt is Know what interrupts are available on the 8051 what interrupts are available on the 8051 Know what is necessary in code for interrupts Enable interrupts
Allow all interrupts, EA=1; or IE |= 0x80; Just Timer 0 Overflow interrupt – enable with ET0 of IE Just Timer 1 Overflow interrupt – enable with ET1 of IE an Interrupt Service Routine Write an Interrupt Service Routine
Include correct interrupt number Be able to find the interrupt number for any type of interrupt, not just Timer interrupts. August 26, 2010 Lecture #6 14 August 26, 2010 Lecture #6 15 IE – Interrupt Enable Interrupt Summary August 26, 2010 Lecture #6 16 August 26, 2010 Lecture #6 17 4 Lecture #6 August 26, 2010 Today’s Class
Finish Lab 1, part 2 If you don’t finish it today, come in during open shop to complete it and be checked to complete it, and be checked-off CheckCheck-off should be done by the beginning of next class
o o Complete entries in lab notebook prior to check-off checkBoth members of a pair must be present for check-off check- Leave hardware intact for Lab 2 Turn in Notebook for Lab 1 Homework 6 will become available after we post this semester’s version of Lab 2!
August 26, 2010 Lecture #6 18 5 ...
View Full Document
This note was uploaded on 04/08/2011 for the course ENGR 2350 taught by Professor Fukanari during the Spring '08 term at Rensselaer Polytechnic Institute.
- Spring '08