帮忙看一下仿真图可能是哪里出问题了,谢谢了

2019-03-24 17:42发布

#include<reg51.h>
#include<intrins.h>
#include<string.h>
#include<absacc.h>
#include"stdlib.h"
#include"string.h"
#define JINGZHEN 48
#define TIME0TH ((65536-100*JINGZHEN/12)&0Xff)>>8
#define TIME0TL ((65536-100*JINGZHEN/12)&0xff)
#define TIME1TH ((65536-5000*JINGZHEN/12)&0xff00)>>8
#define TIME1TL ((65536-5000*JINGZHEN/12)&0xff)
#define uchar unsigned char
#define uint unsigned int
#define BUSY 0x80
#define DATAPORT P0
sbit light=P1^3;
sbit LCM_RS=P2^0;
sbit LCM_RW=P2^1;
sbit LCM_EN=P2^2;
void delay_LCM(uint);
void lcd_wait(void);
void WriteCommandLCM(uchar WCLCM,uchar BusyC);
void WriteDataLCM(uchar WDLCM);
void DisplayOneChar(uchar X,uchar Y,uchar DData);
void initLCM(void);
void DisplayListChar(uchar X,uchar Y,unsigned char *DData);
void delay_LCM(uint k)
{
uint i,j;
for(i=0;i<k;i++)
{
for(j=0;j<60;j++)
{;}
}
}
void WriteCommandLCM(uchar WCLCM,uchar BusyC)
{
if(BusyC)lcd_wait();
DATAPORT=WCLCM;
LCM_RS=0;
LCM_RW=0;
LCM_EN=1;
_nop_();
_nop_();
_nop_();
LCM_EN=0;
}
void WriteDataLCM(uchar WDLCM)
{
lcd_wait();
DATAPORT=WDLCM;
LCM_RS=1;
LCM_RW=0;
LCM_EN=1;
_nop_();
_nop_();
_nop_();
LCM_EN=0;
}
void lcd_wait(void)
{
DATAPORT=0xff;
LCM_RS=0;
LCM_RW=1;
LCM_EN=1;
_nop_();
while(DATAPORT&BUSY)
{
LCM_EN=0;
_nop_();
_nop_();
LCM_EN=1;
_nop_();
_nop_();
}
LCM_EN=0;}
void initLCM()
{
DATAPORT=0;
delay_LCM(15);
WriteCommandLCM(0x38,0);
delay_LCM(5);
WriteCommandLCM(0x38,0);
delay_LCM(5);
WriteCommandLCM(0x38,0);
delay_LCM(5);
WriteCommandLCM(0x38,1);
WriteCommandLCM(0x08,1);
WriteCommandLCM(0x01,1);
WriteCommandLCM(0x06,1);
WriteCommandLCM(0x0c,1);
}
void DisplayOneChar(uchar X,uchar Y,uchar DData)
{
uchar mx,my;
my=Y&1;
mx=X&0xf;
if(my>0)mx+=0x40;
mx+=0x80;
WriteCommandLCM(mx,0);
WriteDataLCM(DData);
}
void DisplayListChar(uchar X,uchar Y,uchar *DData)
{
uchar i=0,n;
Y&=0x01;
X&=0x0f;
n=strlen(DData);
while(i<n)
{
DisplayOneChar(X,Y,DData[1]);
i++;
X++;
}
}
code uchar BitMsk[]={0x01,0x02,0x04,0x08,0x10,0x20,0x40,0x80,};
uint IrCount=0,Show=0,Cont=0;
uchar IRDATBUF[32],s[20];
uchar IrDat[5]={0,0,0,0,0};
uchar IrStart=0,IrDatCount=0;
extern void initLCM(void);
extern void DisPlayListChar(uchar X,ucharY,unsigned char*DData);
void timerlint (void) interrupt 3 using 3{
EA=0;
TH1 = TIME1TH;
TL1 = TIME1TL;
Cont++;
if(Cont>10)Show=1;
EA=1;
}
void timer0int (void) interrupt 1 using 1{
uchar i,a,b,c,d;
EA=0;
TH0 = TIME0TH;
TL0 = TIME0TL;
if(IrCount>500) IrCount=0;
if(IrCount>300&&IrStart>0)
{IrStart=0;IrDatCount=0;IrDat[0]=IrDat[1]=IrDat[2]=IrDat[3]=0;IrCount=0;}
if(IrStart==2)
{  
IrStart=3;
for(i=0;i<IrDatCount;i++)
{   
if(i<32)
   {  
a=i/8;
b=IRDATBUF[i];
c=IrDat[a];
d=BitMsk[i%8];
if(b>5&&b<14)c|=d;
if(b>16&&b<25)c&=~d;
IrDat[a]=c;  
}
  }
if(IrDat[2]!=~IrDat[3])
  {
  IrStart=0;IrDatCount=0;IrDat[0]=IrDat[1]=IrDat[2]=IrDat[3]=0;IrCount=0;   
}  
EA=1;
  return;
}
IrCount++;
   EA=1;
}
void int0() interrupt 0  using 0  {
EA=0;
if(IrStart==0)
  {

IrStart=1;IrCount=0;TH0 = TIME0TH;TL0 = TIME0TL;
   IrDatCount=0;EA=1;  
  return;
}
if(IrStart==1)  
{
if(IrDatCount>0&&IrDatCount<33)  
IRDATBUF[IrDatCount-1]=IrCount;
if(IrDatCount>31)   
{IrStart=2;TH0 = TIME0TH;TL0 = TIME0TL;EA=1;return;}
if(IrCount>114&&IrCount<133&&IrDatCount==0)  
  {IrDatCount=1;}else if(IrDatCount>0)IrDatCount++;
}
IrCount=0;TH0 = TIME0TH;TL0 = TIME0TL;
  EA=1;
} main()
{
   uchar *a,n;
  TMOD  |= 0x011;  
TH0 = TIME0TH;
TL0 = TIME0TL;
  ET0=1;
TR0=1;
ET1=1;
TR1=1;     
IT0 = 1;  
EX0 = 1;
initLCM();  
EA=1;
for(;;)  
{
if(Show==1)
  {  
                Show=0;
    Cont=0;  
DisplayListChar(0,1,"Please keys");
a="";
switch(IrDat[3])
{
    case 0x12://ON/C
      a="ON/C";
  break;
                case 0x0b://+/-
                        a="+/-";
  break;
   case 0x1a://+
    a="+";
  break;
         case 0x1e://-
    a="-";
  break;
         case 0x0e://+
                 a="/";
  break;
         case 0x1d://MRC
  a="MRC";
  break;
         case 0x1f://M-
a="M-";
         break;
         case 0x1b://M+
    a="M+";
  break;
     case 0x00://0
        if(IrDat[2]==0xff)a="0";
  break;
    case 0x01://1
       a="1";   
  break;
  case 0x02://2
a="2";   
  break;
    case 0x03://3
       a="3";
  break;
    case 0x04://4
         a="4";
  break;
   case 0x05://5
         a="5";
  break;   
  case 0x06://6  
a="6";     
  break;   
   case 0x07://7
a="7";

  break;
      case 0x08://8
a="8";
  break;   
   case 0x09://9
a="9";
  break;   
  case 0x2A://%
   a="%";   

  break;

   case 0x2B://X
   a="X";

  break;

       case 0x2C://.
        a=".";


  break;

    case 0x2D://=
a="=";



  break;

    case 0x2E://
        a=" ";
     break;

}
n=strlen(a);
if(n>0) sprintf(s,"Key is [%s]",a);
else sprintf(s,"Not Key",a);
DisplayListChar(0,0,s);
}

}
}

此帖出自小平头技术问答
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。