📄 led_swing.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 AT91EB42
//*
//* 1.0 03/10/01 PFi : Creation
//*--------------------------------------------------------------------------------------
/****************************************************************************************
* Information : If the "SEMIHOSTING" FLAG is set, when the debugger (ARM SDT or ARM ADS)
* is started * you have to set "$top_of_memory=0x2040000" in the Debugger Internals window
*****************************************************************************************/
#ifdef SEMIHOSTING
#include <stdio.h>
#endif
#include "parts/m42800/lib_m42800.h"
#include "drivers/capture/capture.h"
#include "drivers/wait/wait.h"
#include "targets/eb42/eb42.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_SW3) ) == 0 )
{
if ( LedSpeed < 2000000 ) LedSpeed +=1000 ;
}
}
//* End
//*--------------------------------------------------------------------------------------
//* Function Name : main
//* Object : Main function of the led swing
//* Input Parameters : none
//* Output Parameters : True
//*--------------------------------------------------------------------------------------
int main( void )
//* Begin
{
u_int loop_count = 0 ;
u_int i ;
LedSpeed = 80000 ;
//* -- Set up PIO
at91_pio_open ( &PIOB_DESC, LED_MASK, PIO_OUTPUT ) ;
at91_pio_write (&PIOB_DESC, LED_MASK, LED_OFF ) ;
//* Detect Master Clock
wait_desc.mcki_khz = 32768 ;
//* 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 + -