

Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Material Type: Assignment; Professor: Grantner; Class: Microcontroller Applications; Subject: Electrical & Computer Engineer; University: Western Michigan University; Term: Fall 2008;
Typology: Assignments
1 / 2
This page cannot be seen from the preview
Don't miss anything!


#include <mc9s12dp256.h>
#pragma abs_address:0x unsigned long int result = 0; #pragma end_abs_address
int counter = 0; void main (void) {
ATD1CTL2 = 0x82; //enable interrupt on series complete ATD1CTL3 = 0x40; //Set conversion sequence length to 8 ATD1CTL4 = 0x05; //Set 10-bit resolution ATD1CTL5 = 0x83; //Right-justified, unsigned results, conversion
TFLG2 = 0x80; //clear TOF flag by writing 1 TSCR1 = 0x80; //enable timer TSCR2 = 0x80; //enable timer over flow interrupt
asm("cli"); //Enable interrupts.
while(1) { if (counter == 3) { while (ATD1STAT1 != 0xFF); //Wait for all CCF flags to go high // indicating a complete sequence.
//Perform average of 8 converted values and place in result. result = (ATD1DR0 + ATD1DR1 + ATD1DR2 + ATD1DR
ATD1CTL5 = 0x83; //Clear ATD flags (SCF, CCFs) counter = 0; //Reset the overflow counter } } }
#pragma interrupt_handler TOF_ISR void TOF_ISR(void) { TFLG2 = 0x80; //Clear TOF flag counter = counter+1; //Increment TOF counter }
#pragma abs_address:0x3E5E
void (* interrupt_vector[]) (void) = {TOF_ISR}; #pragma end_abs_address