| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 742 人关注过本帖
标题:请问在单片机C语言编程中这个“与”运算怎么用,有什么用
只看楼主 加入收藏
超级大帅哥
Rank: 1
等 级:新手上路
帖 子:4
专家分:0
注 册:2013-2-13
结帖率:0
收藏
已结贴  问题点数:2 回复次数:2 
请问在单片机C语言编程中这个“与”运算怎么用,有什么用
在单片机C语言编程中下面这个“与”是什么意思?
temp=temp&0xf0;还有以下这句是什么意思?   
switch(temp)
 {
     case 0xe7:num=13;
         break;
     case 0xd7:num=14;
         break;
      case 0xb7:num=15;
         break;
     case 0x77:num=16;
         break;
  }

这是原程序【矩阵键盘(16个),在键盘上按下一个键,数码管上也显示出对应的(16进制)数】:
#include<reg52.h>
#define uint unsigned int
#define uchar unsigned char
sbit dula=P2^6;
sbit wela=P2^7;
sbit key1=P3^4;
uchar code table[]={
0x3f,0x06,0x5b,0x4f,
0x66,0x6d,0x7d,0x07,
0x7f,0x6f,0x77,0x7c,
0x39,0x5e,0x79,0x71,0};
uchar num,temp,num1;
void delay(uint z)
{
    uint x,y;
    for(x=z;x>0;x--)
        for(y=110;y>0;y--);
}
uchar keyscan();
void display(uchar aa);
void main()
{
    num=17;
    dula=1;
    P0=0;
    dula=0;
    wela=1;
    P0=0xc0;
    wela=0;
   
    while(1)
        {
            display(keyscan());
        }
}
void display(uchar aa)
{
    dula=1;
    P0=table[aa-1];
    dula=0;        
}
uchar keyscan()
{
    P3=0xfe;
    temp=P3;
    temp=temp&0xf0;
    while(temp!=0xf0)
        {
            delay(5);
            temp=P3;
            temp=temp&0xf0;
            while(temp!=0xf0)
            {
                temp=P3;
            switch(temp)
                {
                    case 0xee:num=1;
                        break;
                    case 0xde:num=2;
                        break;
                    case 0xbe:num=3;
                        break;
                    case 0x7e:num=4;
                        break;
                }
            while(temp!=0xf0)
                {
                    temp=P3;
                    temp=temp&0xf0;
                }
            }
        }

    P3=0xfd;
    temp=P3;
    temp=temp&0xf0;
    while(temp!=0xf0)
        {
            delay(5);
            temp=P3;
            temp=temp&0xf0;
            while(temp!=0xf0)
            {
                temp=P3;
            switch(temp)
                {
                    case 0xed:num=5;
                        break;
                    case 0xdd:num=6;
                        break;
                    case 0xbd:num=7;
                        break;
                    case 0x7d:num=8;
                        break;
                }
            while(temp!=0xf0)
                {
                    temp=P3;
                    temp=temp&0xf0;
                }
            }
        }


    P3=0xfb;
    temp=P3;
    temp=temp&0xf0;
    while(temp!=0xf0)
        {
            delay(5);
            temp=P3;
            temp=temp&0xf0;
            while(temp!=0xf0)
            {
                temp=P3;
            switch(temp)
                {
                    case 0xeb:num=9;
                        break;
                    case 0xdb:num=10;
                        break;
                    case 0xbb:num=11;
                        break;
                    case 0x7b:num=12;
                        break;
                }
            while(temp!=0xf0)
                {
                    temp=P3;
                    temp=temp&0xf0;
                }
            }
        }


    P3=0xf7;
    temp=P3;
    temp=temp&0xf0;
    while(temp!=0xf0)
        {
            delay(5);
            temp=P3;
            temp=temp&0xf0;
            while(temp!=0xf0)            
            {
                temp=P3;
            switch(temp)
                {
                    case 0xe7:num=13;
                        break;
                    case 0xd7:num=14;
                        break;
                    case 0xb7:num=15;
                        break;
                    case 0x77:num=16;
                        break;
                }
            while(temp!=0xf0)
                {
                    temp=P3;
                    temp=temp&0xf0;
                }
            }
        }
return num;

}
            

搜索更多相关主题的帖子: 单片机 include C语言 数码管 
2013-02-13 08:46
wldnscjf
Rank: 2
等 级:论坛游民
帖 子:20
专家分:14
注 册:2013-1-27
收藏
得分:1 
由于您的代码太长,看不懂~
2013-02-15 19:53
yaobao
Rank: 13Rank: 13Rank: 13Rank: 13
等 级:蒙面侠
威 望:4
帖 子:1854
专家分:4121
注 册:2012-10-25
收藏
得分:1 
提取高四位

认认真真的学习,踏踏实实的走路:戒骄戒躁!!!
2013-02-16 08:16
快速回复:请问在单片机C语言编程中这个“与”运算怎么用,有什么用
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.013095 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved