1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149
|
#include <plib.h>
#if defined (__32MX360F512L__) || (__32MX460F512L__) || (__32MX795F512L__) || (__32MX430F064L__)
// Configuration Bit settings
// SYSCLK = 80 MHz (8MHz Crystal / FPLLIDIV * FPLLMUL / FPLLODIV)
// PBCLK = 80 MHz (SYSCLK / FPBDIV)
// Primary Osc w/PLL (XT+,HS+,EC+PLL)
// WDT OFF
// Other options are don't care
void clignotement(void);
void init_variable(void);
void autre_fonction(void);
volatile int autre_variable;
volatile int i, j;
//int j;
#pragma config FPLLMUL = MUL_20, FPLLIDIV = DIV_2, FPLLODIV = DIV_1, FWDTEN = OFF
#pragma config POSCMOD = HS, FNOSC = PRIPLL, FPBDIV = DIV_1
//#define SYS_FREQ (80000000L)
#endif
// Let compile time pre-processor calculate the CORE_TICK_PERIOD
#define SYS_FREQ (80000000)
#define TOGGLES_PER_SEC 1
#define CORE_TICK_RATE (SYS_FREQ/5/TOGGLES_PER_SEC)
#define LED 0x00000007
void init_variable(void)
{
i=1;
j=1;
autre_variable=10;
}
void __ISR(_CORE_TIMER_VECTOR, ipl2) CoreTimerHandler(void)
{
// .. things to do
// .. Toggle the LED
mPORTDToggleBits(BIT_0);
mPORTDToggleBits(BIT_1);
mPORTDToggleBits(BIT_2);
i++;
//if (i==10) i=0;
// update the period
UpdateCoreTimer(CORE_TICK_RATE);
// clear the interrupt flag
mCTClearIntFlag();
}
void clignotement(void)
{
//ClrWdt();
j=i;
//mPORTDToggleBits(BIT_0);
//mPORTDToggleBits(BIT_1);
//mPORTDToggleBits(BIT_2);
//UpdateCoreTimer(CORE_TICK_RATE);
//if (i<5) PORTD=0x00000007; else if(i>5) PORTD=0x00000000;
}
void autre_fonction(void)
{
autre_variable=150;
}
int main(void)
{
// Configure the device for maximum performance but do not change the PBDIV
// Given the options, this function will change the flash wait states, RAM
// wait state and enable prefetch cache but will not change the PBDIV.
// The PBDIV value is already set via the pragma FPBDIV option above.
SYSTEMConfig(SYS_FREQ, SYS_CFG_WAIT_STATES | SYS_CFG_PCACHE);
// Explorer-16 LEDs are on lower 8-bits of PORTA and to use all LEDs, JTAG port must be disabled.
//mJTAGPortEnable(DEBUG_JTAGPORT_OFF);
//Initialize the DB_UTILS IO channel
DBINIT();//ClrWdt();
// configure the core timer roll-over rate (100msec)
OpenCoreTimer(CORE_TICK_RATE);
init_variable();//ClrWdt();
// set up the core timer interrupt with a prioirty of 2 and zero sub-priority
mConfigIntCoreTimer((CT_INT_ON | CT_INT_PRIOR_2 | CT_INT_SUB_PRIOR_0));
j=2;
// Clear PORTA bits so there are no unexpected flashes when setting
// them to output in the next step
mPORTDClearBits(BIT_2 |BIT_1 | BIT_0);
j=3;
// Make lower four bits of PORTD as output
mPORTDSetPinsDigitalOut(BIT_2 |BIT_1 | BIT_0);
j=4;
// enable device multi-vector interrupts
INTEnableSystemMultiVectoredInt();//ClrWdt();
j=5;
//ClrWdt();
//Now blink LEDs ON/OFF forever.
while (1)
{
clignotement();
autre_fonction();
}
return 0;
} |
Partager