#include <AT91SAM7S256.h>
#define nop() __asm__ __volatile__("nop")
#define LED (1<<0) // PA0
#define INPUT_PIN (1<<1) // PA1
#define INT_PIN (1<<2) // PA2
static void initialize( void);
void delay_us( int time);
void delay_ms( int time);
int main(void)
{
int delay = 100;
volatile long input;
initialize();
enableIRQ();
volatile AT91PS_PIO pPIOA = AT91C_BASE_PIOA;
while(1)
{
input = pPIOA->PIO_PDSR; //for debugging. Watch input variable to check if inputs working.
if(( pPIOA->PIO_PDSR & INPUT_PIN) == INPUT_PIN)
delay = 1000;
else
delay = 100;
pPIOA->PIO_CODR = LED;
delay_ms(delay);
pPIOA->PIO_SODR = LED;
delay_ms(delay);
}
}
static void initialize(void)
{
//Turn on the peripheral clock. Without this on, inputs do not actually register in the PDSR register
volatile AT91PS_PMC pPMC = AT91C_BASE_PMC; // pointer to PMC data structure
pPMC->PMC_PCER = (1<<AT91C_ID_PIOA); // enable Timer0 peripheral clock
volatile AT91PS_PIO pPIOA = AT91C_BASE_PIOA;
pPIOA->PIO_PER = (LED | INPUT_PIN); // Set PIO to control LED and button.
// Initialize Input
pPIOA->PIO_ODR = INPUT_PIN ; // Disable outputs for INPUT pins. (not needed as all pins default input on reset)
pPIOA->PIO_PPUER = INPUT_PIN; //Pullup Enable (not needed as all pullups are enabled on reset)
// Initialize Output
pPIOA->PIO_OER = LED; // Enable output for LED.
pPIOA->PIO_SODR = LED; // Turn LED off.
pPIOA->PIO_PPUDR = LED; //Pullup disable
}
void delay_us(int delay)
{
while(delay--)
{
__asm volatile (" NOP");
__asm volatile (" NOP");
__asm volatile (" NOP");
__asm volatile (" NOP");
__asm volatile (" NOP");
__asm volatile (" NOP");
__asm volatile (" NOP");
__asm volatile (" NOP");
__asm volatile (" NOP");
__asm volatile (" NOP");
__asm volatile (" NOP");
__asm volatile (" NOP");
__asm volatile (" NOP");
}
}
void delay_ms(int delay)
{
char i;
while(delay--)
{
for(i=0; i<4; i++)
{
delay_us(250);
}
}
}
Hi Mark
This is an excellent post... although I do not understand the 1U bit. Thanks. It seems to do (simply) what Atmel want to do in a way too complicated way. I will plug it into my IAR compiler and see how I get on.
Incidentally, do you understand the following line?
#define PIN_LED_DS1 {1 << 0, AT91C_BASE_PIOA, AT91C_ID_PIOA, PIO_OUTPUT_1, PIO_DEFAULT}
Because all the registers are 32bit, they have registers that all they do is one way toggle (set or clear) other registers. They also have registers that you can directly write to like you would a PIC, and they have mask registers so that you can mask off specific areas of the registers so you don't effect everything with your writes.Also, another thing that has been buggin' me. Why does the ARM have an enable register AND a disable register for all the config registers?
#include "AT91SAM7S256.h"
#define nop() __asm__ __volatile__("nop")
#define LED (1<<0) // PA0
#define INPUT_PIN (1<<1) // PA1
#define INT_PIN (1<<2) // PA2
static void initialize( void);
void delay_us( int time);
void delay_ms( int time);
int main(void)
{
int delay = 100;
volatile long input;
initialize();
volatile AT91PS_PIO pPIOA = AT91C_BASE_PIOA;
while(1)
{
input = pPIOA->PIO_PDSR; //for debugging. Watch input variable to check if inputs working.
if(( pPIOA->PIO_PDSR & INPUT_PIN) == INPUT_PIN)
delay = 1000;
else
delay = 100;
pPIOA->PIO_CODR = LED;
delay_ms(delay);
pPIOA->PIO_SODR = LED;
delay_ms(delay);
}
}
static void initialize(void)
{
//Turn on the peripheral clock. Without this on, inputs do not actually register in the PDSR register
volatile AT91PS_PMC pPMC = AT91C_BASE_PMC; // pointer to PMC data structure
pPMC->PMC_PCER = (1<<AT91C_ID_PIOA); // enable Timer0 peripheral clock
volatile AT91PS_PIO pPIOA = AT91C_BASE_PIOA;
pPIOA->PIO_PER = (LED | INPUT_PIN); // Set PIO to control LED and button.
// Initialize Input
pPIOA->PIO_ODR = INPUT_PIN ; // Disable outputs for INPUT pins. (not needed as all pins default input on reset)
pPIOA->PIO_PPUER = INPUT_PIN; //Pullup Enable (not needed as all pullups are enabled on reset)
// Initialize Output
pPIOA->PIO_OER = LED; // Enable output for LED.
pPIOA->PIO_SODR = LED; // Turn LED off.
pPIOA->PIO_PPUDR = LED; //Pullup disable
}
void delay_us(int delay)
{
while(delay--)
{
__asm volatile (" NOP");
__asm volatile (" NOP");
__asm volatile (" NOP");
__asm volatile (" NOP");
__asm volatile (" NOP");
__asm volatile (" NOP");
__asm volatile (" NOP");
__asm volatile (" NOP");
__asm volatile (" NOP");
__asm volatile (" NOP");
__asm volatile (" NOP");
__asm volatile (" NOP");
__asm volatile (" NOP");
}
}
void delay_ms(int delay)
{
char i;
while(delay--)
{
for(i=0; i<4; i++)
{
delay_us(250);
}
}
}
could any one goive me free Asemler for ARM based MCUs
Thanks once again and you did not have to photograph the LED working - I believed you! The screenshot of your register settings was most helpful though!
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?