Goal : To become familiar with using Buzzer on Dragon12-Light boards, the timer
ID: 3845251 • Letter: G
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 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 <mc9s12dg256.h> /* derivative information */
//*****************************************************************
// 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<itime;i++)
for(j=0;j<jtime;j++);
}
//*****************************************************************
// Interrupt Service Routines
//*****************************************************************