? 两位计数器显示
电路设计
代码设计
1.在keil端进行代码编写,将实验代码进行编译,结果正确无任何错误。
2.打开Proteus软件,绘制原理图,放置元件,双击AT89C51单片机芯片,将keil端编译之后生成的HEX文件加载到芯片内。
启动仿真
按下第一个按钮,即P3^3对应的start按钮,电路开始计数,显示屏开始显示数字并自增,如下图
然后按下第二个按钮,即P3^4对应的stop按钮,电路暂停计数,显示屏数字保持不变,如下图
最后按下第一个按钮start,电路从0开始计数
#include<reg51.h>
sbit S1 = P3^0; // Select line 1 for Display 1
sbit S2 = P3^1; // Select Line 2 for Display 2
sbit START = P3^3; //START
sbit STOP ?= P3^4; //STOP
void delay(int d)
{
int i,j;
for(i=0;i<d;i++)
for(j=0;j<255;j++);
}
void main()
{
//DP?′á??ó£?×?????è?òa
int arr[10] = {0xC0, 0xF9, 0xA4, 0xB0, 0x99, 0x92, 0x82, 0xF8,0x80, 0x90}; // ******Your codes is required here!!!
int i,on,off;
static int num1,num2,temp1,temp2;
while(1){
if ((START==0)&&(STOP==1))
{
?on = 1;
off = 0;
}
else
{
?on = 0;
off = 1;
}
while(on && !off)
{
for(i=0;i<100;i++)
{
num1 = i/10; ???//First Digit Separated
temp1 = num1;
S1 = 1; //Select Line 1
S2 = 0;
P2 = arr[num1]; ?//Display 1 will indicate number
delay(45);
num2 = i%10; ???//Second Digit Separated
????????????????// *****Your codes is required here!!!
temp2 = num2;
S1 = 0;
S2 = 1;
P2 = arr[num2];
delay(45);
if(STOP==0)
{
off = 1;
?on = 0;
break;
}
}
while(off && !on)
{
S1=1;
S2=0;
P2 = arr[temp1];
delay(10);
S1=0;
S2=1;
P2 = arr[temp2];
delay(30);
if (START==0)
{
off = 0;
?on = 1;
break;
}
}
}
}
}
#include<reg51.h>
sbit S1 = P3^0; // Select line 1 for Display 1
sbit S2 = P3^1; // Select Line 2 for Display 2
sbit START = P3^3; //START
sbit STOP = P3^4; //STOP
void delay(int d)
{
int i,j;
for(i=0;i<d;i++)
for(j=0;j<255;j++);
}
void main()
{
//DP?′á??ó£?×?????è?òa
int arr[10] = {0xC0, 0xF9, 0xA4, 0xB0, 0x99, 0x92, 0x82, 0xF8,0x80, 0x90}; // ******Your codes is required here!!!
int i,on,off;
static int num1,num2,temp1,temp2;
while(1){
if ((START==0)&&(STOP==1))
{
on = 1;
off = 0;
}
else
{
on = 0;
off = 1;
}
while(on && !off)
{
for(i=0;i<100;i++)
{
num1 = i/10; //First Digit Separated
temp1 = num1;
S1 = 1; //Select Line 1
S2 = 0;
P2 = arr[num1]; //Display 1 will indicate number
delay(45);
num2 = i%10; //Second Digit Separated
// *****Your codes is required here!!!
temp2 = num2;
S1 = 0;
S2 = 1;
P2 = arr[num2];
delay(45);
if(STOP==0)
{
off = 1;
on = 0;
break;
}
}
while(off && !on)
{
S1=1;
S2=0;
P2 = arr[temp1];
delay(10);
S1=0;
S2=1;
P2 = arr[temp2];
delay(30);
if (START==0)
{
off = 0;
on = 1;
break;
}
}
}
}
}
可私信获取项目文件