⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 traffic.c

📁 这个是关于ATM9200芯片的traffic的代码
💻 C
📖 第 1 页 / 共 2 页
字号:
                {
                ;
                }
        

        }


        traffic_change  (GREEN,ON);

        if(DEBUG) traffic_printf ("TL: leaving traffic_init \n");
}

/* -- traffic_addone -----------------------------------------------------
 *
 * Description  : return an number incremented by 1
 *
 * Parameters   : int num - number passed into the function.
 * Return       : int
 * Notes        : an example of using in-line assembler.
 *
 */

int traffic_addone ( int num )
{
        __asm 
        {
        mov             r0, num         // r0 = num
        add             r0, r0, #1      // r0 = r0 + 1
        mov             num, r0         // num = r0
        }
        
        return num;
}

/* -- traffic_delay ------------------------------------------------------
 *
 * Description  : This provides the delay required for the traffic lights
 *
 * Parameters   : int delay - the delay is in seconds
 * Retrun       : none...
 * Notes        :
 *
 *              Uses the internal clock on the ARM Evaluation Board.
 *
 */

void traffic_delay (int delay)
{       
        if(DEBUG) traffic_printf ("TL: entering traffic_delay \n");

#ifdef  FULL_LIB
        assert (delay>0);
#endif  

        if(HARDWARE) {
        int             i;

                i = AuxCT_repetitions + 500;
                while ( i > AuxCT_repetitions )
                {
                ;
                }
        
        } else {
#ifdef FULL_LIB
        time_t          old,new;        
        
        // -- semihosting time functions when no hardware available ...

        new = old = time(&old);

                do {
                        // -- spin 
                } while ( (old+delay) > time(&new));
#endif
        }

        if(DEBUG) traffic_printf ("TL: leaving traffic_delay \n");
}
        
/* -- traffic_sequence ------------------------------------------------
 *
 * Description  : Runs the traffic light sequence...
 *
 * Parameters   : int cycles - number of cycles 
 * Return       : none...
 * Notes        : none...
 *
 */


/****************************************************
 * USA Traffic Lights
 ****************************************************/

#ifndef EUROPEAN

void traffic_sequence ( int cycles )
{
int     xcount;
int     phase;

        // -- init ...............................................................

        if(DEBUG) traffic_printf ("TL: entering traffic_sequence \n");

#ifdef FULL_LIB
        assert  (cycles>0);
#endif

        xcount  = 1;
        phase   = 0;

        if(DEBUG) traffic_printf_int ("TL: ** Traffic Sequence with %d cycles \n",cycles);
        
        // -- process ............................................................

        while (xcount <= cycles) {
                
                switch (phase) {

                case 0          : // -- switch the GREEN(off) then AMBA(on) ...

                        if(DEBUG) traffic_printf_int ("\n\nTL: *** New Cycle [%d] *** \n",xcount);
                        traffic_change  (GREEN,OFF);
                        traffic_change  (AMBER,ON);
                        phase           = 1;
                        traffic_delay   (10);
                        
                        break;  

                case 1          : // -- switch the AMBA(off) then RED(on) ....
                
                        traffic_change  (AMBER, OFF);
                        traffic_change  (RED,   ON);
                        phase           = 2;
                        traffic_delay   (10);
                        
                        break;
                

                case 2          : // -- switch the RED(off) then GREEN(on) ...

                        traffic_change  (RED,OFF);
                        traffic_change  (AMBER,OFF);
                        traffic_change  (GREEN,ON);
                        phase           = 0;
                        traffic_delay   (10);
                        xcount = traffic_addone (xcount);
                        break;
                
                }
        }

        if(DEBUG) traffic_printf ( "TL: leaving traffic_sequence \n");
}

#else

/****************************************************
 * EUROPEAN Traffic Lights
 ****************************************************/


void traffic_sequence ( int cycles )
{
int     xcount;
int     phase;

        // -- init ...............................................................

        if(DEBUG) traffic_printf ("TL: entering traffic_sequence \n");

#ifdef FULL_LIB
        assert  (cycles>0);
#endif

        xcount  = 1;
        phase   = 0;

        if(DEBUG) traffic_printf_int ("TL: ** Traffic Sequence with %d cycles \n",cycles);
        
        // -- process ............................................................

        while (xcount <= cycles) {
                
                switch (phase) {

                case 0          : // -- switch the GREEN(off) then AMBA(on) ...

                        if(DEBUG) traffic_printf_int ("\n\nTL: *** New Cycle [%d] *** \n",xcount);
                        traffic_change  (GREEN,OFF);
                        traffic_change  (AMBER,ON);
                        phase           = 1;
                        traffic_delay   (10);
                        
                        break;  

                case 1          : // -- switch the AMBA(off) then RED(on) ....
                
                        traffic_change  (AMBER,OFF);
                        traffic_change  (RED,ON);
                        phase           = 2;
                        traffic_delay   (10);
                        
                        break;


                case 2          : // -- switch the RED(on) then AMBER(on) ...

                        traffic_change  (AMBER,ON);
                        phase           = 3;
                        traffic_delay   (10);

                        break;

                case 3          : // -- switch the RED(off) then GREEN(on) ...

                        traffic_change  (RED,OFF);
                        traffic_change  (AMBER,OFF);
                        traffic_change  (GREEN,ON);
                        phase           = 0;
                        traffic_delay   (10);
                        xcount = traffic_addone (xcount);
                        break;
                
                }
        }

        if(DEBUG) traffic_printf ( "TL: leaving traffic_sequence \n");
}

#endif

/* -- traffic_interrupt ----------------------------------------------------
 *
 * Description  : The interrupt button has been pressed. Toggles D1 LED...
 *
 * Parameters   : none...
 * Return       : none...
 * Notes        : none...
 *
 */

void traffic_interrupt (void)
{
        if( toggle == 0 ) {
        traffic_change  (COMPLETE, ON);
        toggle = 1;
        } else {
        toggle = 0;
        traffic_change  (COMPLETE, OFF);
        }
}

/* -- C_Entry --------------------------------------------------------------
 *
 * Description  : entry point for traffic lights
 * 
 * Parameters   : none...
 * Return       : return 1 if successful
 * Notes        : none...
 *
 */

int C_Entry ( void )
{
        if(DEBUG) traffic_printf ("TL: entering main \n");
        
        // -- initialize all internal structures .......................

                traffic_init ();

        // -- process ..................................................

                traffic_sequence (50);

        if(DEBUG) traffic_printf ("TL: leaving main \n");

        traffic_change (COMPLETE, ON);

        Exit();

        return 0;
}

/**************************************************************************
 * End of traffic.c
 **************************************************************************/

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -