电源设计技术实用资料点击免费获取>>
电子产品世界 » 论坛首页 » 综合技术 » 基础知识 » 用C编程者请进!


共2条 1/1 1 跳转至

用C编程者请进!

院士
2006-12-22 22:43:00    评分
用C编程者请进!



关键词: 编程     请进    

院士
2006-12-22 22:43:00    评分
2楼
问  #include<reg51.h>
   #define  uchar  unsigned char
   #define  uint   unsigned int
   uchar    code   c_code[]={0x21};
   uchar    a_1,a_2,b_1,b_2;
   uint     key,f,g;
   uchar   bdata   st_f;
   sbit    fly=st_f^0;
   sbit    flag=st_f^1;              
   sbit    caij=st_f^2;
   sbit    flag_f1=PSW^1;
   sbit    flag_f0=PSW^5;
   sbit    P1_0=P1^0;
   sbit    P1_1=P1^1;
   sbit    P1_2=P1^2;
   sbit    P1_3=P1^3;
   sbit    P3_0=P1^0;
   sbit    P3_1=P1^1;
   sbit    P3_2=P1^2;
   sbit    P3_5=P1^5;
   sbit    P3_7=P1^7;
   void    int_tr(void) interrupt 0 using 1
           {P1_3=1;
            if(P1_3==0)
            {P1_2=flag_f0;
             if(P1_3==1)
                P3_1=1;}
             if(P3_0==0)
             {P1_1=flag_f1;
              P3_1=1;
              if(P3_0==1)
                P3_1=1;}
              P1_0=fly;
              fly=1;
              flag=1;}
   void     delay(void)
            {uchar  i,j;
             for(i=0;i<=100;i++)
                 for(j=0;j<=254;j++)
                     ;
              }
   uint       hh(void)
             { uchar   k;
              k=P1;
              k=k>>4;
              return(c_code[k]);
              }
   void      main(void)
             {TCON=0x01;
              delay();
              key=hh();
              IE=0x81;
              caij=0;
              while(1)
              {
                uchar  c_1,c_2,d_1,d_2;
                TMOD=0x1d;
                TH1=0xfc;
                TL1=0x18;
                TH0=0;
                TL0=0;
                TR0=1;
                TR1=1;
                while(!TF1);
                TF1=0;
                TR0=0;
                TR1=0;
                if(caij==0)
                {a_1=TH0;
                a_2=TL0; }
                else
                {c_1=TH0;
                c_2=TL0;}
                P3_7=1;
                fly=1;
                if(c_1>a_1)
                  {P3_7=0;
                   fly=0;}
                f=a_1*256+a_2;
                g=c_1*256+c_2;
                if(g>f+key)
                   flag_f0=0;
                TMOD=0xd1;
                TH0=0xfc;
                TL0=0x18;
                TH1=0;
                TL1=0;
                TR0=1;
                TR1=1;
                while(!TF0);
                TF1=0;
                TR0=0;
                TR1=0;
                if(caij==0)
                {b_1=TH1;
                 b_2=TL1;}
                 else
                {d_1=TH1;
                 d_2=TL1;}
                P3_7=1;
                flag=1;
                if(d_1>b_1)
                  {P3_7=0;
                   flag=0;}
                f=b_1*256+b_2;
                g=b_1*256+b_2;
                if(g>f+key)
                   flag_f1=0;
                caij=1;
                key=hh();
                if(fly&flag==1)
                   caij=0;
                }
                 }



