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

📄 led_swing.c

📁 ATEML公司EB40/40a/42/63/55开发板部分测试程序。
💻 C
字号:
//*----------------------------------------------------------------------------
//*      ATMEL Microcontroller Software Support  -  ROUSSET  -
//*----------------------------------------------------------------------------
//* The software is delivered "AS IS" without warranty or condition of any
//* kind, either express, implied or statutory. This includes without
//* limitation any warranty or condition with respect to merchantability or
//* fitness for any particular purpose, or against the infringements of
//* intellectual property rights of others.
//*----------------------------------------------------------------------------
//* File Name           : led_swing.c
//* Object              : Led Swing for the AT91EB63
//*
//* 1.0 30/10/00 JPP    : Creation
//*----------------------------------------------------------------------------

#ifdef SEMIHOSTING
#include <stdio.h>
#endif

#include "parts/m63200/lib_m63200.h"
#include "drivers/capture/capture.h"
#include "drivers/wait/wait.h"
#include "eb63.h"

extern void wake_up_handler (void) ;

/* Global Variable */
WaitDesc wait_desc = { &TC0_DESC, 0, 0, WAIT_DELAY, wake_up_handler } ;
u_int   LedSpeed ;

//*----------------------------------------------------------------------------
//* Function Name       : change_speed
//* Object              : Adjust led speed depending on SW1 and SW2
//* Input Parameters    : none
//* Output Parameters   : none
//*----------------------------------------------------------------------------
void change_speed ( void )
//* Begin
{
    u_int status = at91_pio_read (&PIOB_DESC) ;
    if (( status & (1<<PIO_SW1) ) == 0 )
    {
        if ( LedSpeed > 10000 ) LedSpeed -=1000 ;
    }
    if (( status & (1<<PIO_SW2) ) == 0 )
    {
        if ( LedSpeed < 2000000 ) LedSpeed +=1000 ;
    }
}
//* End


//*----------------------------------------------------------------------------
//* Function Name       : mcki_detect
//* Object              : Master Clock Frequency Detection
//* Input Parameters    : None
//* Output Parameters   : The Frequency in kHz
//*----------------------------------------------------------------------------
u_int mcki_detect ( void )
//* Begin
{
    int period;

    at91_capture_open ( &TC0_DESC, MODE_TIOA_PERIOD ) ;
    while ( at91_capture_get_status ( &TC0_DESC ) != TRUE ) ;
    period = at91_capture_read ( &TC0_DESC ) ;
    at91_capture_close ( &TC0_DESC ) ;

    if ( period > 15 )
        return ( MCKKHz ) ;
    if ( period > 7 )
        return ( MCKKHz >> 1 ) ;
    if ( period > 3 )
        return ( MCKKHz >> 2 ) ;
    if ( period > 1 )
        return ( MCKKHz >> 3 ) ;

    return ( MCKKHz >> 4 ) ;
}
//* End


//*----------------------------------------------------------------------------
//* Function Name       : main
//* Object              : Main function of the led blink
//* Input Parameters    : none
//* Output Parameters   : True
//*----------------------------------------------------------------------------
int main( void )
//* Begin
{
    u_int   loop_count = 0 ;
    u_int   i ;
    LedSpeed = 50000 ;

	at91_clock_open(PIOB_DESC.periph_id);

    //* -- Set up PIO
    at91_pio_write (&PIOB_DESC, LED_MASK, LED_OFF ) ;
    at91_pio_open ( &PIOB_DESC, LED_MASK, PIO_OUTPUT ) ;

    //* Detect Master Clock
    wait_desc.mcki_khz = mcki_detect () ;


at91_tc_open(&TC1_DESC, 0x000CC000,TRUE,FALSE);
//TC1_RC = 1;
at91_tc_trig_cmd(&TC1_DESC, 0x00000004);



    //* Loop forever
    for (;;)
    {
	//* Once a Shot on each led
        for ( i=LED1 ; i <= LED8 ; i<<=1 )
        {
            change_speed () ;
            at91_pio_write (&PIOB_DESC, i, LED_ON ) ;
            wait_desc.period = LedSpeed ;
            at91_wait_open ( &wait_desc ) ;
            at91_pio_write (&PIOB_DESC, i, LED_OFF ) ;
        }
        //* Once a Shot on each led
        for ( i=LED8 ; i >= LED1 ; i>>=1 )
        {
            change_speed () ;
            at91_pio_write (&PIOB_DESC, i, LED_ON ) ;
            at91_wait_open ( &wait_desc ) ;
            at91_pio_write (&PIOB_DESC, i, LED_OFF ) ;
        }
#ifdef SEMIHOSTING
       printf ( "Loop %d\n", loop_count ) ;
#endif
        loop_count ++ ;
    }
    return(TRUE);
//* End
}

⌨️ 快捷键说明

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