Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
Hi,
Look at the data sheet for register description.
You need to configure pin as output and write data to output register in order to change state
/******************************************************************************/
/* BLINKY.C: LED Flasher */
/******************************************************************************/
/* This file is part of the uVision/ARM development tools. */
/* Copyright (c) 2005-2006 Keil Software. All rights reserved. */
/* This software may only be used under the terms of a valid, current, */
/* end user licence from KEIL for a compatible version of KEIL software */
/* development tools. Nothing else gives you the right to use this software. */
/******************************************************************************/
#include <AT91SAM7S64.H> /* AT91SAMT7S64 definitions */
#include "..\Board.h"
#define SPEED (MCKKHz/10)
const int led_mask[] = { LED1, LED2, LED3, LED4 };
unsigned int LEDSpeed = 50*SPEED;
/*
* Change Speed depending on SW1 and SW2
*/
void change_speed (void) {
if ((AT91C_BASE_PIOA->PIO_PDSR & SW1_MASK) == 0) {
if (LEDSpeed > SPEED) LEDSpeed -= SPEED;
}
if ((AT91C_BASE_PIOA->PIO_PDSR & SW2_MASK) == 0) {
if (LEDSpeed < MCK) LEDSpeed += SPEED;
}
}
/*
* Wait Function (SW Waiting Loop)
* Waiting Time defined by global variable LEDSpeed
*/
void wait (void) {
unsigned int n;
change_speed();
for (n = 0; n < LEDSpeed; n++);
}
/*
* Main Program
*/
int main (void) {
int i;
// Enable the Clock of the PIO
AT91C_BASE_PMC->PMC_PCER = 1 << AT91C_ID_PIOA;
// Configure the PIO Lines corresponding to LED1..LED4 as Outputs
AT91C_BASE_PIOA->PIO_PER = LED_MASK;
AT91C_BASE_PIOA->PIO_OER = LED_MASK;
// Clear the LED's. On the Board we must apply a "1" to turn off LEDs
AT91C_BASE_PIOA->PIO_SODR = LED_MASK;
// Loop forever
for (;;) {
for (i = 0; i < NB_LED; i++) {
AT91C_BASE_PIOA->PIO_CODR = led_mask[i];
wait();
AT91C_BASE_PIOA->PIO_SODR = led_mask[i];
wait();
}
for (i = (NB_LED - 1); i >= 0; i--) {
AT91C_BASE_PIOA->PIO_CODR = led_mask[i];
wait();
AT91C_BASE_PIOA->PIO_SODR = led_mask[i];
wait();
}
}
}