//===========================================================================
//文件名称：isr.c
//功能概要： 中断底层驱动构件源文件
//版权所有：苏州大学飞思卡尔嵌入式中心(sumcu.suda.edu.cn)
//更新记录：2012-11-12   V1.0
//===========================================================================
#include "includes.h"

//========================测试===============================
//串口0接收中断服务例程
void isr_uart0_re(void)
{
    uint_8 ch;
    uint_8 flag = 1;
    
    enter_critical();
    
    ch = uart_re1(UART_0, &flag);
    if (0 == flag)
    {
        uart_send1(UART_0, ch);
    }
    
    exit_critical();
}


//串口1接收中断服务例程
void isr_uart1_re(void)
{
    uint_8 ch;
    uint_8 flag = 1;
    
    enter_critical();
    
    ch = uart_re1(UART_1, &flag);
    if (0 == flag)
    {
        uart_send1(UART_1, ch);
    }
    
    exit_critical();
}

//串口1接收中断服务例程
void isr_uart2_re(void)
{
    uint_8 ch;
    uint_8 flag = 1;
    
    enter_critical();
    
    ch = uart_re1(UART_2, &flag);
    if (0 == flag)
    {
        uart_send1(UART_2, ch);
    }
    
    exit_critical();
}

void tpm0_isr(void)
{
    static uint_32 TPMCounter = 0;   //计时器		  
    uint_8 value;                    //键盘变量
    static uint_8 LEDindex=0;        //位选口声明
    uint_8 i;
    
   // LCD显示缓冲区，其中.表示按下的数字
    uint_8 kbv[32]="The keyboard you just input is .";              
    if((TPM_SC_REG(TPM0_BASE_PTR) & TPM_SC_TOF_MASK) == TPM_SC_TOF_MASK)
    {	
	    TPMCounter++;     
    }
    BSET(TPM_SC_TOF_SHIFT,TPM_SC_REG(TPM0_BASE_PTR));  //中断置标志位写1清0 
    //处理LED部分
    if(fg==0){
    LEDindex++; //位选位+1                                    
    if (LEDindex>=4)  LEDindex=0;                      //大于4位选口置0
    i=LEDchangeCode(LEDDataBuffer[LEDindex]-'0');      //转码
    LEDshow1(LEDindex,i);	       //显示LED		
    }
	if(TPMCounter>100)                     
	{
		TPMCounter = 0;
	    //键盘得到扫描值
	    value = KBScanN(2);
	   
	    //扫描键值,存于value中
	    if(KBDef(value) != 0xff)      //发送键值
	    {
	       //修改.成为按键值
	       kbv[31] = KBDef(value);
	       fg=0;	         
	       LCDShow(kbv);
	       beep_control(BEEP_PORT_PIN, BEEP_ON);
	    }
	    
    }		  
}
