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

📄 led_blink.c

📁 ARM入门的好帮手.包含了从简单到相对较复杂的程序.
💻 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_blink.c
//* Object              : Led Blinking for the AT91EB40, use PIO in input and
//*                       output
//*
//* 1.0 10/10/00 JCZ    : Creation
//*----------------------------------------------------------------------------

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

#include    "parts/r40807/lib_r40807.h"
#include    "targets/eb40/eb40.h"

//*----------------------------------------------------------------------------
//* Function Name       : delay
//* Object              : Wait
//* Input Parameters    : none
//* Output Parameters   : none
//* Functions called    : at91_pio_read
//*----------------------------------------------------------------------------
void delay ( void )
{
    u_int    i ;

    //* loop delay
    for ( i = 0 ;(i < 30000);i++ ) ;

    //* loop delay when SW4 is released
    for ( i = 0 ;
          (i < 10000) &&  (( at91_pio_read ( &PIO_DESC) & SW4_MASK ) != SW4_MASK );
          i++ ) ;

    //* while SW3 is push wait
    while ( ( at91_pio_read ( &PIO_DESC) & SW3_MASK ) == SW3_MASK );

    //* while SW5 is push wait
    while ( ( at91_pio_read ( &PIO_DESC) & SW5_MASK ) == SW5_MASK );

}

//*----------------------------------------------------------------------------
//* Function Name       : main
//* Object              : Main function of the led blink
//* Input Parameters    : none
//* Output Parameters   : TRUE
//* Functions called    : at91_pio_open, at91_pio_write, delay
//*----------------------------------------------------------------------------
int main( void )
//* Begin
{
    u_int   loop_count = 0 ;

    //* define led at PIO output
    at91_pio_open ( &PIO_DESC, LED_MASK, PIO_OUTPUT );

    //* define switch at PIO input
    at91_pio_open ( &PIO_DESC, SW_MASK, PIO_INPUT );

    for (;;)
    {
        at91_pio_write ( &PIO_DESC, LED1, LED_OFF );

        delay () ;

        at91_pio_write ( &PIO_DESC, LED2, LED_OFF );

        delay () ;

        at91_pio_write ( &PIO_DESC, LED3, LED_OFF );

        delay () ;

        at91_pio_write ( &PIO_DESC, LED1, LED_ON );

        delay () ;

        at91_pio_write ( &PIO_DESC, LED2, LED_ON );

        delay () ;
        at91_pio_write ( &PIO_DESC, LED3, LED_ON );

        delay () ;


#ifdef SEMIHOSTING
       printf ( "Loop %d\n", loop_count ) ;
#endif
        loop_count ++ ;
    }
    return(TRUE);
//* End
}

⌨️ 快捷键说明

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