#include<reg51.h>
#define uchar unsigned char void delay() { uchar i,j,k; for(i=0;i<10;i++) for(j=0;j<100;j++) for(k=0;k<6;k++) { ;} } uchar conv(uchar digit) {uchar mid; switch(digit) {case 0:mid=0x3f; break; case 1:mid=0x06; break; case 2:mid=0x5b; break; case 3:mid=0x4f; break; case 4:mid=0x66; break; case 5:mid=0x6d; break; case 6:mid=0x7d; break; case 7:mid=0x07; break; case 8:mid=0x7f; break; case 9:mid=0x6f; break; default:break; } return mid; } uchar *bcd(uchar k) {uchar car[4]; car[0]=k%10; k=k/10; if(car[0]>9) { car[0]=car[0]-10; k=k+1;} car[1]=k%10; k=k/10; if(car[1]>9) { car[1]=car[1]-10; k=k+1;} car[2]=k%10; k=k/10; if(car[2]>9) { car[2]=car[2]-10; k=k+1;} car[3]=k%10; k=k/10; if(car[3]>9) { car[3]=car[3]-10; k=k+1;} return car;} void main(void) { uchar xdata temp[10]; uchar i,j; uchar a[4]; int sum=0; for(i=0;i<3;i++) temp=i+1; for(j=0;j<3;j++) sum=temp[j]+sum; for( ; ;) {a=bcd(sum); P3=0x01; for(i=0;i<4;i++) {P1=conv(a); delay2(); P3=P3<<1;} } 其中a=bcd(sum)返回数组首地址的值,为什么不行! |