这些小活动你都参加了吗?快来围观一下吧!>>
电子产品世界 » 论坛首页 » 综合技术 » 基础知识 » 那位好心的人,帮我看一下我的程序怎么错了,急用,求求!!

共2条 1/1 1 跳转至

那位好心的人,帮我看一下我的程序怎么错了,急用,求求!!

院士
2006-09-17 18:14:16     打赏
那位好心的人,帮我看一下我的程序怎么错了,急用,求求!!



关键词: 那位     好心     帮我     看一下     我的     程序     怎么     错了         

院士
2006-12-22 22:43:00     打赏
2楼
问 #include <reg52.h>
#include<absacc.h>
//ad控制线
#define ad_244 XBYTE[0xbfff];
sbit  ad_stb=P3^3;
sbit  ad_start=P1^1;
//lcd控制线
sbit lcd_di=P1^7;
sbit lcd_rw=P1^2;
sbit lcd_e=P1^0;
//7289控制线
sbit cs7289=P1^3;
sbit clk7289=P1^4;
sbit dio7289=P1^5;
//sbit    key7289=P1^6;      //7289查询方式
sbit    key7289=P3^2;        //7289中断方式
sbit  baoj=P3^5;

//7289子程序
void    ini_7289(void);
void    send7289(short);
short   receive(void);
void    keyin(void);
//lcd子程序
void ini_lcd(void);
void lcdd_send(short);
void lcdi_send(short);
void chk_busy(void);
//ad子程序
void ad(void);
void baojing(void);
void d_change(long);
//初始化,编号,日期
void ini();
void error1(void);
void nop1()
{}
void change(s)

int    dealy;               //全局变量
short  sh=0;               //商品号
short  dot=0;               //小数点标志
bit    list=0;
short  qb=0;
char xdata shuju[7]="";
short xdata bcd[5];
char xdata s1[16]="单价:         元";
char xdata s2[16]="重量:         Kg";
char xdata s3[16]="金额:         元";
char xdata s4[16]="累计:         元";
char code message0[]="联华超市        乐山分店";
char code message1[]="输入收银员代号:";
char code message2[]="输入日期:";
char code message3[16]="  --联华超市--  ";
char code message5[16]="匀桧叶商场欢迎您!";
char xdata bianhao[16]="收银员:        ";
char xdata riqi[16]="    -  -        ";