#include<reg51.h>
   #define  uchar  unsigned char
   #define  uint   unsigned int
   uchar    code   c_code[]={0x21};
   uchar    a_1,a_2,b_1,b_2;
   uint     key,f,g;
   uchar   bdata   st_f;
   sbit    fly=st_f^0;
   sbit    flag=st_f^1;              
   sbit    caij=st_f^2;
   sbit    flag_f1=PSW^1;
   sbit    flag_f0=PSW^5;
   sbit    P1_0=P1^0;
   sbit    P1_1=P1^1;
   sbit    P1_2=P1^2;
   sbit    P1_3=P1^3;
   sbit    P3_0=P1^0;
   sbit    P3_1=P1^1;
   sbit    P3_2=P1^2;
   sbit    P3_5=P1^5;
   sbit    P3_7=P1^7;
   void    int_tr(void) interrupt 0 using 1
           {P1_3=1;
            if(P1_3==0)
            {P1_2=flag_f0;
             if(P1_3==1)
                P3_1=1;}
             if(P3_0==0)
             {P1_1=flag_f1;
              P3_1=1;
              if(P3_0==1)
                P3_1=1;}
              P1_0=fly;
              fly=1;
              flag=1;}
   void     delay(void)
            {uchar  i,j;
             for(i=0;i<=100;i++)
                 for(j=0;j<=254;j++)
                     ;
              }
   uint       hh(void)
             { uchar   k;
              k=P1;
              k=k>>4;
              return(c_code[k]);
              }
   void      main(void)
             {TCON=0x01;
              delay();
              key=hh();
              IE=0x81;
              caij=0;
              while(1)
              {
                uchar  c_1,c_2,d_1,d_2;
                TMOD=0x1d;
                TH1=0xfc;
                TL1=0x18;
                TH0=0;
                TL0=0;
                TR0=1;
                TR1=1;
                while(!TF1);
                TF1=0;
                TR0=0;
                TR1=0;
                if(caij==0)
                {a_1=TH0;
                a_2=TL0; }
                else
                {c_1=TH0;
                c_2=TL0;}
                P3_7=1;
                fly=1;
                if(c_1>a_1)
                  {P3_7=0;
                   fly=0;}
                f=a_1*256+a_2;
                g=c_1*256+c_2;
                if(g>f+key)
                   flag_f0=0;
                TMOD=0xd1;
                TH0=0xfc;
                TL0=0x18;
                TH1=0;
                TL1=0;
                TR0=1;
                TR1=1;
                while(!TF0);
                TF1=0;
                TR0=0;
                TR1=0;
                if(caij==0)
                {b_1=TH1;
                 b_2=TL1;}
                 else
                {d_1=TH1;
                 d_2=TL1;}
                P3_7=1;
                flag=1;
                if(d_1>b_1)
                  {P3_7=0;
                   flag=0;}
                f=b_1*256+b_2;
                g=b_1*256+b_2;
                if(g>f+key)
                   flag_f1=0;
                caij=1;
                key=hh();
                if(fly&flag==1)
                   caij=0;
                }
                 }


ERROR L107:ADDRESS   SPACE  OVERFLOW
     SPACE:CODE
   SEGMENT:?PR?MIAN?2051
   LENGTH:00FDH
PROGRAM  SIZE:DATA=24.0   XDATA=0   CODE=342
TARGET   NOT   CREATED
小弟处次用C请指点!
1: 这两句有问题。 "
f=a_1*256+a_2;
g=c_1*256+c_2;
"
类型不匹配。结果不会超过256。 2: 谢谢!希望大家继续指出错误,很批!! 3: 但编译指出的错与那两条语句无关查一下“{”是否匹配。有无遗漏“;”等 4: 程序编译可以通过。 5: 谢yangtse,我检查过了,通不过啊 6: 怎么两个主函数阿,有问题的是哪个项目呢,看不明白 7: 试了可以过的谢yangtse,我检查过了,通不过啊
-----------
我试了可以过的。你的编译器是keil uVision2吗? 8: 是啊keil  uVision2难道是我设置不对吗
应怎么 社 keil  uVision2 9: 注意格式注意格式,这样怎么看,注意美观。 10: 你最好换个编译器再试一下 11: 推荐用PC-LINT查。推荐用PC-LINT查。 12: 怎么都不看提示?CODE地址空间覆盖冲突
段SEGMENT:?PR?MIAN?2051
LENGTH:00FDH


该不会是楼主从别处拷贝程序时粘贴了2次?
弄出了2个main?


13: 最差的是风格,居然没有一句注释!!! 14: 看你的c怎么和看汇编一样的感觉啊?我以前用汇编写冬冬时注释不比代码少,看起来也没有这么吃力
15: 呵呵!我也觉得!你就不怕你忘了某句是什么意思吗?加点注释吧! 16: 我也有这种感决 17: 这几句是什么?   uchar   bdata   st_f;
   sbit    fly=st_f^0;
   sbit    flag=st_f^1;              
   sbit    caij=st_f^2;

我晕
18: 酷!居然把C做的具有汇编的境界! 19: 一点建议   uchar   bdata   st_f;
   sbit    fly=st_f^0;
   sbit    flag=st_f^1;              
   sbit    caij=st_f^2;

定义位变量不用这么复杂的,直接bit fly,flag,caij;岂不方便?还省了一个st_f变量。sbit  一般是用来定义管脚的。SFR的设置一般单独写到子程序里,不要加到主程序中,这样显得很乱。另外,uchar    code   c_code[]={0x21};
return(c_code[k]); 不明白你要做什么,你的数组只有一个数据,还c_code[k]);
要作什么?感觉楼主还没有明白数组的用法,建议最好还是先弄懂了再用。 

共2条 1/1 1 跳转至

回复

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