📄 main.c
字号:
/***********************************************************************
file ID :main.c
Version Number :
Project Code :
Project Name :
Architect :ProjectLeader
Designer :
Author :
Date of last updation :02-04-2009
Description :
************************************************************************/
#include "CDAC_uart_tr.h"
static void joystick_init(); //intialize the joy stic pins and interrupts .
static void joystic_handler( void );
void main (void)
{
int i = 0,j=0 ,count = 65 ;
init_all();
joystick_init();
for(;;)
{
for( i = 0 ; i < 3000 ; i ++ ) //just for a delay .
for( j = 0 ; j < 700 ; j++ );
if( count != 96 )
UART_WrByte((char )count++);
else{
count = 65;
UART_WrByte('\n');
UART_WrByte('\r');
}
}
}
/*----------------------------------------------------------------------*/
static void joystick_init()
{
//----------------PIOA initialition.
AT91C_BASE_PMC->PMC_PCER |= 0x1 << AT91C_ID_PIOA; //Enable peripheral clock
AT91C_BASE_PIOA->PIO_PER |= 0x03E00000; //Pioa Enable Register ;Enable PIOA TO CONTROL PINs
AT91C_BASE_PIOA->PIO_ODR |= 0x03E00000; //Output Disale Register ;Output Disabled ,made input pins
AT91C_BASE_PIOA->PIO_PPUER |= 0x03E00000; //pull up P25,p21,p22,p23,p24 .
AT91C_BASE_PIOA->PIO_IER |= 0x03E00000; //Enable Joystick PUSH pins interrupt
//-------------AIC initialition.
AT91C_BASE_AIC->AIC_IDCR |= 0X00000004 ; //disabling interrupts .
AT91C_BASE_AIC->AIC_SVR[(CPU_INT32U)2] = (CPU_INT32U)joystic_handler; //passing the handler address.
AT91C_BASE_AIC->AIC_SMR[(CPU_INT32U)2] = 0X00000027; // +VE EDGE TRIGGER AND PRIORITY 7 (ITS given highets priority).
AT91C_BASE_AIC->AIC_IECR |= 0X00000004; //Enable interrupts . 02
}
/*-----------------------------------------------------------------------*/
static void joystic_handler( void )
{
CPU_INT32U irq_id,temp;
AT91C_BASE_AIC->AIC_IVR = 0 ; //Write the IVR, as required TO CLEAR IT .
irq_id = AT91C_BASE_AIC->AIC_ISR & 0x1F; // Retrieve the ID of the interrupting source ( PIOA )
AT91C_BASE_AIC->AIC_ICCR |= (0x1 << irq_id); // Clear the current interrupt ( PIOA )
temp = AT91C_BASE_PIOA->PIO_ISR ; //reading PIO_ISR value,ISR register indicate a change since last read or reset For the joy stic
temp++;
UART_WrByte('&');
UART_WrByte('\n');
//---------------------------------------------------------------------------------------------------------------
AT91C_BASE_AIC->AIC_ICCR |= 0X00000004; //Clear all interrupts from PIOA.
}//end of ISR.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -