找回密码
 注册会员
更新自动建库工具PCB Footprint Expert 2024.04 Pro / Library Expert 破解版

新手求助,关于《51单片机C语言教程》里面的例程的疑问

[复制链接]
admin 发表于 2012-8-24 10:50:37 | 显示全部楼层 |阅读模式

本文包含原理图、PCB、源代码、封装库、中英文PDF等资源

您需要 登录 才可以下载或查看,没有账号?注册会员

×
关于显示子函数在几个例程里面的写法,有点晕,C语言不太会,麻烦大家了!
例3.5.2(75页),例4.1.1(82页),例5.3.1(107页)

1.在例3.5.2里面,是这样写void display(uchar shi,uchar ge)
例4.1.1里面,是这样写void display(uchar numdis)
为什么不同呢?
2.例3.5.2,在主程序中调用的时候,就是display(shi,ge);后面中断程序中是这样shi=num/10;
ge=num%10;
例5.3.1,在主程序中调用的时候,就是display(A1,A2,A3);后面又是这样写A1=adval/100;
A2=adval%100/10;
A3=adval%10;
那这里为什么用到A1,A2,A3?为什么不是直接用bai,shi,ge?


附上程序
例3.5.2
#include<reg52.h>
#define uchar unsigned char
#define uint unsigned int
sbit dula=P2^6;
sbit wela=P2^7;
sbit led1=P1^0;
uchar code table[]={
0x3f,0x06,0x5b,0x4f,
0x66,0x6d,0x7d,0x07,
0x7f,0x6f,0x77,0x7c,
0x39,0x5e,0x79,0x71};
void display(uchar,uchar);
void delayms(uint);
uchar num,num1,num2,shi,ge;
void main()
{
TMOD=0x11;
TH0=(65536-45872)/256;
TL0=(65536-45872)%256;
TH1=(65536-45872)/256;
TL1=(65536-45872)%256;
EA=1;
ET0=1;
ET1=1;
TR0=1;
TR1=1;
while(1)
{
display(shi,ge);
}
}
void display(uchar shi,uchar ge)
{
dula=1;
P0=table[shi];
dula=0;
P0=0xff;
wela=1;
P0=0xfe;
wela=0;
delayms(5);
dula=1;
P0=table[ge];
dula=0;
P0=0xff;
wela=1;
P0=0xfd;
wela=0;
delayms(5);
}
void delayms(uint xms)
{
uint i,j;
for(i=xms;i>0;i--)
for(j=110;j>0;j--);
}
void T0_time() interrupt 1
{
TH0=(65536-45872)/256;
TL0=(65536-45872)%256;
num1++;
if(num1==4)
{
num1=0;
led1=~led1;
}
}
void T1_time() interrupt 3
{
TH1=(65536-45872)/256;
TL1=(65536-45872)%256;
num2++;
if(num2==20)
{
num2=0;
num++;
if(num==60)
num=0;
shi=num/10;
ge=num%10;

}
}


例4.1.1
#include<reg52.h>
#define uchar unsigned char
#define uint unsigned int
sbit key1=P3^4;
sbit key2=P3^5;
sbit key3=P3^6;
sbit key4=P3^7;
sbit dula=P2^6;
sbit wela=P2^7;
uchar code table[]={
0x3f,0x06,0x5b,0x4f,
0x66,0x6d,0x7d,0x07,
0x7f,0x6f,0x77,0x7c,
0x39,0x5e,0x79,0x71};
void delayms(uint);
uchar numt0,num;
void display(uchar numdis)
{
uchar shi,ge;
shi=numdis/10;
ge=numdis%10;
dula=1;
P0=table[shi];
dula=0;
P0=0xff;
wela=1;
P0=0xfe;
wela=0;
delayms(5);
dula=1;
P0=table[ge];
dula=0;
P0=0xff;
wela=1;
P0=0xfd;
wela=0;
delayms(5);

}
void delayms(uint xms)
{
uint i,j;
for(i=xms;i>0;i--)
for(j=110;j>0;j--);
}
void init()
{
TMOD=0x01;
TH0=(65536-45872)/256;
TL0=(65536-45872)%256;
EA=1;
ET0=1;
}
void keyscan()
{
if(key1==0)
{
delayms(10);
if(key1==0)
{
num++;
if(num==60)
num=0;
while(!key1);
}
}
if(key2==0)
{
delayms(10);
if(key2==0)
{
if(num==0)
num=60;
num--;
while(!key2);
}
}
if(key3==0)
{
delayms(10);
if(key3==0)
{
num=0;
while(!key3);
}
}
if(key4==0)
{
delayms(10);
if(key4==0)
{
while(!key4);
TR0=~TR0;
}
}
}
void main()
{
init();
while(1)
{
keyscan();
display(num);
}
}
void T0_time() interrupt 1
{
TH0=(65336-45872)/256;
TL0=(65336-45872)%256;
numt0++;
if(numt0==20)
{
numt0=0;
num++;
if(num==60)
num=0;
}
}


例5.3.1
#include<reg52.h>
#include<intrins.h>
#define uchar unsigned char
#define uint unsigned int
sbit dula=P2^6;
sbit wela=P2^7;
sbit adwr=P3^6;
sbit adrd=P3^7;
uchar code table[]={
0x3f,0x06,0x5b,0x4f,
0x66,0x6d,0x7d,0x07,
0x7f,0x6f,0x77,0x7c,
0x39,0x5e,0x79,0x71};
void delayms(uint xms)
{
uint i,j;
for(i=xms;i>0;i--)
for(j=110;j>0;j--);
}
void display(uchar bai,uchar shi,uchar ge)
{
dula=1;
P0=table[bai];
dula=0;
P0=0xff;
wela=1;
P0=0x7e;
wela=0;
delayms(5);
dula=1;
P0=table[shi];
dula=0;
P0=0xff;
wela=1;
P0=0x7d;
wela=0;
delayms(5);
dula=1;
P0=table[ge];
dula=0;
P0=0xff;
wela=1;
P0=0x7b;
wela=0;
delayms(5);
}
void main()
{
uchar a,A1,A2,A3,adval;
wela=1;
P0=0x7f;
wela=0;
while(1)
{
adwr=1;
_nop_();
adwr=0;
_nop_();
adwr=1;
for(a=10;a>0;a--)
{
display(A1,A2,A3);
}
P1=0xff;
adrd=1;
_nop_();
adrd=0;
_nop_();
adval=P1;
adrd=1;
A1=adval/100;
A2=adval%100/10;
A3=adval%10;

}
}
*滑块验证:
您需要登录后才可以回帖 登录 | 注册会员

本版积分规则

QQ|手机版|MCU资讯论坛 ( 京ICP备18035221号-2 )|网站地图

GMT+8, 2024-11-23 10:41 , Processed in 0.067099 second(s), 10 queries , Redis On.

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表