野火电子论坛

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 12498|回复: 3

各位帮我分析下 谢谢大家!矩阵键盘4*3问题 第一行 和第二行没有用 三四行有用。

[复制链接]
发表于 2016-7-23 08:15:18 | 显示全部楼层 |阅读模式
本帖最后由 a18270826679 于 2016-7-23 09:08 编辑

QQ图片20160723081215.png 下面是代码  各位帮我分析下  谢谢


#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 0x62:        printf("7\n");        break;//三行
                                case 0x52:        printf("8\n");        break;
                                case 0x32:        printf("9\n");        break;
                                case 0x66:        printf("*\n");        break;//四行
                                case 0x56:        printf("0\n");        break;
                                case 0x36:        printf("#\n");        break;
                        }

     }


}






回复

使用道具 举报

发表于 2016-7-23 08:49:36 | 显示全部楼层
还真早啊,帮顶
回复 支持 1 反对 0

使用道具 举报

发表于 2016-7-23 13:43:24 | 显示全部楼层
谁让你把求助帖发这里的
回复 支持 反对

使用道具 举报

发表于 2016-7-23 13:47:14 | 显示全部楼层
为什么不使用库函数,全是寄存器完全就不想看了,都不知道写的是啥
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

联系站长|手机版|野火电子官网|野火淘宝店铺|野火电子论坛 ( 粤ICP备14069197号 ) 大学生ARM嵌入式2群

GMT+8, 2024-9-22 23:31 , Processed in 0.036878 second(s), 26 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表