1、IO控制
将相应的管脚设置成输出:
//首先使能PIO控制
AT91C_BASE_PIO->PIO_PER = pio;
//设置pio为输出口
AT91C_BASE_PIO->PIO_OER = pio;
将相应的管脚设置成输入:
//首先使能PIO控制
AT91C_BASE_PIO->PIO_PER = pio;
//设置pio为输出禁止口,即输入口。
AT91C_BASE_PIO->PIO_ODR = pio;
禁止相应的管脚:
//禁止PIO控制
AT91C_BASE_PIO->PIO_PDR = pio;
将某管脚设置输出高电平
void IOSet(Uint32 pio)
{
AT91C_BASE_PIO->PIO_SODR = pio;
}
将某管脚设置输出地电平
void IOClr(Uint32 pio)
{
AT91C_BASE_PIO->PIO_CODR = pio;
}
2、点亮发光二极管子程序
int main(void)
{
AT91C_BASE_PIO->PIO_PER =PIO0;
//设置pio为输出口
AT91C_BASE_PIO->PIO_OER = PIO0;
while(1)
{
//AT91C_BASE_PIO->PIO_SODR = PIO0;
AT91C_BASE_PIO->PIO_CODR = PIO0;//将PIO0设置成低电平,低电平二极管点亮
}
}
3、定时器0
中断安装函数
void Int_Install(void)
{
AT91C_BASE_AIC->AIC_IDCR = ALL_IRQ; // In initializing ,disable all interrupt
// initialize interrupt mode
AT91C_BASE_AIC->AIC_SMR[0] = AIC_SRCTYPE_EXT_NEGATIVE_EDGE; // FIQ
AT91C_BASE_AIC->AIC_SMR[1] = AIC_SRCTYPE_INT_EDGE_TRIGGERED | 0x00; // SWI
AT91C_BASE_AIC->AIC_SMR[2] = AIC_SRCTYPE_INT_EDGE_TRIGGERED | 0x03; // USART0
AT91C_BASE_AIC->AIC_SMR[3] = AIC_SRCTYPE_INT_EDGE_TRIGGERED | 0x02; // USART1
AT91C_BASE_AIC->AIC_SMR[4] = AIC_SRCTYPE_INT_EDGE_TRIGGERED | 0x07; // TC0
AT91C_BASE_AIC->AIC_SMR[5] = AIC_SRCTYPE_INT_EDGE_TRIGGERED | 0x04; // TC1
AT91C_BASE_AIC->AIC_SMR[6] = AIC_SRCTYPE_INT_EDGE_TRIGGERED | 0x04; // TC2
AT91C_BASE_AIC->AIC_SMR[7] = AIC_SRCTYPE_INT_EDGE_TRIGGERED | 0x07; // WDT
AT91C_BASE_AIC->AIC_SMR[8] = AIC_SRCTYPE_INT_EDGE_TRIGGERED | 0x01; // Parrel
AT91C_BASE_AIC->AIC_SMR[16] = AIC_SRCTYPE_EXT_HIGH_LEVEL | 0x04; //
AT91C_BASE_AIC->AIC_SMR[17] = AIC_SRCTYPE_EXT_HIGH_LEVEL | 0x05; //
AT91C_BASE_AIC->AIC_SMR[18] = AIC_SRCTYPE_EXT_LOW_LEVEL | 0x05; //
// Setup interrupt handlers
AT91C_BASE_AIC->AIC_SVR[0] = (unsigned int) FIQ_Manual_SW;
AT91C_BASE_AIC->AIC_SVR[1] = (unsigned int) INT_SWI;
AT91C_BASE_AIC->AIC_SVR[2] = (unsigned int) INT_USART0;
AT91C_BASE_AIC->AIC_SVR[3] = (unsigned int) INT_USART1;
AT91C_BASE_AIC->AIC_SVR[4] = (unsigned int) INT_TC0;
AT91C_BASE_AIC->AIC_SVR[5] = (unsigned int) INT_TC1;
AT91C_BASE_AIC->AIC_SVR[6] = (unsigned int) INT_TC2;
AT91C_BASE_AIC->AIC_SVR[7] = (unsigned int) INT_WDT;
AT91C_BASE_AIC->AIC_SVR[8] = (unsigned int) INT_PIO;
AT91C_BASE_AIC->AIC_SVR[16] = (unsigned int) IRQ_EX0;
AT91C_BASE_AIC->AIC_SVR[17] = (unsigned int) IRQ_EX1;
AT91C_BASE_AIC->AIC_SVR[18] = (unsigned int) IRQ_EX2;
AT91C_BASE_AIC->AIC_SPU = (unsigned int) INT_SPU;
}
定时器初始化
void TC0Init(Uint16 time)
{
//TCBlock.TC_BMR |= TC_NONEXC0; /* non extern clock signal */
(* AT91C_TCB0_BMR) |= TC_NONEXC0; /* non extern clock signal */
AT91C_BASE_TC0->TC_CMR = TC_CLKS_MCK1024 | TC_CPCTRG;
AT91C_BASE_TC0->TC_RC = time * (TC_CLKS_MCK >> 10) / 1000;
AT91C_BASE_TC0->TC_IDR = TC_COVFS | TC_LOVRS | TC_LDRAS | TC_LDRBS | TC_ETRGS; /* disable unused interrupt */
AT91C_BASE_TC0->TC_IER = TC_CPCS;
AT91C_BASE_TC0->TC_CCR = TC_CLKEN | TC_SWTRG;
}
定时器中断处理函数
void TC0_Handler(void)
{
volatile int i;
SysTime++;
if(SysTime > 1 * 60 * 1000 / 10)
{
ONEminute = 1;//定时一分钟标志
}
if(SysTime > 15 * 1000 / 10)
{
gFiftminute = 1;
}
i = AT91C_BASE_TC0->TC_SR;
}
定时器中断使能
void EnableInt(Uint8 n)
{
AT91C_BASE_AIC->AIC_IECR = 1 << n;
}
4、看门狗x5043的相关操作
要正常使用看门狗定时器,需要完成以下几步的操作:
看门狗初始化:
wdt_init();
设置看门狗定时器的中断时间:
void WDT_SetTime(Uint8 rstTime);
开启看门狗并设置模式:
wdt_settime(600, 0x55);
最后可以在看门狗中断中做相关的处理:
// Internal watchdog interrupt
void WDT_Handler(void)
{
}
阅读(823) | 评论(0) | 转发(0) |