30 void init_time(void)
31 {
32 TCFG0 = (TCFG0_DZONE(0) | TCFG0_PRE1(15) | TCFG0_PRE0(0));
33 }
|
结合上面的寄存器,然后看init_time函数,则是分别设定timer0死区的长度(死区的用处还不明白),timer的预分频
int ret;
ret = board_init();
GPFDAT = 0X20;
if (ret)
{
putstr("Failed a board_init() procedure\r\n");
error();
}
static void error(void)
{
purstr("Sorry. We can not run vivi\n");
for(; ;);
/* Infinite loop */
}
int board_init(void)
{
/*
*set the timer register:
*the dead zone0 and the prescaler of timer0,1,2,3,4
*/
init_time();
set_gpios();
/*if success, then return 0*/
return 0;
/**/
}
void init_time(void)
{
TCFG0 = (TCFG0_DZONE(0) | TCFG0_PRE1(15) | TCFG0_PRE0(0));
}
void set_gpios(void)
{
GPACON = vGPACON;
GPBCON = vGPBCON;
GPBUP = vGPBUP;
GPCCON = vGPCCON;
GPCUP = vGPCUP;
GPDCON = vGPDCON;
GPDUP = vGPDUP;
GPECON = vGPECON;
GPEUP = vGPEUP;
/* port F[7:4]as the output port, and the bit[3:0]as the extint port */
GPFCON = vGPFCON;
GPFUP = vGPFUP;
GPGCON = vGPGCON;
GPGUP = vGPGUP;
GPHCON = vGPHCON;
GPHUP = vGPHUP;
EXTINT0 = vEXTINT0;
EXTINT1 = vEXTINT1;
EXTINT2 = vEXTINT2;
}
|
到这里step2也就完成了,起主要的作用就是初始化时钟,I/O端口和外部中断为后面的工作做好准备
这里需要注意的就是F端口初始化的时候。F端口为复用端口,可以作为普通的I/O端口来使用,也可作为外部中断口来使用,在我们的初始化中则是使用了4个外部中断端口
The EXTINT register configures the signaling method between the level trigger and edge trigger for the external interrupt request, and also configures the signal polarity.
遮面这段话是2440手册里面的话,说明了3个用来控制外部中断请求的寄存器。通过设定寄存器的值分别来控制外部中断的目的。
#define vEXTINT0 0X22222222
#define vEXTINT1 0X22222222
#define vEXTINT2 0X22222222
这就说明了外部中断为(falling edge triggered),而且(disable filter)
具体的每个端口的配置则需要结合实际的硬件电路来配置(端口是 用来输出或者是输入,当为输出时,则初始化的输出的值为高或者低,是否使能上拉电阻)
阅读(1360) | 评论(0) | 转发(0) |