⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 main.c

📁 EMB91SAM7S64开发板(全套资料)
💻 C
字号:
//*----------------------------------------------------------------------------
//*         ATMEL Microcontroller Software Support  -  ROUSSET  -
//*----------------------------------------------------------------------------
//* The software is delivered "AS IS" without warranty or condition of any
//* kind, either express, implied or statutory. This includes without
//* limitation any warranty or condition with respect to merchantability or
//* fitness for any particular purpose, or against the infringements of
//* intellectual property rights of others.
//*----------------------------------------------------------------------------
//* File Name           : main.c
//* Object              : main application written in C
//* 1.0 24/Jun/04 JPP   : Creation
//*
//*----------------------------------------------------------------------------

// Include Standard LIB  files
#include "Board.h"
#include "dbgu.h"
#include <stdio.h>

#define ALARM_INC			4
#define RTTC_INTERRUPT_LEVEL		0

//*----------------------------------------------------------------------------
//* Function Name       : Real_Time_Timer_handler
//* Object              : C handler interrupt function called by the interrupts
//*                       assembling routine
//*----------------------------------------------------------------------------
void Real_Time_Timer_handler(void)
{
    unsigned int status;


    status = AT91C_BASE_RTTC->RTTC_RTSR;

    if ( (status & AT91C_SYSC_ALMS) == AT91C_SYSC_ALMS)
    {
		AT91F_DBGU_Printk("*");
	//* Read the output state
	//* Set the Alarm At 3 seconde
        AT91C_BASE_RTTC->RTTC_RTAR += ALARM_INC;

		if ((AT91F_PIO_GetInput(AT91C_BASE_PIOA) & LED1 ) == LED1 )   AT91F_PIO_ClearOutput( AT91C_BASE_PIOA, LED1 );
        else  AT91F_PIO_SetOutput( AT91C_BASE_PIOA, LED1 );
    }
    if ( (status & AT91C_SYSC_RTTINC) == AT91C_SYSC_RTTINC)
    {
        AT91F_DBGU_Printk("-");
	//* Read the output state
	if ((AT91F_PIO_GetInput(AT91C_BASE_PIOA) & LED2 ) == LED2 )   AT91F_PIO_ClearOutput( AT91C_BASE_PIOA, LED2 );
        else  AT91F_PIO_SetOutput( AT91C_BASE_PIOA, LED2 );
    }
}

//*----------------------------------------------------------------------------
//* Function Name       : main
//* Object              : Main interrupt function
//*		level timer 0 => 1
//*	SW2	level Irq0    => 2
//*		level timer 1 => 4
//*	SW4	level PIOA    => 6
//*		level USART   => 7
//*		LEVEL FIQ     => MAX
//* Input Parameters    : none
//* Output Parameters   : TRUE
//*----------------------------------------------------------------------------
int main( void )
//* Begin
{
		char message[80],val;
		unsigned int value;
        
        AT91F_DBGU_Init();
        
		AT91F_DBGU_Printk("\n\r================================================");
		AT91F_DBGU_Printk("\n\r==         欢迎使用英贝德公司的产品           ==");
		AT91F_DBGU_Printk("\n\r==         EBD7S64 RealTimeTimer演示测试         ==");
		AT91F_DBGU_Printk("\n\r==   更多的的帮助请到 http://www.szembed.com  ==");		
		AT91F_DBGU_Printk("\n\r================================================\n\r");                 

    	// First, enable the clock of the PIOB
    	AT91F_PMC_EnablePeriphClock ( AT91C_BASE_PMC, 1 << AT91C_ID_PIOA ) ;

   	//* then, we configure the PIO Lines corresponding to LED1 to LED8
   	//* to be outputs. No need to set these pins to be driven by the PIO because it is GPIO pins only.
    	AT91F_PIO_CfgOutput( AT91C_BASE_PIOA, LED_MASK ) ;
   	//* Clear the LED's. On the EB55 we must apply a "1" to turn off LEDs
   	   AT91F_PIO_SetOutput( AT91C_BASE_PIOA, LED_MASK ) ;
   	   
    //* Set Timer
	AT91F_AIC_ConfigureIt ( AT91C_BASE_AIC, AT91C_ID_SYS, RTTC_INTERRUPT_LEVEL,AT91C_AIC_SRCTYPE_INT_EDGE_TRIGGERED, Real_Time_Timer_handler);
	//* Set the Alarm At 3 seconde
	AT91C_BASE_RTTC->RTTC_RTAR = ALARM_INC;

	//* Set the interrupt
	AT91C_BASE_RTTC->RTTC_RTMR = AT91C_SYSC_ALMIEN | AT91C_SYSC_RTTINCIEN | AT91C_SYSC_RTTRST | 0x8000;  //  IRQ enable CPC
	//*  RTTC_RTAR
	AT91F_AIC_EnableIt (AT91C_BASE_AIC, AT91C_ID_SYS);
    //* Infinit loop
    
    for (;;)
    {
    	//* Interrupt Acknowledge
    	if (AT91F_DBGU_Get(&val))
    	{
    		value = AT91C_BASE_RTTC->RTTC_RTVR;
       		sprintf(message,"RTVR %d\n\r",value );
       		AT91F_DBGU_Printk(message);
			value = AT91C_BASE_RTTC->RTTC_RTAR; 	// Real-time Alarm Register
       		sprintf(message,"RTVR %d \n\r",value);
       		AT91F_DBGU_Printk(message);
       	}
    }

//* End
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -