标题: 一个计算器的小程序,求大神来看一看 [打印本页]

作者: 氺墨留苩    时间: 2017-4-25 09:11
标题: 一个计算器的小程序,求大神来看一看
#include<reg52.h>
#include<intrins.h>
#define uint unsigned int
#define uchar unsigned char
uchar code table[]={
0x3f,0x06,0x5b,0x4f,
0x66,0x6d,0x7d,0x07,
0x7f,0x6f,0x77,0x7c,
0x39,0x5e,0x79,0x71};
uchar t,t_1,t_2;
sbit dula=P2^6;
sbit wela=P2^7;
uint num;
sbit temp=0xfe;
void delay(int z)
{
        uint x,y;
        for(x=z;x>0;x--)
                for(y=110;y>0;y--);
}
/*******************************¾ØÕó¼üÅì*****************************************/
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=0;        display(0);        berak;       
                        case 0xde:num=1;        display(1); berak;
                        case 0xbe:num=2;        display(2); berak;
                        case 0x7e:num=3;        display(3);        berak;
                }
                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=4;        display(4);berak;       
                        case 0xdd:num=5;        display(5);berak;
                        case 0xbd:num=6;        display(6);berak;
                        case 0x7d:num=7;        display(7);berak;
                }
                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=8;        display(8);        berak;       
                        case 0xdb:num=9;        display(9);        berak;
                        case 0xbb:num=10;        berak;
                        case 0x7b:num=11;        berak;
                }
                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=12;        berak;       
                        case 0xd7:num=13;        berak;
                        case 0xb7:num=14;        berak;
                        case 0x77:num=15;        berak;
                }
                while(temp!=0xf0)
                {
                        temp=P3;
                        temp=temp&0xf0;
                }
                }
        }
        return num;
}
/******************************ÏÔê¾**************************************/
void display(uchar ee)
{
                dula=1;
                P0=table[ee];
                dula=0;
                P0=0xff;
                wela=1;
                P0=0xfe;
                wela=0;
                delay(1);
}
/*************************************Ö÷oˉêy***********************************/
void main()
{
        wela=0;
        dula=0;
        while(1)
        {
                keyscan();
                t_1=num;
                keyscan();
                t_2=num;
                if(num<10)
                {
                        keyscan();       
                        if(num=10)        t=t_1+t_2+2;
                        if(num=11)        t=t_1-t_2;
                        if(num=12)        t=(t_1+1)*(t_2+1);
                        if(num=13)        t=(t_1+1)/(t_2+1);
        }
}
错误:homework4.c(37): error C255: switch expression has illegal type
求大神解,switch中不能用sbit定义的吗?那应该怎么改呢
               






欢迎光临 (http://www.51hei.com/bbs/) Powered by Discuz! X3.1