int main(void)
{
uint16 ticker = 0;
P_SW2 |= 0x80; //使能访问 XFR特殊寄存器
GPIO_Init();
UART_Init();
SPI_Init();
Timer2_Init();
LCD_Init();
// WDT_CONTR = 0x24; //使能看门狗,溢出时间约为1s
ticker = Timer_count;
EA = 1; //允许中断
while(1)
{
// WDT_CONTR = 0x34; //清看门狗,否则系统复位
if(ticker != Timer_count)
{
ticker = Timer_count;
Vk1621_Data_Exch();//数据处理
Key_Schedule(); //按键处理
}
}
}
void Timer2_Init(void)
{
AUXR |= 0x04; //定时器时钟1T模式 16位自动重载
T2L = 0xdf; //设置定时初始值
T2H = 0xff; //设置定时初始值
AUXR |= 0x10; //定时器2开始计时
// INT_CLKO |=0x04; //使能P13定时器输出功能
IE2 |= 0x04; //使能定时器中断
}
void TM2_Isr() interrupt 12
{
count++;//1微秒计数
if(!(count%1000))
{
Timer_count++;//毫秒计数
UART_SendChar(Timer_count);//测试数据
}
}
void SPI_Transivion (void) interrupt SPI_VECTOR
{
SPSTAT = SPIF + WCOL; //清0 SPIF和WCOL标志
if(SPI_RxCnt >= SPI_BUF_LENTH)
{
SPI_RxCnt = 0;
}
SPI_RxBuffer[SPI_RxCnt] = SPDAT;
if(SPI_RxBuffer[SPI_RxCnt] == 0x20)
{
SPI_RxCnt = 0;
}
else
{
SPI_RxCnt++;
}
SPDAT = Key_Information.KeyData;
SPI_RxTimerOut = 5;
}
|