主题:函数调用有问题
keil里,我是用C语言编,我是把函数定义好做调用,但是我的数码管显示的是同一数,也就是我调用四次,但是运行的是同一个数,那位大虾帮忙看看!
程序如下:#include <reg52.h>
#include <intrins.h>
void display(unsigned char number);
void delay(unsigned int);/*延时定义*/
sbit pdata0=P1^3;/*定义管脚*/
sbit pclock=P1^4;
sbit a0=ACC^0;
sbit a1=ACC^1;
sbit a2=ACC^2;
sbit a3=ACC^3;
sbit a4=ACC^4;
sbit a5=ACC^5;
sbit a6=ACC^6;
sbit a7=ACC^7;
unsigned char data num1[]={0x81,0xcf,0x92,0x86,0xcc,0xa4,0xa0,0x8f,0x80,0x84};
void delay(unsigned int);
/*主程序*/
void main(void)
{
unsigned int time;
unsigned char a;
time=4215;
a=time/1000;
display(a);/*调用函数*/
delay(200);
a=time/100%10;
display(a);
delay(200);
a=time/10%10;
display(a);
delay(200);
a=time%10;
display(a);
delay(200);
while(1);
}
void display(unsigned char number)
{
unsigned char beer;
beer=num1[number];
ACC=beer;
pclock=1;pdata0=a0;_nop_();pclock=0;/*是序*/
pclock=1;pdata0=a1;_nop_();pclock=0;
pclock=1;pdata0=a2;_nop_();pclock=0;
pclock=1;pdata0=a3;_nop_();pclock=0;
pclock=1;pdata0=a4;_nop_();pclock=0;
pclock=1;pdata0=a5;_nop_();pclock=0;
pclock=1;pdata0=a6;_nop_();pclock=0;
pclock=1;pdata0=a7;_nop_();pclock=0;
delay(200);
}
我也是初学C语言,请帮忙看看!
程序如下:#include <reg52.h>
#include <intrins.h>
void display(unsigned char number);
void delay(unsigned int);/*延时定义*/
sbit pdata0=P1^3;/*定义管脚*/
sbit pclock=P1^4;
sbit a0=ACC^0;
sbit a1=ACC^1;
sbit a2=ACC^2;
sbit a3=ACC^3;
sbit a4=ACC^4;
sbit a5=ACC^5;
sbit a6=ACC^6;
sbit a7=ACC^7;
unsigned char data num1[]={0x81,0xcf,0x92,0x86,0xcc,0xa4,0xa0,0x8f,0x80,0x84};
void delay(unsigned int);
/*主程序*/
void main(void)
{
unsigned int time;
unsigned char a;
time=4215;
a=time/1000;
display(a);/*调用函数*/
delay(200);
a=time/100%10;
display(a);
delay(200);
a=time/10%10;
display(a);
delay(200);
a=time%10;
display(a);
delay(200);
while(1);
}
void display(unsigned char number)
{
unsigned char beer;
beer=num1[number];
ACC=beer;
pclock=1;pdata0=a0;_nop_();pclock=0;/*是序*/
pclock=1;pdata0=a1;_nop_();pclock=0;
pclock=1;pdata0=a2;_nop_();pclock=0;
pclock=1;pdata0=a3;_nop_();pclock=0;
pclock=1;pdata0=a4;_nop_();pclock=0;
pclock=1;pdata0=a5;_nop_();pclock=0;
pclock=1;pdata0=a6;_nop_();pclock=0;
pclock=1;pdata0=a7;_nop_();pclock=0;
delay(200);
}
我也是初学C语言,请帮忙看看!