Мучаюсь уже 3 дня, но прога не работает. Код прошивается, но светодиоды не мигают. При этом, если прошить МК уже собранным бинарников, взятым отсюда (
Возможно, ошибка в коде? Но вроде я всё проверил, код элементарный. Или в настройках CrossWorks? Проект собирался и в режиме THUMB, и в режиме ARM.
- Код: Выделить всё • Развернуть
/Simple program that blinking leds
#include "AT91SAM7S64.h"
//#include "system.h"
//#include "system.c"
//#define BIT17 0x00020000
//#define BIT18 0x00040000
#define BIT17 (1<<17);
#define BIT18 (1<<18);
//AT91PS_PMC pPMC = AT91C_BASE_PMC;
AT91PS_PIO p_pPio = AT91C_BASE_PIOA;
AT91PS_PMC p_pPMC = AT91C_BASE_PMC;
AT91PS_USART p_pUSART = AT91C_BASE_US0;
AT91PS_PDC p_pPDC = AT91C_BASE_PDC_US0;
AT91PS_MC p_pMC = AT91C_BASE_MC;
AT91PS_AIC p_pAic = AT91C_BASE_AIC;
//it's a simple delay
void Delay (unsigned long a) { while (--a!=0); }
void InitFrec(void)
{
// Disable watchwog
AT91C_BASE_WDTC->WDTC_WDMR= AT91C_WDTC_WDDIS;
//Enabling the Main Oscillator:
//SCK = 1/32768 = 30.51 uSecond
//Start up time = 8 * 6 / SCK = 56 * 30.51 = 1,46484375 ms
//AT91C_BASE_PMC->PMC_MOR = ...
p_pPMC->PMC_MOR = (( AT91C_CKGR_OSCOUNT & (0x06 <<8) | AT91C_CKGR_MOSCEN ));
//Wait the startup time
while(!(p_pPMC->PMC_SR & AT91C_PMC_MOSCS));
//Setting PLL and divider:
//- div by 5 Fin = 3,6864 =(18,432 / 5)
//- Mul 25+1: Fout = 95,8464 =(3,6864 *26)
//for 96 MHz the erroe is 0.16%
//Field out NOT USED = 0
//PLLCOUNT pll startup time estimate at : 0.844 ms
//PLLCOUNT 28 = 0.000844 /(1/32768)
p_pPMC->PMC_PLLR = ((AT91C_CKGR_DIV & 3) | (AT91C_CKGR_PLLCOUNT & (28<<8)) | (AT91C_CKGR_MUL & (24<<16)));
// Wait the startup time
while(!(p_pPMC->PMC_SR & AT91C_PMC_LOCK));
while(!(p_pPMC->PMC_SR & AT91C_PMC_MCKRDY));
//Selection of Master Clock and Processor Clock
//select the PLL clock divided by 2
p_pPMC->PMC_MCKR = AT91C_PMC_CSS_PLL_CLK | AT91C_PMC_PRES_CLK_2 ;
while(!(p_pPMC->PMC_SR & AT91C_PMC_MCKRDY));
}
void InitPeriphery(void) {
/**** LED BUTTONS ****/
//enable the clock of the PIO
p_pPMC->PMC_PCER = 1 << AT91C_ID_PIOA;
//LED 1
//configure the PIO Lines corresponding to LED1
p_pPio->PIO_PER = BIT17; //Enable PA17
p_pPio->PIO_OER = BIT17; //Configure in Output
p_pPio->PIO_SODR = BIT17; //set reg to 1
//LED 2
//configure the PIO Lines corresponding to LED2
p_pPio->PIO_PER = BIT18; //Enable PA18
p_pPio->PIO_OER = BIT18; //Configure in Output
p_pPio->PIO_SODR = BIT18; //set reg to 1
}
int main()
{
//Init frequency
InitFrec();
//Init leds
InitPeriphery();
// loop forever
while(1)
{
p_pPio->PIO_CODR = BIT18; //set reg to 0 (led2 on)
p_pPio->PIO_SODR = BIT17; //set reg to 1 (led1 off)
Delay(800000); //simple delay
p_pPio->PIO_CODR = BIT17; //set reg to 0 (led1 on)
p_pPio->PIO_SODR = BIT18; //set reg to 1 (led2 off)
Delay(800000); //simple delay
}
}