标题:
单片机用数组名作为函数的参数进行传递实验
[打印本页]
作者:
liuda
时间:
2015-1-21 23:12
标题:
单片机用数组名作为函数的参数进行传递实验
是用51hei单片机开发板 电路图详见:
http://www.51hei.com/f/51hei-5.pdf
的数码管部分, 用2个74hc573 锁存,p0口作为数据口 ,p3.6和p3.7分别是段和位的锁存端口.P2口上面是按键
#include<reg52.h>
#define uchar unsigned char
#define uint unsigned int
uchar code SEG7[10]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};
sbit D=P3^6;
sbit V=P3^7;
uchar ACT[4]={0xfe,0xfd,0xfb,0xf7};
//===============
void sum(uint *q,uint n)
{
uint i,s;
uint *t;
t=q;
for(i=0;i<n;i++)s=s+*(t+i);
t=q+10;
*t=s;
}
//==========
void delay(uint k)
{
uint i,j;
for(i=0;i<k;i++){
for(j=0;j<121;j++)
{;}}
}
//===============
void main(void)
{
uint a[11]={0,1,2,3,4,5,6,7,8,9,0};
uint *pt,len=10;
pt=a;
sum(a,len);
while(1)
{
D=1;P0=SEG7[a[10]/1000];D=0;P0=0xff;V=1;P0=ACT[0];V=0;delay(5);
D=1;P0=SEG7[(a[10]/100)%10];D=0;P0=0xff;V=1;P0=ACT[1];V=0;delay(5);
D=1;P0=SEG7[(a[10]/10)%10];D=0;P0=0xff;V=1;P0=ACT[2];V=0;delay(5);
D=1;P0=SEG7[a[10]%10];D=0;P0=0xff;V=1;P0=ACT[3];V=0;delay(5);
}
}
复制代码
欢迎光临 (http://www.51hei.com/bbs/)
Powered by Discuz! X3.1