|
int main(void)
{
uint16 ticker = 0;
P_SW2 |= 0x80; //使能訪問 XFR特殊寄存器
GPIO_Init();
UART_Init();
SPI_Init();
Timer2_Init();
LCD_Init();
// WDT_CONTR = 0x24; //使能看門狗,溢出時(shí)間約為1s
ticker = Timer_count;
EA = 1; //允許中斷
while(1)
{
// WDT_CONTR = 0x34; //清看門狗,否則系統(tǒng)復(fù)位
if(ticker != Timer_count)
{
ticker = Timer_count;
Vk1621_Data_Exch();//數(shù)據(jù)處理
Key_Schedule(); //按鍵處理
}
}
}
void Timer2_Init(void)
{
AUXR |= 0x04; //定時(shí)器時(shí)鐘1T模式 16位自動(dòng)重載
T2L = 0xdf; //設(shè)置定時(shí)初始值
T2H = 0xff; //設(shè)置定時(shí)初始值
AUXR |= 0x10; //定時(shí)器2開始計(jì)時(shí)
// INT_CLKO |=0x04; //使能P13定時(shí)器輸出功能
IE2 |= 0x04; //使能定時(shí)器中斷
}
void TM2_Isr() interrupt 12
{
count++;//1微秒計(jì)數(shù)
if(!(count%1000))
{
Timer_count++;//毫秒計(jì)數(shù)
UART_SendChar(Timer_count);//測(cè)試數(shù)據(jù)
}
}
void SPI_Transivion (void) interrupt SPI_VECTOR
{
SPSTAT = SPIF + WCOL; //清0 SPIF和WCOL標(biāo)志
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;
}
|
|