long int xdata zongjia=0,jine=0,jine1=0;
int  xdata shizhong=0,pizhong=0,zhongliang=0;
long int  xdata qingdan[20][4];
char code shangpin[11][4]={{"单价"},{"苹果"},{"糖果"},{"花生"},{"大米"},
{"衣服"},{"刷子"},{"瓜子"},{"桔子"},{"香蕉"},{"大豆"}};
long int xdata danjia[11]=
{0,2000,3635,5502,6660,3320,5502,660,3210,6600,5600};
char xdata jiage[6]={0x0,0x0,0x0,0xfe,0x0,0x0};   //  0.00
short xdata xiuzheng[]={0,2,5,6,7,8,9,12,13};
char s[16];
{s[6]=shuju[0];
s[7]=shuju[1];
s[8]=shuju[2];
s[9]=shuju[3];
s[10]=shuju[4];
s[11]=shuju[5];
s[12]=shuju[6];
}
//****************************************************************
void main()
{short i,j;
long int x,z;
int y;
int xdata duilie[3]={0};
P1=0xff;
ini_lcd();             //初始化LCD
lcdi_send(0x8a);
while(message0[i]) lcdd_send(message0[i++]);
ini_7289();            //初始化7289
pizhong=ad1();
lcdi_send(0x1);       //总清 屏
ini();                 //初始页面,收银员编号,日期
lcdi_send(0x1);       //总清 屏
EA=1;EX0=1;                     //中断
//EX1=1;
//ad_start=1;
while(1)
   {if(list){lcdi_send(0x80);                        //显示单位名称
          for(i=0;i<16;i++) lcdd_send(message3[i]);
          x=qingdan[0][0];                        //商品名 单价
          for(i=0;i<4;i++) s1[i]=shangpin[x][i];
          x=qingdan[0][1];
          d_change(x);  change(s1);
          lcdi_send(0x90);
          for(i=0;i<16;i++) lcdd_send(s1[i]);
          x=qingdan[0][2];                        //显示重量
          d_change(x); change(s2);
          s2[10]=s2[9];s2[9]='.';
          if(s2[8]==32) s2[8]=0x30;
          lcdi_send(0x88);
          for(i=0;i<16;i++) lcdd_send(s2[i]);
          x=qingdan[0][3];
          d_change(x);   change(s3);
          lcdi_send(0x98);
          for(i=0;i<16;i++) lcdd_send(s3[i]);           //以上为第一页
          EA=0;EX0=0;                           //关键盘中断
           for(j=1;j<qb;j++)
            {while(key7289);
             x=qingdan[j][2];
             d_change(x); change(s2);               //显示数据
             s2[10]=s2[9];
             s2[9]='.';                                     if(s2[8]==32) s2[8]=0x30;
             lcdi_send(0x90);
             for(i=0;i<16;i++) lcdd_send(s2[i]);
             x=qingdan[j][1];
             d_change(x);  change(s1);
             x=qingdan[j][0];
             for(i=0;i<4;i++) s1[i]=shangpin[x][i];   
             lcdi_send(0x80);
             for(i=0;i<16;i++) lcdd_send(s1[i]);
             x=qingdan[j][3];
             d_change(x);   change(s3);
             lcdi_send(0x88);
             for(i=0;i<16;i++) lcdd_send(s3[i]);    
             lcdi_send(0x98);
             for(i=0;i<16;i++) lcdd_send(0x20);     
             lcdi_send(0x98);
             while(key7289==0);
            }
            while(key7289);
            d_change(zongjia); change(s4);
            lcdi_send(0x80);
            for(i=0;i<16;i++) lcdd_send(s4[i]);
            lcdi_send(0x90);
            for(i=0;i<16;i++) lcdd_send(bianhao[i]);
            lcdi_send(0x88);
            for(i=0;i<16;i++) lcdd_send(message5[i]);
            lcdi_send(0x98);
            for(i=0;i<16;i++) lcdd_send(riqi[i]);
            list=0;
            while(key7289==0);
            while(key7289==1);
            while(key7289==0);
             EA=1;EX0=1;
         }
  else{ y=0;
      /* duilie[2]=duilie[1];           //数字滤波
       duilie[1]=duilie[0];
       y=ad1();
       duilie[0]=y>>1;
       x=duilie[0];
       x=x<<1;
       x=x+duilie[1]+duilie[2];   */
       zhongliang=ad1();
       shizhong=zhongliang-pizhong;                 //数据转换
       x=danjia[sh];
       jine1=shizhong*x;
       jine=jine1/1000;
       d_change(shizhong); change(s2);               //显示数据
       s2[10]=s2[9]; s2[9]='.';
       if(s2[8]==32) s2[8]=0x30;
       lcdi_send(0x90);
       for(i=0;i<16;i++) lcdd_send(s2[i]);
       d_change(danjia[sh]);  change(s1);
       for(i=0;i<4;i++) s1[i]=shangpin[sh][i];
       lcdi_send(0x80);
       for(i=0;i<16;i++) lcdd_send(s1[i]);
       d_change(jine);   change(s3);
       lcdi_send(0x88);
       for(i=0;i<16;i++) lcdd_send(s3[i]);
       d_change(zongjia); change(s4);
       lcdi_send(0x98);
       for(i=0;i<16;i++) lcdd_send(s4[i]);
       lcdi_send(0x98);
     //while(1);
      }
  }
}
void keyin(void) interrupt 0 using 0 //中断0服务程序
{char X,i;
long int  y;
send7289(0x15); //接收数据
X=receive();
cs7289=1;
X=X&0x1f;
switch(X)
       {case 0xf : {zongjia=zongjia+jine;
                     qingdan[qb][0]=sh;
                     qingdan[qb][1]=danjia[sh];
                     qingdan[qb][2]=shizhong;
                     qingdan[qb][3]=jine;
                     qb++; sh=0;dot=0;
                     danjia[0]=0;
                     for(i=0;i<6;i++)  jiage[i]=0;
                    }
                    break;              //累加
        case 0xe : pizhong=zhongliang; break;               //去皮
        case 0xd : {danjia[sh]=0;dot=0;} break;              //清单价
        case 0xc : {zongjia=0;jine=0;dot=0;list=0;qb=0;pizhong=0;
                     if(sh==0) danjia[sh]=0;} break;          //总清
        case 0xa : dot=1;break;                             //点
        case 0xb : list=1;break;                            //清单
        case 0x19 : sh=10;break;
        case 0x18 : sh=9;break;
        case 0x17 : sh=8;break;
        case 0x16 : sh=7;break;
        case 0x15 : sh=6;break;
        case 0x14 : sh=5;break;
        case 0x13 : sh=4;break;
        case 0x12 : sh=3;break;
        case 0x11 : sh=2;break;
        case 0x10 : sh=1;break;
        case 0x1f  :
        case 0x1e  :
        case 0x1d  :
        case 0x1c  :
        case 0x1a  : break;
        case 0x1b  : dot=1;break;
      default  :{ if(dot==0) {jiage[0]=jiage[1];jiage[1]=jiage[2];jiage[2]=X;}

                  if(dot==1) {jiage[4]=X;dot++; }
                  else if(dot==2) {jiage[5]=X; dot++;}
                  else if(dot>2) break;
                   // lcdi_send(0x84);
                    y=jiage[0];
                    y=y*10+jiage[1];
                    y=y*10+jiage[2];
                    y=y*10+jiage[4];
                    danjia[sh]=y*10+jiage[5];
                   }
                  }
        while(key7289==0);        //等待键盘松开
  }
/*
void ad(void) interrupt 2 using 1
{short x,y;
x=ad_244;
y=x;
if(x&0x80) baojing();
  else x=x>>4;
y=y&0xf;
bcd[x]=y;
}     */
//初始页面
void ini()                           // 输入收银员编号,日期
{short i,j;
char X;
lcdi_send(0x80);                    //提示输入收银员编号
i=0;
while(message1[i]) lcdd_send(message1[i++]);
for(i=8;i<12;i++)
    {
     while(key7289);
     send7289(0x15); //接收数据
     X=receive();
     cs7289=1;
     bianhao[i]=X+0x30;
     lcdi_send(0x93);
     for(j=8;j<16;j++) lcdd_send(bianhao[j]);
     while(key7289==0);
     }
lcdi_send(0x88);                     //提示输入日期
i=0;
while(message2[i]) lcdd_send(message2[i++]);
for(i=0;i<10;i++)                     //输入日期
{if(i==4||i==7) i++;
  while(key7289==1);
  send7289(0x15); //接收数据
  X=receive();
  cs7289=1;
  riqi[i]=X+0x30;
  j=0;
  lcdi_send(0x9a);
  for(j=0;j<10;j++) lcdd_send(riqi[j]);
  while(key7289==0);
  }
  while(key7289);
  nop1();
  while(key7289==0);
  nop1();
  lcdi_send(0x1);
}
//LCD子程序
void ini_lcd()         //LCD初始化子程序
{
lcdi_send(0x30);
lcdi_send(0x1);       //总清
lcdi_send(0xc);
lcdi_send(0x2);      //光标右移,AC+1
}
void lcdd_send(short X)        //LCD发送数据子程序
{chk_busy();
nop1();
lcd_di=1;lcd_rw=0;lcd_e=0;
P0=X;
for(dealy=0;dealy<5;dealy++);//
lcd_e=1; X=X;
P0=0xff;
}
void lcdi_send(short X)       //LCD发送指令子程序
{chk_busy();
nop1();
lcd_di=0;lcd_rw=0;lcd_e=0;
P0=X;
for(dealy=0;dealy<5;dealy++);//
lcd_e=1; X=X;
P0=0xff;
}
void chk_busy()
{short i=0xff;
while(i&0x80)
  {lcd_di=0;
   lcd_rw=1;
   lcd_e=0;
   i=P0;
   lcd_e=1;
  }
}
//7289子程序
void ini_7289()
{short i;
cs7289=1;  key7289=1; dio7289=1;     //7289初始化子程序
for(i=0;i<50;i++)
for(dealy=0;dealy<5000;dealy++);        //延时25ms
send7289(0xa4); cs7289=1;
}
void send7289(short X)         //7289发送数据子程序
{short i,j=1;
cs7289=0;
for(dealy=0;dealy<6;dealy++);  //延时50us
for(i=7;i>=0;i--)
    {j=j<<i;
     dio7289=X&j;
     j=1;j=1;clk7289=1;
     for(dealy=0;dealy<1;dealy++) ;   //延时10us
     clk7289=0;
     for(dealy=0;dealy<1;dealy++) ;   //延时10us
    }
  dio7289=0;
}
short receive()            //7289接收数据子程序
{short i,X=0;
dio7289=1;
for(dealy=0;dealy<6;dealy++);  //延时50us
for(i=0;i<=7;i++)
    {clk7289=1;
     for(dealy=0;dealy<1;dealy++);  //延时10us
     X=X<<1;
     if(dio7289)X++;
     clk7289=0;
     for(dealy=0;dealy<1;dealy++);   //延时10us
    }
dio7289=0;
return(X);
}
//ad
//AD子程序
int ad1()
{short k,x;
int ad_zhi=0,xz;
EA=0;
ad_start=1;
for(k=0;k<5;k++)
  { while(ad_stb);
     x=ad_244;
     x=x&0xf;
     ad_zhi=ad_zhi*10+x;
  }
  ad_start=0;
  EA=1;EX0=1;
  ad_zhi=ad_zhi>>1;
  xz=ad_zhi-50;
  xz=xz/100;
  ad_zhi=ad_zhi+xiuzheng[xz];
return(ad_zhi);

void d_change(long X)
{char qian,bai,shi,ge,shifen,baifen;
long int yu;
if(X>999999) error1();
qian=X/100000; yu=X%100000;
bai=yu/10000;  yu=yu%10000;
shi=yu/1000;   yu=yu%1000;
ge=yu/100;    yu=yu%100;
shifen=yu/10;
baifen=yu%10;

qian=qian+0x30;
bai=bai+0x30;
shi=shi+0x30;
ge=ge+0x30;
shifen=shifen+0x30;
baifen=baifen+0x30;
if(qian==0x30)
    {qian=0x20;
     if(bai==0x30)
       {bai=0x20;
        if(shi==0x30) shi=0x20;
       }
     }
shuju[0]=qian;
shuju[1]=bai;
shuju[2]=shi;
shuju[3]=ge;
shuju[4]='.';
shuju[5]=shifen;
shuju[6]=baifen;
}

void baojing()
{short i;
for(i=0;i<50;i++)
   {baoj=0;
    for(dealy=0;dealy<10;dealy++);
    baoj=1;
    for(dealy=0;dealy<10;dealy++);
   }
}
1: 狂晕,这怎么看啊?二天也看不完 2: 那里错了。到底那里错了?

共2条 1/1 1 跳转至

回复

匿名不能发帖!请先 [ 登陆 注册 ]