當前位置:編程學習大全網 - 編程軟體 - 單片機C51編程(C語言):1到100的求和顯示,在數碼管裏顯示出來.

單片機C51編程(C語言):1到100的求和顯示,在數碼管裏顯示出來.

#include?<reg51.h>

#include?<stdio.h>

#define?uchar?unsigned?char

void?convert();

void?display();

void?delay();

//***陰:0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F

code?unsigned?char?Led[16]={0x3F,0x06,0x5B,0x4F,0x66,0x6D,0x7D,0x07,0x7F,0x6F,

0x77,0x7C,0x39,0x5E,0x79,0x71};

uchar?num,sw,gw;

void?main()

{

num=0;

while(1)

{

convert();

display();

delay();

num++;

if(num==100)num=0;

}

}

void?convert()

{

sw=num/10;

gw=num%10;

}

void?display()

{

P1=Led[gw];

P2=Led[sw];?

}

void?delay()

{

uchar?i,j,k;

for(k=0;k<2;k++)

for(i=0;i<250;i++)

for(j=0;j<250;j++);

}

使用仿真軟件電路連接如下圖

  • 上一篇:圖形化計算思維課適合多大孩子學
  • 下一篇:!(--x)在c語言中是什麽意思?
  • copyright 2024編程學習大全網