1987的一个人 发表于 2012-10-17 16:54:53

问下高手一个广域C语言参数传递的问题

void xianshi()
{
        uchar i,j;
        xs(tempdata,4,4);
        xs(tempdata,6,6);
        for(i = 0;i<8;i++)
        {
                w_shuzi(i,0,table1);
                j = 8+i;
                w_shuzi(i,0,table1);
        }
}
void w_shuzi(uchar x,uchar y,uchar zz)
{
        uchar i,z;
        z = zz;
        LCD_add(x*6,y);
        for(i = 0;i<6;i++)
                LCD_write_dat(shuzi);
        LCD_add(x*6,y+1);
        for(i = 6;i<12;i++)
                LCD_write_dat(shuzi);               
}

当这个函数进行传递时 w_shuzi(i,0,table1); 是正常如i=0;table1 = 0;zz = 0x00;
但当w_shuzi(i,0,table1);确不能正常传递函数。i = 0j=8;table1 = 0;zz = 0xff;
这是什么原因?

lcw_swust 发表于 2012-10-17 17:12:52

table1怎么定义的

1987的一个人 发表于 2012-10-17 17:21:18

unsigned char table1;

1987的一个人 发表于 2012-10-17 17:21:40

lcw_swust 发表于 2012-10-17 17:12 static/image/common/back.gif
table1怎么定义的


unsigned char table1;

lcw_swust 发表于 2012-10-17 17:24:47

1987的一个人 发表于 2012-10-17 17:21 static/image/common/back.gif
unsigned char table1;

用的KEIL编译器?
断点在哪个位置?

zcoder 发表于 2012-10-17 17:40:50

你的断电在哪?

1987的一个人 发表于 2012-10-17 19:44:34

lcw_swust 发表于 2012-10-17 17:24 static/image/common/back.gif
用的KEIL编译器?
断点在哪个位置?

断点是
void xianshi()函数的for循环。

1987的一个人 发表于 2012-10-17 19:44:50

zcoder 发表于 2012-10-17 17:40 static/image/common/back.gif
你的断电在哪?

断点是
void xianshi()函数的for循环。

1987的一个人 发表于 2012-10-17 19:53:49

lcw_swust 发表于 2012-10-17 17:24 static/image/common/back.gif
用的KEIL编译器?
断点在哪个位置?

是用keil调试的 请问我还有什么没描述清楚的么

gamalot 发表于 2012-10-17 20:14:54

本帖最后由 gamalot 于 2012-10-17 20:20 编辑

1987的一个人 发表于 2012-10-17 19:53 static/image/common/back.gif
是用keil调试的 请问我还有什么没描述清楚的么

我很想知道什么是“广域C语言参数传递”

看懂了,是“关于”吧 ......

你的程序我跑了一下,参数传递没问题,你最好把代码贴出来,尤其是那个table1数组

1987的一个人 发表于 2012-10-17 20:26:08

gamalot 发表于 2012-10-17 20:14 static/image/common/back.gif
我很想知道什么是“广域C语言参数传递”

看懂了,是“关于”吧 ......


