Simple calculator source code

Publisher:lambda21Latest update time:2015-07-24 Source: 51heiKeywords:Calculator Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere
#include
#include
#define uint unsigned int
#define uchar unsigned char
uchar code tab[]={0xee,0xed,0xeb,0xe7,
      0xde,0xdd,0xdb,0xd7,
      0xbe,0xbd,0xbb,0xb7,
      0x7e,0x7d,0x7b,0x77,}; //0~f key position code table


uchar code tab1[]={0x88,0Xbe,0Xc4,0X94,0Xb2,0X91,0X81,0Xbc,
       0X80,0X90,0xa0,0x83,0xc9,0x86,0xc1,0xe1,0xff}; //0~f font code table

void delay(uchar x) //millisecond delay function
{
 flying y;           
 for(;x>0;x--)
  for(y=110;y>0;y--);
}


scanf() //Key processing function   
{
 fly temp,temp1,i;  
 P0=0xf0; //Assign the value of P0 to oxf0 for column scanning
 if(P0!=0xf0) //Determine if a key is pressed
 {
  delay(2); 
  if(P0!=0xf0) //Check again whether a key is pressed
  {
   temp1=P0; //P0 value is assigned to temp1
   P0=0x0f; //P0 value is assigned to 0x0f for row scanning
   temp=temp1|P0; //Merge the row and column scan values ​​and assign them to temp
  }
 
 switch(temp)
 {
  case 0xee:i=1; break;
  case 0xed:i=2; break;
  case 0xeb:i=3; break;
  case 0xe7:i=4; break;
  case 0xde:i=5; break;
  case 0xdd:i=6; break;
  case 0xdb:i=7; break;
  case 0xd7:i=8; break;
  case 0xbe:i=9; break;
  case 0xbd:i=0; break;
  case 0xbb:i=10; break;
  case 0xb7:i=11; break;
  case 0x7e:i=12; break;
  case 0x7d:i=13; break;
  case 0x7b:i=14; break;
  case 0x77:i=15; break; 
 }
 }
  else return 16;
  return i;
}  

 

void display(uint temp) //display function
{
 flying i;
 float z[6];
 from[0]=16;
 z[1]=temp/10000;
 z[2]=temp%10000/1000;
 z[3]=temp%1000/100;
 z[4]=temp%100/10;
 z[5]=temp%10;


 for(i=0;i<6;i++)
 {  
  SBUF=tab1[z[i]]; // Find the key code value according to the key value and assign the key code value to the serial port send register
  while(!TI); //Judge whether the serial port data transmission is completed
  TI=0; //Serial port data transmission completed flag cleared to 0
 }


}

 

E(uchar n)
{
 uint  t=1;
 for(;n>0;n--)
 t=t*10;
 return t; 
}

 

 

void main(void) //main function
{ 

 


 uint has,has1;

 fly x,y,fh,j,k=0;
 flying zhi[6];
 fly zhi1[6];

while(1)
 {


  if(x<5&&!k)
  { if(scanf()<10)
  {
   delay(5);
   if(scanf()<10)
   {
     if(x==0){zhi[0]=scanf();while(scanf()!=16);}
    
     if(x==1){zhi[1]=scanf();while(scanf()!=16);}

     if(x==2){zhi[2]=scanf();while(scanf()!=16);}

     if(x==3){zhi[3]=scanf();while(scanf()!=16);}

     if(x==4){zhi[4]=scanf();while(scanf()!=16);}   


     x++;           
     has=0;

    for(y=0;y11&&scanf()<16)
 {
  delay(2);
  if(scanf()>9&&scanf()<16)
  {
   
   fh=scanf();
   while(scanf()!=16);
   k=1;
  }
 }


  

if(j<5&&k)
  { if(scanf()<10)
  {
   delay(2);
   if(scanf()<10)
   {
     if(j==0){zhi1[0]=scanf();while(scanf()!=16);}
    
     if(j==1){zhi1[1]=scanf();while(scanf()!=16);}

     if(j==2){zhi1[2]=scanf();while(scanf()!=16);}

     if(j==3){zhi1[3]=scanf();while(scanf()!=16);}

     if(j==4){zhi1[4]=scanf();while(scanf()!=16);}

     j++;           
     tem1=0;

    for(y=0;y
				   
Keywords:Calculator Reference address:Simple calculator source code

Previous article:TLC5620 generates frequency-adjustable three-phase sinusoidal signals
Next article:The single chip microcomputer STC5A60S2 completes audio acquisition and output

Latest Microcontroller Articles
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号