现在的位置: 首页 > 综合 > 正文

并行时钟

2013年02月21日 ⁄ 综合 ⁄ 共 1069字 ⁄ 字号 评论关闭

并行时钟

下面的程序把用户程序加到1CH中断之前,来实现一个并行时钟。其中4f为字符属性,显示红底白字的时间。加'0'是为了实现类型转换。内存地址为长整数,在彩色时为0xb80000001,单色(模式7)时为0xb00000001在CRT上第一行第72个字符开始显示一个时钟,形式为:12:12:12。由于1CH中断每秒产生18.2次,为此要设置count加以修正。

#include"time.h"
#include "dos.h"
char far *buf;
void (interrupt far *oldintfun)();
struct time t;
union REGS i,o;
void interrupt far newintfun()
{
static int time1=0,count=0;
time1++;
if(time1>=18)
{
count++;
t.ti_sec++;
if(t.ti_sec>=60)
{
t.ti_sec=0;
t.ti_min++;
if(t.ti_min>=60)
{
t.ti_min=0;
t.ti_hour=t.ti_hour>=23 ? 0: t.ti_hour+1;
}
}
*(buf+144)=t.ti_hour/10+'0';
*(buf+145)=0x4f;
*(buf+146)=t.ti_hour%10+'0';
*(buf+147)=0x4f;
*(buf+148)=':';
*(buf+149)=0x4f;
*(buf+150)=t.ti_min/10+'0';
*(buf+151)=0x4f;
*(buf+152)=t.ti_min%10+'0';
*(buf+153)=0x4f;
*(buf+154)=':';
*(buf+155)=0x4f;
*(buf+156)=t.ti_sec/10+'0';
*(buf+157)=0x4f;
*(buf+158)=t.ti_sec%10+'0';
*(buf+159)=0x4f;

if (count==5)
{count=0;time1=-1;}
else time1=0;
}
oldintfun();
}

main()
{
void interrupt far newintfun();
i.h.ah=0x0f;
int86(0x10,&i,&o);
if(o.h.al!=7)
buf=(char far *)0xb8000000l;
else
buf=(char far *)0xb0000000l;
gettime(&t);
oldintfun=getvect(0x1c);
setvect(0x1c,newintfun);
keep(0,3000);
}

抱歉!评论已关闭.