题目要求:
两位数码管从1开始增加,直到99,而后又开始从1增加。
仿真电路图:
实验代码:
#include <at89x51.h>
unsigned char duanma[]={0x3F,0x06,0x5B,0x4F,0x66,0x6D,0x7D,0x07,0x7F,0x6F};
unsigned int shuzi,num;
sbit ge=P1^1;
sbit shi=P1^0;
void delay();
void main()
{
shuzi=0;
num=0;
P2=0x00;
for(num=0;num<99;num++)
{
P2=0x00;
shuzi++;
ge=0;
shi=1;
P2=duanma[shuzi%10];
delay();
ge=1;
shi=0;
P2=duanma[shuzi/10];
delay();
P2=0x00;
}
}
void delay()
{
unsigned int i,j;
for(i=0;i<1000;i++);
for(j=0;j<5000;j++);
}