A. 單片機C51編程(C語言):1到100的求和顯示,在數碼管里顯示出來.
#include<reg51.h>
#include<stdio.h>
#defineucharunsignedchar
voidconvert();
voiddisplay();
voiddelay();
//共陰:0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F
codeunsignedcharLed[16]={0x3F,0x06,0x5B,0x4F,0x66,0x6D,0x7D,0x07,0x7F,0x6F,
0x77,0x7C,0x39,0x5E,0x79,0x71};
ucharnum,sw,gw;
voidmain()
{
num=0;
while(1)
{
convert();
display();
delay();
num++;
if(num==100)num=0;
}
}
voidconvert()
{
sw=num/10;
gw=num%10;
}
voiddisplay()
{
P1=Led[gw];
P2=Led[sw];
}
voiddelay()
{
uchari,j,k;
for(k=0;k<2;k++)
for(i=0;i<250;i++)
for(j=0;j<250;j++);
}
使用模擬軟體電路連接如下圖