#include <REG52.H>
#include <stdio.h>
#include <intrins.h>
sbit startButton=P0^0;
sbit pauseButton=P0^1;
sbit resetButton=P0^2;
sbit exitButton=P0^3;
void time(unsigned int ucMs);
unsigned char HEXtoBCD (unsigned char hex)
{
return ((hex/10)*16+(hex%10));
}
void main (void)
{
unsigned char uc10ms=0,uc1s=0,uc60s=0;
while (1) {
exitButton =1;
uc10ms=0,uc1s=0,uc60s=0;
P1=HEXtoBCD(uc10ms);
P2=HEXtoBCD(uc1s);
P3=HEXtoBCD(uc60s);
while (startButton);
while (!startButton);
while(exitButton){
time(7);
uc10ms++;
if (uc10ms==100){
uc10ms=0;uc1s++;
}
P1=HEXtoBCD(uc10ms);
if(uc1s==60){
uc1s=0;uc60s++;
}
P2=HEXtoBCD(uc1s);
if(uc60s==60){
uc60s=0;
}
P3=HEXtoBCD(uc60s);
if(!pauseButton){
while(!pauseButton);
while(pauseButton){
if(!resetButton){
uc10ms=0,uc1s=0,uc60s=0;
P1=HEXtoBCD(uc10ms);
P2=HEXtoBCD(uc1s);
P3=HEXtoBCD(uc60s);
}
if(exitButton==0){
exitButton=0;
break;
}
}
while (!pauseButton);
}
if(!resetButton){
uc10ms=0,uc1s=0,uc60s=0;
P1=HEXtoBCD(uc10ms);
P2=HEXtoBCD(uc1s);
P3=HEXtoBCD(uc60s);
}
}
}
}
void delay_5us(void)
{
_nop_();
_nop_();
_nop_();
_nop_();
}
void delay_50us(void)
{
unsigned char i;
for (i=0;i<4;i++)
{
delay_5us();
}
}
void delay_100us(void)
{
delay_50us();
delay_50us();
}
void time(unsigned int ucMs)
{
unsigned char j;
while (ucMs>0){
for(j=0;j<10;j++) delay_100us();
ucMs--;
}
}
proteus仿真图
?
|