SO I need a little push to get me started with the RTI and the for statement in this code:
Code:
// this program is a simple traffic light CONTROLLER program
// green on 4 seconds, yellow for 1 second, red for 5 seconds
// HCS12 controller,,,outputs on PORTA
// uses a RTI from timing control
// i will hook 5 output wires from each of the 6 bits on PORTA CONTROLLER
// TO LEDS
#include <hidef.h> /* common defines and macros */
#include "derivative.h" /* derivative-specific definitions */
//structure definition, type definition
struct state{
unsigned char Out;
unsigned short Time;
struct state *Next; // pointer to the struture for the next state
};
typedef state_type;
#define S0 &fsm[0]
#define S1 &fsm[1]
#define S2 &fsm[2]
#define S3 &fsm[3]
state_type fsm[4] = { // Traf Lite sequence - a structure containing 4 structures
{0x21,400,S1},
{0x22,100,S2},
{0x0C,400,S3},
{0x14,100,S0}
};
void delay(int);
static int counter = 0;
void main(void)
{
state_type *ptr; // setup a pointer to a state-type data structure...
ptr = S0; // ...and initialize it to point to state S0 in fsm
PORTA = 0xFF; // initialize PORTA
DDRA = 0xFF;
CPMURTI = 0x01; // set RTI clock divide get 1mS interval
CPMUFLG_RTIF = 1; // clear RTIF before enable INT
CPMUINT_RTIE = 1; // enable RTI
EnableInterrupts; // global enable
for (;;)
{
// ?????????CALL FUNCTIONS TO INITILIZE HARDWARE HERE
}
}
/******* Interrupt Service Routine ********/
#pragma CODE_SEG NON_BANKED
interrupt ( ( (0x10000 - 0xFFF0) / 2 ) - 1 ) void isrRTI(void)
{
//???????????
CPMUFLG_RTIF = 1; // clear RTIF
}
#pragma CODE_SEG DEFAULT
void delay(int k )
{
unsigned int i,j;
for (i=0;i<=k;i++)
{ /* adjust condition field for delay time */
for (j=0;j<=0xff;j++)
{
asm("nop");
}
}