Thread: Traffic Controller in C using an HCS12 MCU

  1. #1
    Registered User
    Join Date
    Sep 2015
    Posts
    1

    Traffic Controller in C using an HCS12 MCU

    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");
        }     
       }
    


  2. #2
    Registered User
    Join Date
    Feb 2012
    Posts
    347
    For the first one you should initialize the hardware above the for loop and above enable interrupts, since it should be called only once. Regarding the second what is the question? You can leave the interrupt function as it is. You are clearing the rti interrupt flag that should be OK.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Traffic light controller using HCS12
    By runhard33 in forum C Programming
    Replies: 3
    Last Post: 03-22-2014, 05:36 PM
  2. Code for hcs12 towerw/ lcd and interrupt question???
    By runhard33 in forum C Programming
    Replies: 5
    Last Post: 11-10-2013, 12:27 PM
  3. using a dualshock 2 controller via USB
    By Francois Gibon in forum C++ Programming
    Replies: 0
    Last Post: 11-05-2011, 11:44 AM
  4. LCD controller interface
    By oakleyman18 in forum C Programming
    Replies: 5
    Last Post: 05-14-2011, 12:12 PM
  5. About Traffic light controller.
    By ovid in forum C++ Programming
    Replies: 4
    Last Post: 03-28-2010, 02:22 PM