新手上路
- 积分
- 26
- 金钱
- 26
- 注册时间
- 2016-7-21
- 在线时间
- 6 小时
|
1金钱
#include "./KEY/KEY.h"
#include "./USART/usart.h"
void delay_ms(unsigned short time)
{
unsigned short i=0;
while(time--)
{
i=100;
while(i--);
}
}
void delay1ms(void) //?? 0us
{
unsigned char a,b,c;
for(c=1;c>0;c--)
for(b=142;b>0;b--)
for(a=2;a>0;a--);
}
u8 KEY_Scan(void)
{
u16 cord_h,cord_l;//??????? ???? ,????;
u8 Val = 0xFF;
//i=(GPIOG->ODR)&0xFFFF;
RCC->APB2ENR|=1<<3;
GPIOB->CRL=0x83333444; //1100 1110 0010 0010 0010 0001 0001 00
GPIOB->CRH=0x44444488;
GPIOB->ODR = 0xff87; //行全输出0 //1111 1111 1000 0111
cord_h = GPIOB->IDR & 0x0380; //读列值 //0000 0111 1000 0000
delay_ms(1); //??
if(cord_h != 0x0380) //????????? //1111 1100 0011 1111
{
// printf("0x%X\n",cord_h);
delay_ms(100); //??
if(cord_h != 0x0380) // 0000 0000 0000 0000 //1111 1100 0011 1111
{
printf("0x%X\n",cord_h);
//printf("0x%X\n",cord_h);
cord_h = GPIOB->IDR&0x0380; //?????//
// printf("0x%X\n",cord_h);
GPIOB->CRL=0x38888444;
GPIOB->CRH=0x44444433;
delay_ms(1); //??
GPIOB->ODR = cord_h|0xfc7f; //???????1111 1111 1100 0011
// printf("0x%X\n",cord_h);
delay1ms();// ???????;
delay1ms();
cord_l = GPIOB->IDR&0x0038; //????? 0000 0011 1100 0000
//printf("0x%X\n",cord_l);
delay_ms(1); //??
cord_h>>=3;
cord_l>>=3;
// printf("0x%X\n",cord_h);
Val = (cord_h+cord_l)&0xff;
//printf("0x%X\n",cord_l);
//printf("0x%X\n",Val);
return Val; //????????
}
while(cord_h != 0x0380);
}
return 0xFF; //????
}
主函数调用
int main(void)
{
//SystemInit();
u8 x;
uart_init(9600);
LED_Configuration();
while(1)
{
x=KEY_Scan(); //????
switch(x)
{
case 0xEA: printf("7\n"); break;//三行
case 0xDA: printf("8\n"); break;
case 0xBA: printf("9\n"); break;
case 0xE6: printf("*\n"); break;//四行
case 0xD6: printf("0\n"); break;
case 0xB6: printf("#\n"); break;
}
}
}
|
|