|
/* MAIN.C file
*
* Copyright (c) 2002-2005 STMicroelectronics
*/
#include "stm8s103k.h"
void delay(unsigned char b)
{
unsigned char i;
for(i=0;i<b;i++)
{
}
}
unsigned int save1;
unsigned int back[8];
unsigned int savetime2;
//unsigned int savetime2back;
unsigned int savemiddle;
unsigned char keytime;
unsigned char keynottime;
unsigned char keyvalue;
main()
{
unsigned char i;
//PD_DDR = 0xFF;//the PD set is input
//PD_CR1 = 0xFF;//the PULL resist is not use
//PD_ODR = 0xFF;
//PF_DDR = 0xFF;
//PF_CR1 = 0xFF;
//PF_ODR = 0xFF;
TIM2_CNTRL = 0x00;
TIM2_CNTRH = 0x00;
//TIM2_CR1 = 0x01;
PF_ODR = 0xFF;
PF_CR1 = 0xFF;
PF_DDR = 0xFF;
PC_ODR = 0xFF;
PC_CR1 = 0xFF;
PC_DDR = 0xFF;
PB_ODR = 0xFF;
PB_CR1 = 0xFF;
PB_DDR = 0xFF;
for(i=0;i<8;i++)
{
PF_ODR = 0xFF;
PF_CR1 = 0xFF;
PF_DDR = 0xFF;
PC_ODR = 0xFF;
PC_CR1 = 0xFF;
PC_DDR = 0xFF;
TIM2_CNTRL = 0x00;
TIM2_CNTRH = 0x00;
PC_ODR = 0x00;
PC_CR1 = 0x00;//不上拉输出
PC_DDR = 0x00;
TIM2_CR1 = 0x01;
for(;;)
{
if(PC_IDR & (1<<5)) //1<<6 is *8 //1<<5 is *9
break;
}
TIM2_CR1 = 0x00;
save1 = (unsigned int)(TIM2_CNTRH<<8);
save1 += (unsigned int)TIM2_CNTRL;
TIM2_CNTRL = 0x00;
TIM2_CNTRH = 0x00;
PC_ODR = 0xFF;
PC_CR1 = 0xFF;
PC_DDR = 0xFF;
PF_ODR = 0x00;
PF_CR1 = 0xFF;
PF_DDR = 0xFF;
PC_CR1 = 0x00;
PC_DDR = 0x00;
TIM2_CR1 = 0x01;
for(;;)
{
if(!(PC_IDR & (1<<5))) //1<<6 is *8 //1<<5 is *9
break;
}
TIM2_CR1 = 0x00;
savetime2 = (unsigned int)(TIM2_CNTRH<<8);
savetime2 += (unsigned int)(TIM2_CNTRL);
if(i>0)
{
back = save1+savetime2;
}
}
for(i=1;i<8;i++)
{
if(back == back[i+1])
{
keynottime++;
}
else
{
if((back- 35)>10)
keytime++;
}
}
while(1);
} |
|