📄 新建 文本文档.txt
字号:
//*---------------------------------------------------------------------------------------------------------
//* File Name: Timer_interrupt.c
//* Object : AT91EB40A - Timer Counter - Interrupt
//* Author: AT91 Application Group
//*---------------------------------------------------------------------------------------------------------
#define TC1_CCR ((volatile unsigned int *) 0xFFFE0040)
#define TC1_CMR ((volatile unsigned int *) 0xFFFE0044)
#define TC1_RC ((volatile unsigned int *) 0xFFFE005C)
#define TC1_SR ((volatile unsigned int *) 0xFFFE0060)
#define TC1_IER ((volatile unsigned int *) 0xFFFE0064)
#define TC1_IDR ((volatile unsigned int *) 0xFFFE0068)
#define PIO_PER ((volatile unsigned int *) 0xFFFF0000)
#define PIO_OER ((volatile unsigned int *) 0xFFFF0010)
#define PIO_SODR ((volatile unsigned int *) 0xFFFF0030)
#define PIO_CODR ((volatile unsigned int *) 0xFFFF0034)
#define PIO_PDSR ((volatile unsigned int *) 0xFFFF003C)
#define AIC_SMR5 ((volatile unsigned int *) 0xFFFFF014)
#define AIC_SVR5 ((volatile unsigned int *) 0xFFFFF094)
#define AIC_IECR ((volatile unsigned int *) 0xFFFFF120)
#define AIC_IDCR ((volatile unsigned int *) 0xFFFFF124)
#define AIC_ICCR ((volatile unsigned int *) 0xFFFFF128)
#define TC1_ID 5 /* Timer Channel 1 interrupt */
//* TC_CMR: Timer Counter Channel Mode Register Bits Definition
#define TC_CLKS_MCK1024 0x4
#define TC_CPCTRG 0x4000
//* TC_CCR: Timer Counter Control Register Bits Definition
#define TC_CLKEN 0x1
#define TC_CLKDIS 0x2
#define TC_SWTRG 0x4
//* TC_SR: Timer Counter Status Register Bits Definition
#define TC_CPCS 0x10 /* RC Compare Status */
//* AIC_SMR: Interrupt Source Mode Registers
#define AIC_SRCTYPE_INT_LEVEL_SENSITIVE 0x00 /* Level Sensitive */
//* Leds Definition
#define LED1 (1<<16)
#define LED8 (1<<6)
extern void timer1_asm_irq_handler(void);
//*-----------------------------------------------------------------------------
//* Function Name : timer1_c_irq_handler
//* Object : Timer 1 interrupt Handler
//*-----------------------------------------------------------------------------
void timer1_c_irq_handler (void)
//* Begin
{
unsigned int dummy ;
dummy = *TC1_SR; /* Read TC1 Status Register to clear it */
if ( (*PIO_PDSR & LED8) == LED8 )
*PIO_CODR = LED8 ;
else
*PIO_SODR = LED8 ;
}
//* End
void delay (void)
{
unsigned int i;
for (i=0; i<1000000 ; i++);
}
//*-----------------------------------------------------------------------------
//* Function Name : main
//* Object : AT91 - Timer Counter- PWM generation
//* Input Parameters : none
//* Output Parameters : none
//* Functions called : none
//*-----------------------------------------------------------------------------
int main ( void )
//* Begin
{
unsigned int dummy ;
*PIO_PER = LED8 | LED1 ; /* Enable the PIO/LED8 pin */
*PIO_OER = LED8 | LED1; /* Enable the PIO/LED8 pin as Output */
*PIO_CODR = LED8 | LED1 ; /* Set LED8 */
// Timer1 Init
*TC1_CCR = TC_CLKDIS ; /* Disable the Clock Counter */
*TC1_IDR = 0xFFFFFFFF ;
dummy = *TC1_SR ;
*TC1_CMR = TC_CLKS_MCK1024 |TC_CPCTRG ;
*TC1_CCR = TC_CLKEN ; /* Enable the Clock counter */
*TC1_IER = TC_CPCS ; /* Validate the RC compare interrupt */
*AIC_IDCR = (1<<TC1_ID) ; /* Disable timer 1 interrupt at AIC level */
*AIC_SVR5 = (unsigned int) timer1_asm_irq_handler ; /* Set the TC1 IRQ handler address */
*AIC_SMR5 = ( AIC_SRCTYPE_INT_LEVEL_SENSITIVE | 0x4 ); /* Set the trigg and priority for TC1 interrupt */
*AIC_ICCR = (1<<TC1_ID) ; /* Clear the TC1 interrupt */
*AIC_IECR = (1<<TC1_ID) ; /* Enable the TC1 interrupt */
*TC1_RC = 0xFBC5;
*TC1_CCR = TC_SWTRG ;
while (1)
{
*PIO_CODR = LED1 ;
delay();
*PIO_SODR = LED1 ;
delay();
}
return(0) ;
}//*End
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -