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

📄 main.c

📁 前段时间做了一个AT91M55800的芯片测试
💻 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           : main.c
//* Object              : main application written in C
//* Creation            : PFi   16/Oct/2002
//* Clean up            : JPP   10/dec/2002
//*----------------------------------------------------------------------------
#include "AT91M55800A.h"
#include "lib_AT91M55800A.h"
#include "eb55.h"

/* Global variables */
#define SPEED 		(MCKKHz/100)
unsigned int LedSpeed = SPEED *100 ;

//*--------------------------------------------------------------------------------------
//* Function Name       : change_speed
//* Object              : Adjust "LedSpeed" value depending on SW1 and SW2 are pressed or not
//* Input Parameters    : none
//* Output Parameters   : Update of LedSpeed value.
//*--------------------------------------------------------------------------------------
void change_speed ( void )
//* Begin
{
    if ( (AT91F_PIO_GetInput(AT91C_BASE_PIOB) & SW1_MASK) == 0 )
    {
        if ( LedSpeed > SPEED ) LedSpeed -=SPEED ;
    }
    if ( (AT91F_PIO_GetInput(AT91C_BASE_PIOB) & SW3_MASK) == 0 )
    {
        if ( LedSpeed < MCK ) LedSpeed +=SPEED ;
    }
}
//* End

//*--------------------------------------------------------------------------------------
//* Function Name       : wait
//* Object              : Software waiting loop
//* Input Parameters    : none. Waiting time is defined by the global variable LedSpeed.
//* Output Parameters   : none
//*--------------------------------------------------------------------------------------
void wait ( void )
//* Begin
{
    unsigned int waiting_time ;
    
    for(waiting_time = 0; waiting_time < LedSpeed; waiting_time++) ;
}
//* End

//*--------------------------------------------------------------------------------------
//* Function Name       : Main
//* Object              : Software entry point 
//* Input Parameters    : none. 
//* Output Parameters   : none.
//*--------------------------------------------------------------------------------------
int main()
{
    unsigned int led_index ;

    // First, enable the clock of the PIOB
    AT91F_APMC_EnablePeriphClock ( AT91C_BASE_APMC, 1<<AT91C_ID_PIOB ) ;

    // then, we configure the PIO Lines corresponding to LED1 to LED8
    // to be outputs. No need to set these pins to be driven by the PIO because it is GPIO pins only.
    AT91F_PIO_CfgOutput( AT91C_BASE_PIOB, LED_MASK ) ;

    // Clear the LED's. On the EB55 we must apply a "1" to turn off LEDs
    AT91F_PIO_SetOutput( AT91C_BASE_PIOB, LED_MASK ) ;
    
    //* Loop forever
    for (;;)
    {
		// Now, we can start to give one shoot on each LED
		// from LED1 to LED8
		for (led_index = LED1 ; led_index < LED8  ; led_index <<=1)
		{
            change_speed () ;
	    	AT91F_PIO_ClearOutput( AT91C_BASE_PIOB, led_index ) ;
	    	wait();
	    	AT91F_PIO_SetOutput( AT91C_BASE_PIOB, led_index ) ;
	    	wait();
		}
	
		// from LED8 to LED1
        for ( led_index =LED8 ; led_index  >= LED1 ; led_index >>=1 )
        {
            change_speed () ;
	   		AT91F_PIO_ClearOutput( AT91C_BASE_PIOB, led_index ) ;
	    	wait();
	    	AT91F_PIO_SetOutput( AT91C_BASE_PIOB, led_index ) ;
	    	wait();
        }
    }
	
}

⌨️ 快捷键说明

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