#include<reg52.h>
#include"LCD.h"
#defineuchar unsignedchar
#defineuint unsignedint
sbit CS = P3^2;
sbit RES = P0^1;
sbit A0 = P3^3;
sbit l_scl = P2^3;
sbit l_sda = P2^2;
extern h_tem,l_tem;
extern table1,tempdata;
uchar table,result1,result2;
uchar code shuzi[]=
{
/*--文字:0--*/
0xF8,0x04,0x04,0x04,0xF8,0x00,0x01,0x02,0x02,0x02,0x01,0x00,

/*--文字:1--*/
0x00,0x08,0xFC,0x00,0x00,0x00,0x00,0x02,0x03,0x02,0x00,0x00,

/*--文字:2--*/
0x18,0x84,0x44,0x24,0x18,0x00,0x03,0x02,0x02,0x02,0x02,0x00,

/*--文字:3--*/
0x08,0x04,0x24,0x24,0xD8,0x00,0x01,0x02,0x02,0x02,0x01,0x00,

/*--文字:4--*/
0x40,0xB0,0x88,0xFC,0x80,0x00,0x00,0x00,0x00,0x03,0x02,0x00,

/*--文字:5--*/
0x3C,0x24,0x24,0x24,0xC4,0x00,0x01,0x02,0x02,0x02,0x01,0x00,

/*--文字:6--*/
/*--宋体9;此字体下对应的点阵为:宽x高=6x12   --*/
/*--高度不是8的倍数,现调整为:宽度x高度=6x16--*/
0xF8,0x24,0x24,0x2C,0xC0,0x00,0x01,0x02,0x02,0x02,0x01,0x00,

/*--文字:7--*/
0x0C,0x04,0xE4,0x1C,0x04,0x00,0x00,0x00,0x03,0x00,0x00,0x00,

/*--文字:8--*/
0xD8,0x24,0x24,0x24,0xD8,0x00,0x01,0x02,0x02,0x02,0x01,0x00,

/*--文字:9--*/
0x38,0x44,0x44,0x44,0xF8,0x00,0x00,0x03,0x02,0x02,0x01,0x00,
};
void LCD_write_dat(uchar dat) //写数据
{
        uchar i;
        CS = 0;
        A0 = 1;
        for(i = 0;i<8;i++)
        {
                if(0x80 == (dat&0x80))
                        l_sda = 1;
                else l_sda = 0;
                dat = dat<<1;
                l_scl = 0;
                l_scl = 1;
        }
        CS = 1;       
}
void LCD_write_com(uchar com) //写命令
{
        uchar i;
        CS = 0;
        A0 = 0;
        for(i = 0;i<8;i++)
        {
                if(0x80 == (com&0x80))
                        l_sda = 1;
                else l_sda = 0;
                com = com<<1;
                l_scl = 0;
                l_scl = 1;
        }
        CS = 1;       
}
void LCD_add(uchar x,y) //写命令
{
        LCD_write_com(0xb0|y);
        x = x+4;
        LCD_write_com(x>>4|0x10);           //要写两次地址
        LCD_write_com(x&0x0f);
}

void w_shuzi(uchar x,uchar y,uchar zz)
{
        uchar i,z;
        z = zz;
        LCD_add(x*6,y);
        for(i = 0;i<6;i++)
                LCD_write_dat(shuzi);
        LCD_add(x*6,y+1);
        for(i = 6;i<12;i++)
                LCD_write_dat(shuzi);               
}
void LCD_qingping(uchar aa)
{
        uchar page,j;
       for(page = 0;page<8;page++)
               for(j = 0;j<128;j++)
                {
                        LCD_add(j,page);       
                        LCD_write_dat(aa);
                }
}
void delay_1(uint z)
{
        uint x,y;
        for(x=0;x<z;x++)
                for(y=0;y<148;y++);
}
void LCD_init()
{
//        CS=0;
//        res();   
/*        LCD_write_com(0xA2);    //LCD偏压设置,V3时选--LCD Bias selection(1/65 Duty,1/9Bias)   
        LCD_write_com(0xA1);    //Segment方向选择,正常--ADC selection(SEG0->SEG128)   
        LCD_write_com(0x80);    //设置显示起始行对应RAM--SHL selection(COM0->COM64)   
          
       delay(5);
       LCD_write_com(0x26);    //设置Rb/Ra=6--Regulator Resistor Selection   
       LCD_write_com(0x81);    //电量设置模式(显示亮度)--Electronic Volume
       LCD_write_com(0x08);   //Reference Register selectionVo=(1+Rb/Ra)(1+a)*2.1=10
       
       delay(10);
       LCD_write_com(0x2f);       //设置上电控制模式--Power Control(Vc=1;Vr=1;Vf=1)   
       delay(10);
       LCD_write_com(0xF8);    //升压比设置
       LCD_write_com(0x00);   
       delay(5);
        LCD_write_com(0xAF);    //LCD显示开--Display on
       delay(5);
        LCD_write_com(0xa4);*/
        LCD_write_com(0xaf); //开关指令       
        LCD_write_com(0x40); //读状态设置
        LCD_write_com(0xa1);//ADC选择
        LCD_write_com(0xa6); //正向显示
        LCD_write_com(0xa2); //偏压比设置
        LCD_write_com(0xa4); //全屏点亮设置
        LCD_write_com(0xe0); //读写操作
        LCD_write_com(0xc0); //COM口正常方向扫描
        LCD_write_com(0x2f); //上电控制
        LCD_write_com(0x23); //电阻控制
        LCD_write_com(0x3f); //电量控制
        LCD_write_com(0x81); //电量控制
        LCD_write_com(0xad); //静态指示器关        */
}
void xianshi()
{
        char i;
//        xs(tempdata,4,4);
        xs(tempdata,0,0);
        for(i = 0;i<8;i++)
        {
//                w_shuzi(i,0,table1);
                w_shuzi(i,2,table1);
        }
}
void xs(uchar dd,uchar i,uchar k)//结果显示函数,dd 要显示的函数,k显示的列数位置,i显示行数位置
{
   uint temp4,temp5,shu;
   char j = 0;
   if(dd<10)
   {
                   w_shuzi(k,i,0);
                w_shuzi(k+1,i,dd);               
   }
   else
   {
      while(dd)
               {
                        temp4 = dd/10;
                        temp5 = dd%10;
                        shu = temp5;       
                        dd = temp4;
               }
               for(--j;j>=0;j--)
               {
                        w_shuzi(k++,i,shu);
               }
        }
}

