新聞中心

        EEPW首頁 > 嵌入式系統 > 設計應用 > 單片機做的8位計算器

        單片機做的8位計算器

        作者: 時間:2016-12-01 來源:網絡 收藏

        CODE:

        本文引用地址:http://www.104case.com/article/201612/324178.htm

        #include
        #define uint unsigned int
        #define uchar unsigned char
        sbit dula=P2^6;
        sbit wela=P2^7;
        uchar LA[8];
        uchar code wetable[]={
        0x7f,0xbf,0xdf,0xef,
        0xf7,0xfb,0xfd,0xfe};
        uchar code dutable[]={
        0x3f,0x06,0x5b,0x4f,
        0x66,0x6d,0x7d,0x07,
        0x7f,0x6f};//段選0~9
        longint num1,num2,num;
        uchar temp;//按鍵需要的中間變量
        uchar flag;//標記是否為數字鍵
        uchar ch;//保存當前按下的符號標記按鍵的次數,按下“+-*/”
        uchar date,count;//date保存按鍵得到的數字,count標記是第幾個數字
        uchar p;//p為指針,為了消除數字之前多余的0
        uchar mark;
        void delay(uint z)
        {
        uint x,y;
        for(x=z;x>0;x--)
        {
        for(y=0;y<=112;y++)
        {
        }
        }
        }
        void init()
        {
        count=0;
        flag=0;
        mark=0;
        num1=0;
        num2=0;
        num=0;
        }
        uchar keyscan()//判斷按下那個鍵
        {
        P1=0xfe;
        temp=P1;
        temp=temp&0xf0;
        if(temp!=0xf0)
        {
        delay(5);//消除抖動
        temp=P1;
        temp=temp&0xf0;
        while(temp!=0xf0)//證明有鍵按下,while語句是為了讓鍵盤松開
        {
        temp=P1;
        switch(temp)
        {
        case 0xee:flag=1;date=7;
        break;
        case 0xde:flag=1;date=8;
        break;
        case 0xbe:flag=1;date=9;
        break;
        case 0x7e:flag=2;ch=/;
        break;
        }
        if(temp!=0xf0)
        {
        delay(5);
        temp=P1;
        temp=temp&0xf0;
        while(temp!=0xf0)//等待按鍵松開
        {
        temp=P1;
        temp=temp&0xf0;
        }
        }
        }
        }
        P1=0xfd;
        temp=P1;
        temp=temp&0xf0;
        if(temp!=0xf0)
        {
        delay(5);//消除抖動
        temp=P1;
        temp=temp&0xf0;
        while(temp!=0xf0)//證明有鍵按下,while語句是為了讓鍵盤松開
        {
        temp=P1;
        switch(temp)
        {
        case 0xed:flag=1;date=4;
        break;
        case 0xdd:flag=1;date=5;
        break;
        case 0xbd:flag=1;date=6;
        break;
        case 0x7d:flag=2;ch=*;
        break;
        }
        if(temp!=0xf0)
        {
        delay(5);
        temp=P1;
        temp=temp&0xf0;
        while(temp!=0xf0)//等待按鍵松開
        {
        temp=P1;
        temp=temp&0xf0;
        }
        }
        }
        }
        P1=0xfb;
        temp=P1;
        temp=temp&0xf0;
        if(temp!=0xf0)
        {
        delay(5);//消除抖動
        temp=P1;
        temp=temp&0xf0;
        while(temp!=0xf0)//證明有鍵按下,while語句是為了讓鍵盤松開
        {
        temp=P1;
        switch(temp)
        {
        case 0xeb:flag=1;date=1;
        break;
        case 0xdb:flag=1;date=2;
        break;
        case 0xbb:flag=1;date=3;
        break;
        case 0x7b:flag=2;ch=-;
        break;
        }
        if(temp!=0xf0)
        {
        delay(5);
        temp=P1;
        temp=temp&0xf0;
        while(temp!=0xf0)//等待按鍵松開
        {
        temp=P1;
        temp=temp&0xf0;
        }
        }
        }
        }

        P1=0xf7;
        temp=P1;
        temp=temp&0xf0;
        if(temp!=0xf0)
        {
        delay(5);//消除抖動
        temp=P1;
        temp=temp&0xf0;
        while(temp!=0xf0)//證明有鍵按下,while語句是為了讓鍵盤松開
        {
        temp=P1;
        switch(temp)
        {
        case 0xe7:flag=4;ch=C;
        break;
        case 0xd7:flag=1;date=0;
        break;
        case 0xb7:flag=3;//ch==;
        break;
        case 0x77:flag=2;ch=+;
        break;
        }
        if(temp!=0xf0)
        {
        delay(5);
        temp=P1;
        temp=temp&0xf0;
        while(temp!=0xf0)//等待按鍵松開
        {
        temp=P1;
        temp=temp&0xf0;
        }
        }
        }
        }



        關鍵詞: 單片機8位計算

        評論


        技術專區

        關閉
        主站蜘蛛池模板: 樟树市| 灵丘县| 武安市| 洛宁县| 乌兰察布市| 海伦市| 巍山| 蚌埠市| 姚安县| 顺平县| 紫金县| 南江县| 曲周县| 浮山县| 高淳县| 海林市| 嘉荫县| 廊坊市| 开鲁县| 彰化市| 邢台市| 丽江市| 延庆县| 聂拉木县| 邵阳县| 延寿县| 油尖旺区| 赫章县| 新昌县| 怀仁县| 揭东县| 平顺县| 安溪县| 乃东县| 晋州市| 临清市| 南川市| 兴和县| 丰镇市| 林口县| 晋城|