怎么把51程序改为430的

2019-07-15 16:06发布

#include<reg52.h>
sbit K0=P2^4;
sbit K1=P2^5;
sbit K2=P2^6;
sbit K3=P2^7;
sbit KO0=P2^0;
sbit KO1=P2^1;
sbit KO2=P2^2;
sbit KO3=P2^3;
unsigned char t;
extern void keyaction(unsigned char keycode);
unsigned char ajxt[4][4]={{1,1,1,1},{1,1,1,1},{1,1,1,1},{1,1,1,1}};
unsigned char code keymap[4][4]={{'1','2','3',0x26},
                                 {'4','5','6',0x25},
{'7','8','9',0x28},
{'0',0x1b,0x0d,0x27}};






void keydrive()
{  unsigned char i,j;
   unsigned char ajct[4][4]={{1,1,1,1},{1,1,1,1},{1,1,1,1},{1,1,1,1}};
    for(i=0;i<4;i++)
{   
   for(j=0;j<4;j++)
   {
   
     if(ajxt[j]!=ajct[j])
      {
         ajct[j]=ajxt[j];
     if(ajct[j]==0)
       {
     t=i*4+j;
           }     
      }
       }  
  }
}   
void keyscan()
{
   static unsigned char ajjl[4][4]={{0xff,0xff,0xff,0xff,},{0xff,0xff,0xff,0xff,},
                                  {0xff,0xff,0xff,0xff,},{0xff,0xff,0xff,0xff,}};
   unsigned char i,j;
   for(i=0;i<4;i++)
   {
      switch(i)
  {
    case 0:KO0=1;KO1=1;KO2=1;KO3=0;break;
case 1:KO0=1;KO1=1;KO2=0;KO3=1;break;
case 2:KO0=1;KO1=0;KO2=1;KO3=1;break;
case 3:KO0=0;KO1=1;KO2=1;KO3=1;break;
  }
  ajjl[0]=((ajjl[0]<<1)|K0);
  ajjl[1]=((ajjl[1]<<1)|K1);
  ajjl[2]=((ajjl[2]<<1)|K2);
  ajjl[3]=((ajjl[3]<<1)|K3);
  for(j=0;j<4;j++)
  {
    if((ajjl[j]&0x0f)==0x00)
   {
    ajxt[j]=0;
   }
if((ajjl[j]&0x0f)==0x0f)
   {
    ajxt[j]=1;
   }
   
   
  }
   }
   
}   

sbit RS=P1^0;
sbit RW=P1^1;
sbit  E=P1^5;
unsigned char t;
bit l=0;
unsigned char code xs1[]="é‡چé‡ڈ:SJDIDW3993JD";
unsigned char xs2[4];
unsigned char code xs3[]="هچ•ن»·:";
unsigned char code xs4[]="金é¢‌:";
unsigned char xs5[10];
void delay(unsigned char x)
{
  unsigned char j,i;
  for(i=0;i<x;i++)
  {
    for(j=0;j<100;j++);
  }
}


void yjmbm()
{
unsigned char dat;
  RS=0;
  RW=1;
  P0=0XFF;
  do{
     E=1;
dat=P0;
E=0;
    }while(dat>0x7f);
  
}

void write_com(com)
{
  
  yjmbm();
  RS=0;
  RW=0;
  P0=com;
  delay(1);
  E=1;
  delay(1);
  E=0;
}

void yjcsh()
{
write_com(0x30);
write_com(0x0c);
write_com(0x06);
}
void dz(unsigned char x,unsigned char y)
{
  unsigned char addr;
   if(x==0)
  {
    addr=0x80+y;
  }
if(x==1)
  {
    addr=0x90+y;
  }
if(x==2)
  {
    addr=0x88+y;
  }
if(x==3)
  {
    addr=0x98+y;
  }
  write_com(addr);

}
void write_dat(unsigned char dat)
{
  yjmbm();
  RS=1;
  RW=0;
  P0=dat;
  delay(1);
  E=1;
  delay(1);
  E=0;
  
}
void yjxs(unsigned char x,unsigned char y,unsigned char *str,unsigned char len)
{
   dz(x,y);
   while(len--)
   {
     write_dat(*str++);
   }
}


void main()
{
  unsigned int sum=0;
  unsigned int  a =0;
  TMOD=0X01;
  TH0=0XFC;
  TL0=0X67;
  TR0=1;
  EA=1;
  ET0=1;


  yjcsh();
  yjxs(1,0,xs3,5);
  yjxs(2,0,xs4,5);
  yjxs(0,0,xs1,5);
  

  while(1)
  {
keydrive();
   if(l==1)
   {
   l=0;
   a++;
   sum=a*4;
   xs2[0]=(unsigned char)(a/1000%10)+'0';
   xs2[3]=(unsigned char)(a%10)+'0';
   xs2[2]=(unsigned char)(a/10%10)+'0';
   xs2[1]=(unsigned char)(a/100%10)+'0';


   xs5[0]=(unsigned char)(t/1000%10)+'0';
   xs5[3]=(unsigned char)(t%10)+'0';
   xs5[2]=(unsigned char)(t/10%10)+'0';
   xs5[1]=(unsigned char)(t/100%10)+'0';
  }
   yjxs(2,4,xs5,5);
   yjxs(0,4,xs2,4);
  
}
}

void t0() interrupt 1
{
  static unsigned int cunt=0;
  TH0=0XFC;
  TL0=0X67;
  keyscan();
cunt++;
if(cunt>=1000)
{
  cunt=0;
l=1;
}
}

友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。