1987的一个人 发表于 2012-10-17 20:29:47

gamalot 发表于 2012-10-17 20:14 static/image/common/back.gif
我很想知道什么是“广域C语言参数传递”

看懂了,是“关于”吧 ......


table1是在另外一个c文件定义的

#include<reg52.h>
#include<intrins.h>
#include"ds1624r.h"
uchar table1,count;
uchar tempdata;
extern h_tem,l_tem;
sbit SDA = P1^6;
sbit SCL = P1^5;
void init()
{
SCL=1;
delay();
SDA=1;
delay();
/*SCL=0;
delay();
i_stop();*/
}

void delay(void)
{
   _nop_();
   _nop_();
   _nop_();
   _nop_();
   _nop_();
   _nop_();
   
}

void i_start(void)        // iic开始传输
{
    SDA=1;
        delay();
    SCL=1;
        delay();
        SDA=0;
        delay();
        SCL=0;
        delay();
}

void i_send(uchar i_com)
{
uchar i;
for(i=0;i<8;i++)
    {
      SDA=(i_com&0x80);
      i_com=i_com<<1;
      SCL=1;
      delay();
      SCL=0;
      delay();
    }
SDA=1;
SCL=1;

}

void i_stop(void) //iic停止传输
{
SDA=0;
delay();
SCL=1;
delay();
SDA=1;
delay();
SCL=0;
delay();


}


void start_temp()
{
   i_start();
   delay();
   i_send(0x90);
   ack();
   i_send(0xee);
   ack();
   i_stop();
}

void respons()
{
   SDA=0;
   SCL=1;
   delay();
   SCL=0;
   delay();
   SDA=1;
   delay();
   SCL=1;           //
   delay();                //
}

void read_temp()
{
   
   i_start();
   i_send(0x90);
   ack();
   i_send(0xaa);
   ack();
   i_start();
   i_send(0x91);
   ack();
   count = 0;
   tempdata=receive_temp();
   respons();
   count = 8;
   tempdata=receive_temp();
   i_stop();
}

uchar receive_temp()
{
bit sample=0;
uchar i_data=0;
uchar i;
for(i=0;i<8;i++)
    {
         SCL=1;
         delay();
         sample=SDA;
         _nop_();
               _nop_();
               _nop_();
         SCL=0;
         delay();
               table1=sample;
         i_data*=2;
         if(sample==1) i_data++;
         delay();      
    }
    return(i_data)       ;
}

void ack()
{
uchar x=0;
SCL=1;
delay();
while((SDA==1)&&(x<50))x++;
SCL=0;
delay();
}   

zcoder 发表于 2012-10-17 22:56:01

1987的一个人 发表于 2012-10-17 19:44 static/image/common/back.gif
断点是
void xianshi()函数的for循环。

zz这个变量你要到 函数w_shuzi里面去看。
在xianshi()里你是看不到zz的值的,或是不正确的。

1987的一个人 发表于 2012-10-17 23:27:28

zcoder 发表于 2012-10-17 22:56 static/image/common/back.gif
zz这个变量你要到 函数w_shuzi里面去看。
在xianshi()里你是看不到zz的值的,或是不正确的。 ...

之后又单步进去w_shuzi();函数 就发现参数传递过去式错误的了
上面一个倒是不会就是下面那个函数传递过去式错的

lcw_swust 发表于 2012-10-18 09:41:09

本帖最后由 lcw_swust 于 2012-10-18 09:42 编辑

我这没问题:




页: [1]
查看完整版本: 问下高手一个广域C语言参数传递的问题