main.c 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. #include "Board.h"
  2. void timer_init ( void );
  3. /* Global variables */
  4. #define SPEED (MCKKHz/10)
  5. unsigned int LedSpeed = SPEED *50 ;
  6. const int led_mask[8]= {LED1, LED2, LED3, LED4};
  7. //*--------------------------------------------------------------------------------------
  8. //* Function Name : change_speed
  9. //* Object : Adjust "LedSpeed" value depending on SW1 and SW2 are pressed or not
  10. //* Input Parameters : none
  11. //* Output Parameters : Update of LedSpeed value.
  12. //*--------------------------------------------------------------------------------------
  13. void change_speed(void) {
  14. if ( (AT91F_PIO_GetInput(AT91C_BASE_PIOA) & SW1_MASK) == 0 ) {
  15. if ( LedSpeed > SPEED ) {
  16. LedSpeed -= SPEED ;
  17. }
  18. }
  19. if ( (AT91F_PIO_GetInput(AT91C_BASE_PIOA) & SW3_MASK) == 0 ) {
  20. if ( LedSpeed < MCK ) {
  21. LedSpeed += SPEED ;
  22. }
  23. }
  24. }
  25. //*--------------------------------------------------------------------------------------
  26. //* Function Name : wait
  27. //* Object : Software waiting loop
  28. //* Input Parameters : none. Waiting time is defined by the global variable LedSpeed.
  29. //* Output Parameters : none
  30. //*--------------------------------------------------------------------------------------
  31. void wait(void) {
  32. unsigned int waiting_time;
  33. change_speed();
  34. for(waiting_time = 0; waiting_time < LedSpeed; waiting_time++) ;
  35. }
  36. //*--------------------------------------------------------------------------------------
  37. //* Function Name : Main
  38. //* Object : Software entry point
  39. //* Input Parameters : none.
  40. //* Output Parameters : none.
  41. //*--------------------------------------------------------------------------------------
  42. int main() {
  43. int i;
  44. // First, enable the clock of the PIO
  45. AT91F_PMC_EnablePeriphClock ( AT91C_BASE_PMC, 1 << AT91C_ID_PIOA ) ;
  46. // then, we configure the PIO Lines corresponding to LED1 to LED4
  47. // to be outputs. No need to set these pins to be driven by the PIO because it is GPIO pins only.
  48. AT91F_PIO_CfgOutput( AT91C_BASE_PIOA, LED_MASK ) ;
  49. // Clear the LED's. On the EB55 we must apply a "1" to turn off LEDs
  50. AT91F_PIO_SetOutput( AT91C_BASE_PIOA, LED_MASK ) ;
  51. //* Init timer interrupt
  52. timer_init();
  53. // Loop forever
  54. for (;;) { // Once a Shot on each led
  55. for ( i=0 ; i < NB_LEB ; i++ ) {
  56. AT91F_PIO_ClearOutput( AT91C_BASE_PIOA, led_mask[i]);
  57. wait();
  58. AT91F_PIO_SetOutput( AT91C_BASE_PIOA, led_mask[i] );
  59. wait();
  60. }
  61. // Once a Shot on each led
  62. for ( i = (NB_LEB - 1) ; i >= 0 ; i-- ) {
  63. AT91F_PIO_ClearOutput( AT91C_BASE_PIOA, led_mask[i]);
  64. wait();
  65. AT91F_PIO_SetOutput( AT91C_BASE_PIOA, led_mask[i]);
  66. wait();
  67. }
  68. }
  69. }