📄 blinky.c
字号:
/******************************************************************************/
/* 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 <AT91SAM9261.H> /* AT91SAM9261 definitions */
#include <lib_AT91SAM9261.h> /* Library function definitions */
#define CLOCK_FREQ 96109714 /* Main clock frequency in Hz */
#define LED_NUM 2 /* Number of user LEDs */
const int led_mask[] = { AT91C_PIO_PA14, AT91C_PIO_PA13 };
volatile char TimeFlag;
volatile long TimeTick;
/*
* Waiting until TimeFlag is activated
*/
void wait (void) {
while (!TimeFlag);
TimeFlag = 0;
}
/*
* Period Interrupt Timer (PIT) - interrupt function (every ~10 ms)
* Activate TimeFlag (every ~10ms * 100)
*/
__irq void PIT_Handler (void) {
if (TimeTick++ >= 100) {
TimeFlag = 1;
TimeTick = 0;
}
*AT91C_AIC_EOICR = AT91C_BASE_PITC->PITC_PIVR;
}
/*
* Main Program
*/
int main (void) {
int i;
// Enable the Clock of the PIO for LEDs
AT91C_BASE_PMC->PMC_PCER = 1 << AT91C_ID_PIOA;
// Configure the PIO Lines corresponding to LEDS DS7 and DS8 as Outputs
AT91C_BASE_PIOA->PIO_OER = led_mask[0] | led_mask[1];
// Clear the LED's. On the Board we must apply a "1" to turn off LEDs
AT91C_BASE_PIOA->PIO_SODR = led_mask[0] | led_mask[1];
// System Timer initialization
AT91C_BASE_SYS->PITC_PIMR = CLOCK_FREQ/16/100; // Interrupt time interval ~10 ms
AT91C_BASE_SYS->PITC_PIMR |= AT91C_PITC_PITIEN;
AT91C_BASE_AIC->AIC_SVR[AT91C_ID_SYS] = (unsigned int) PIT_Handler;
AT91C_BASE_AIC->AIC_SMR[AT91C_ID_SYS] = AT91C_AIC_SRCTYPE_INT_LEVEL_SENSITIVE;
// Enable ST interrupt
AT91C_BASE_AIC->AIC_IECR = (1<<AT91C_ID_SYS);
// Run System Timer
AT91C_BASE_SYS->PITC_PIMR |= AT91C_PITC_PITEN;
// Loop forever
for (;;) {
for (i = 0; i < LED_NUM; i++) {
AT91C_BASE_PIOA->PIO_CODR = led_mask[i];
wait();
AT91C_BASE_PIOA->PIO_SODR = led_mask[i];
wait();
}
for (i = (LED_NUM - 1); i >= 0; i--) {
AT91C_BASE_PIOA->PIO_CODR = led_mask[i];
wait();
AT91C_BASE_PIOA->PIO_SODR = led_mask[i];
wait();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -