管理提醒: 本帖被 xoom 执行取消置顶操作(2011-11-14)
裸机程序,实现K1到K8按键中断触发,串口发送识别信息。
#include "S3c6410_addr.h"
#include "utils.h"
#include "Interrupt.h"
void key_Init(void) //定义PIN脚位中断脚,并设置中断触发类型,使能中断。
{
rGPNCON = (rGPNCON & ~(0xfffU)) | 0xaaa; //K1--K6
rGPLCON1 = (rGPLCON1 & ~(0xff<<12)) | (0x33<<12); //K7,K8
rEINT0CON0 =(rEINT0CON0 & ~(0xfffU)) |0x222; //下降沿触发
rEINT0CON1 =(rEINT0CON1 & ~(0xff<<4)) |(0x22<<4);
rEINT0MASK &= ~0x18003f; //中断使能
}
void KeyIntHandle(void) __irq //中断函数
{
if(rEINT0PEND & 0x01)
Uart_Printf("K1. \n");
if(rEINT0PEND & 0x02)
Uart_Printf("K2. \n");
if(rEINT0PEND & 0x04)
Uart_Printf("K3. \n");
if(rEINT0PEND & 0x08)
Uart_Printf("K4. \n");
if(rEINT0PEND & 0x10)
Uart_Printf("K5. \n");
if(rEINT0PEND & 0x20)
Uart_Printf("K6. \n");
if(rEINT0PEND & 0x80000)
Uart_Printf("K7. \n");
if(rEINT0PEND & 0x100000)
Uart_Printf("K8. \n");
Uart_Printf("KeyIntHandle rEINT0PEND %d. \n",rEINT0PEND);
rEINT0PEND |= 0x18003f; //中断状态寄存器写1清0
INTC_ClearVectAddr(); //清空中断向量表中的状态标志
//Uart_Printf("KeyIntHandle rVIC0ADDR %d. \n",rVIC0ADDR);
}
void _main(void)
{
Uart_Init();
Port_Init();
key_Init();
INTC_Init();
INTC_SetIntISR(0, KeyIntHandle); //往中断向量地址寄存器中写入中断函数地址
INTC_SetIntISR(1, KeyIntHandle);
INTC_SetIntISR(32, KeyIntHandle);
INTC_SetIntISR(33, KeyIntHandle);
INTC_Enable(0); //使能中断向量号,中断向量号对应的中断见中断向量表
INTC_Enable(1);
INTC_Enable(32);
INTC_Enable(33);
Uart_Printf("s3c6410 keytest . \n");
while(1);
}