秒钟的显示程序
发布网友
发布时间:2022-05-01 14:18
我来回答
共2个回答
热心网友
时间:2023-05-08 21:55
MIA EQU 30H
MIAO EQU 31H
FEN EQU 32H
SHI EQU 33H
ORG 0000H
SJMP START
ORG 000BH
LJMP TTT
ORG 0010H
START:MOV SP,#60H
MOV MIAO,#0
MOV MIA,#20 ;定时20次即20*50ms=1s
MOV FEN,#0
MOV SHI,#12
MOV TMOD,#01H
MOV TL0,#0B0H
MOV TH0,#3CH
SETB ET0
SETB TR0
SETB EA ;启动50ms定时器
LOOP:LCALL MIAOS 秒到60分加1且秒复位,分、时同秒算法
LCALL MIAOX 我采用动态显示,p1时数码管选线,p0是数码管字形
LJMP LOOP
MIAOS:MOV A,MIAO
CJNE A,#60,MSUAN1
MSUAN1:JC MSUAN11
MOV MIAO,#0
INC FEN
MSUAN11:MOV A,FEN
CJNE A,#60,MSUAN2
MSUAN2:JC MSUAN22
MOV FEN,#0
INC SHI
MSUAN22:MOV A,SHI
CJNE A,#24,MSUAN3
MSUAN3:JC MSUAN33
MOV SHI,#0
MSUAN33:RET
MIAOX:MOV A,MIAO
MOV B,#10
DIV AB
LCALL CHAB
MOV P0,A
MOV P1,#11111110B
MOV P1,#0FFH
MOV A,B
LCALL CHAB
MOV P0,A
MOV P1,#11111101B
MOV P1,#0FFH
MOV A,FEN
MOV B,#10
DIV AB
LCALL CHAB
MOV P0,A
MOV P1,#11111011B
MOV P1,#0FFH
MOV A,B
LCALL CHAB
MOV P0,A
MOV P1,#11110111B
MOV P1,#0FFH
MOV A,SHI
MOV B,#10
DIV AB
LCALL CHAB
MOV P0,A
MOV P1,#11101111B
MOV P1,#0FFH
MOV A,B
LCALL CHAB
MOV P0,A
MOV P1,#11011111B
MOV P1,#0FFH
RET
TTT:MOV TL0,#0B0H
MOV TH0,#3CH
DJNZ MIA,NEXT
INC MIAO
MOV MIA,#20
NEXT:RETI
CHAB:MOV DPTR,#TAB
MOVC A,@A+DPTR
RET
TAB:DB 28H,7EH,0A2H,62H,74H,61H,21H,7AH,20H,60H;不同品牌数码管对应码不一样!
END
兄的,按键部分你就自己来吧!注意按键去抖动!
程序我已试过可行!看你给的分挺高的!
热心网友
时间:2023-05-08 21:56
#include <windows.h>
#include <time.h>
#include <stdlib.h>
#include <iostream>
#include <string>
using namespace std;
class SystemTime
{
private:
int year,month,day,hour,minute,second;
public:
const int T;
SystemTime(int t);
~SystemTime();
void GetSystemTime();
void move();
void show();
};
void main()
{
SystemTime t(1); //参数为更新时间的间隔,可以随意,1s、2s、3s...
t.GetSystemTime(); //程序开始运行时获得系统时间
while(1) //设置无限循环模拟系统时间!
{
t.show(); //显示时间
t.move(); //更新时间
Sleep(t.T * 1000); //暂停t.T s
system("cls");
}
}
SystemTime::SystemTime(int t):T(t){}
SystemTime::~SystemTime(){}
void SystemTime::GetSystemTime()
{
time_t ltime;
time(<ime);
char *str= ctime(<ime);
string stryear(str+20,str+24);
string strmonth(str+4,str+7);
if (strmonth == "Jan")strmonth="1";
if (strmonth == "Feb")strmonth="2";
if (strmonth == "Mar")strmonth="3";
if (strmonth == "Apr")strmonth="4";
if (strmonth == "May")strmonth="5";
if (strmonth == "Jun")strmonth="6";
if (strmonth == "Jul")strmonth="7";
if (strmonth == "Aug")strmonth="8";
if (strmonth == "Sep")strmonth="9";
if (strmonth == "Oct")strmonth="10";
if (strmonth == "Nov")strmonth="11";
if (strmonth == "Dec")strmonth="12";
string strday(str+8,str+10);
string strhour(str+11,str+13);
string strminute(str+14,str+16);
string strsecond(str+17,str+19);
year = atoi(stryear.c_str());
month = atoi(strmonth.c_str());
day = atoi(strday.c_str());
hour = atoi(strhour.c_str());
minute = atoi(strminute.c_str());
second = atoi(strsecond.c_str());
}
void SystemTime::move()
{
second += T ; //T s更新一次
if (second>59) { second =0; minute +=1; }
if (minute>59) { minute =0; hour +=1; }
if (hour>23) { hour =0; }
}
void SystemTime::show()
{
cout<<year<<"."<<month<<"."<<day<<" ";
if (hour<10)
{
cout<<0;
}
cout<<hour<<":"; //时
if (minute<10)
{
cout<<0;
}
cout<<minute<<":"; //分
if (second<10)
{
cout<<0;
}
cout<<second<<endl; //秒
}