Question
Goal : To become familiar with using Buzzer on Dragon12-Light boards, the timer output compare function, and interrupt method, as well as to improve your
Goal: To become familiar with using Buzzer on Dragon12-Light boards, the timer output compare function, and interrupt method, as well as to improve your programming skills.
Project: Write a C program to do the following:
Write your own program to turn the Buzzer on and off in exactly one millisecond frequency by using the timer output compare and interrupt method.
The Buzzer is connected to PT5 of the port T. In your main program, you need to write codes to configure PT5 and timer channel 5 so that interrupt for channel 5 output compare is enabled, and PT5 is configured in toggle mode. You need to write an interrupt service routine for timer channel 5 to provide a one millisecond delay (or interrupt).
In EVB (or Debug) mode, the clock frequency for instructions is 24MHz. Use a variable called ClockCycles that provides the correct number of clock cycles for the service routine to generate exactly one millisecond delay. This variable is similar to the variable Period in the example program Buzzer.txt.
Here is the example program Buzzer
//***************************************************************** // Include derivative-specific definitions //***************************************************************** //The microcontroller chip used by Dragon12-Light boards #include
//***************************************************************** // Gloable Variables //*****************************************************************
//***************************************************************** // Function Prototype //***************************************************************** void MSDelay(unsigned int, unsigned in);
//***************************************************************** // Main program section //***************************************************************** void main(void) { DDRT = DDRT | 0b00100000; //PTT5 as output for (;;) { PTT = PTT | 0x20; //make PT5=1 MSDelay(70, 70); //change the delay size to see what happens PTT = PTT & 0xDF; //Make PT5=0 MSDelay(70, 70); //change delay size....
}
}
//***************************************************************** // Subroutine: MSDelay //***************************************************************** void MSDelay(unsigned int itime, unsigned int jtime) //msec delay { unsigned int i; unsigned int j; for(i=0;i //***************************************************************** // Interrupt Service Routines //*****************************************************************
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started