Message Edited by mccp on 2007-05-16 10:11 AM
Message Edited by t.dowe on 2007-05-18 05:51 PM
Message Edited by t.dowe on 2007-05-18 05:56 PM
/* IMPORTANT
Add to mcf5xxx_vectors.s file
// at the top, below other externs
.extern _IRQ_PIT0
.extern _IRQ7_SW2
//vector071: .long asm_exception_handler
vector071: .long _IRQ7_SW2
//vector119: .long asm_exception_handler
vector119: .long _IRQ_PIT0 // 55 + 64
*/
/*
* File: main.c
* Purpose: sample program
*
*/
#include "support_common.h"
#include <stdio.h>
#define OSCOPE_MODE 1
#define USE_LEDS 1
static uint16 g_counter = 0;
static uint8 g_sr = 0;
#ifdef USE_LEDS
void leds_display( uint8 value )
{
MCF_GPIO_PORTTC |= value;
}
void leds_init( void )
{
MCF_GPIO_DDRTC = 0x0F; // set to output
MCF_GPIO_PORTTC = 0x00; // all LEDS off
}
void leds_on( uint8 numLed )
{
MCF_GPIO_PORTTC |= numLed;
}
void leds_off( uint8 numLed )
{
MCF_GPIO_PORTTC &= ~numLed;
}
void leds_toggle( uint8 numLed )
{
MCF_GPIO_PORTTC ^= numLed;
}
#endif
__declspec(interrupt)void IRQ_PIT0( void )
{
#ifdef OSCOPE_MODE
MCF_GPIO_SETQS = 0x7F;
MCF_GPIO_CLRQS = 0x00;
#endif
MCF_PIT_PCSR(0) |= MCF_PIT_PCSR_PIF;
}
__declspec(interrupt)void IRQ7_SW2( void )
{
printf( "IRQ7_SW2 %d\r\n", g_counter++ );
MCF_EPORT_EPFR |= 0x80;
#ifdef USE_LEDS
if( g_counter % 2 == 0 )
{
leds_toggle(0x0A);
leds_off( 0x05 );
}
else
{
leds_toggle(0x05);
leds_off( 0x0A );
}
#endif
}
int main(void)
{
#ifdef OSCOPE_MODE
// Set Up The GPIO Pins (connect oscope probe to Pin 19 on J1)
MCF_GPIO_PORTQS = 0x7F;
MCF_GPIO_DDRQS = 0x7F;
#endif
#ifdef USE_LEDS
leds_init();
#endif
// Set Up The PIT0 IRQ
// set the interrupt level IL and the interrupt priority IP
MCF_INTC_ICR55 = MCF_INTC_ICR_IL(6) | MCF_INTC_ICR_IP(0);
// Set Up the PIT0 Timer
MCF_PIT0_PCSR = 0;
MCF_PIT0_PCSR = (uint16)(MCF_PIT_PCSR_PRE(2)); // arbitrary value, 0 is default
MCF_PIT0_PMR = 0x40; // arbitrary value, 0xFFFF is default
// Create and enable 'set and forget' timer
MCF_PIT0_PCSR |= MCF_PIT_PCSR_OVW // overwrite
| MCF_PIT_PCSR_PIE // interrupt enable
| MCF_PIT_PCSR_PIF // interrupt flag
| MCF_PIT_PCSR_RLD // reload (auto)
| MCF_PIT_PCSR_DBG // debug bit is set
| MCF_PIT_PCSR_EN; // enable timer
// Unmask 55 = PIT0 interrupt source
MCF_INTC_IMRL &= ~(MCF_INTC_IMRL_MASKALL);
MCF_INTC_IMRH &= ~(MCF_INTC_IMRH_INT_MASK55);
asm( move.w #0x2000, sr ); // enable all priority levels
while( 1 )
{
// spin forever
}
}