data segment
;定义please等提示信息
str db 20
db 50h,7,0,0
db 6ch,7,0,1
db 65h,7,0,1
db 61h,7,0,1
db 73h,7,0,1
db 65h, 7,0,1
db 70h,7,1,-10
db 72h,7,0,1
db 65h,7,0,1
db 73h,7,0,1
db 73h,7,0,1
db 53h,7,0,2
db 6bh,7,0,2
db 65h,7,0,1
db 79h,7,0,1
db 65h,7,0,2
db 78h,7,0,1
db 69h,7,0,1
db 74h,7,0,1
db 21h,7,0,1
;定义0-9十个图形数字
s0 db 6
db 5fh,7,0,0
db 7ch,7,1,-1
db 7ch,7,1,0
db 5fh,7,0,1
db 7ch,7,0,1
db 7ch,7,-1,0
sy db 2
db 7ch,7,1,0
db 7ch,7,1,0
s2 db 5
db 5fh,7,0,0
db 7ch,7,1,1
db 5fh,7,0,-1
db 7ch,7,1,-1
db 5fh,7,0,1
s3 db 5
db 5fh,7,0,0
db 7ch,7,1,1
db 5fh,7,0,-1
db 7ch,7,1,1
db 5fh,7,0,-1
s4 db 4
db 7ch,7,1,0
db 5fh,7,0,1
db 7ch,7,1,1
db 7ch,7,-1,0
s5 db 5
db 5fh,7,0,0
db 7ch,7,1,-1
db 5fh,7,0,1
db 7ch,7,1,1
db 5fh,7,0,-1
s6 db 6
db 5fh,7,0,0
db 7ch,7,1,-1
db 5fh,7,0,1
db 7ch,7,1,1
db 5fh,7,0,-1
db 7ch,7,0,-1
s7 db 3
db 5fh,7,0,0
db 7ch,7,1,1
db 7ch,7,1,0
s8 db 7
db 7ch,7,1,0
db 5fh,7,-1,1
db 7ch,7,1,1
db 5fh,7,0,-1
db 7ch,7,1,1
db 5fh,7,0,-1
db 7ch,7,0,-1
s9 db 6
db 7ch,7,1,0
db 5fh,7,-1,1
db 7ch,7,1,1
db 5fh,7,0,-1
db 7ch,7,1,1
db 5fh,7,0,-1
s11 db 2
db 03h,7,1,0
db 03h,7,1,0
data ends
stack segment
db 200 dup (0)
stack ends
code segment
assume cs:code,ss:stack,ds:data
start:
mov ax,data
mov ds,ax
mov ah,0 ;设置显示方式
mov al,4
int 10h
mov ah,0bh ;置彩色调板
mov bh,0
mov bl,1
int 10h
mov ah,0bh ;置彩色调板
mov bh,1
mov bl,4
int 10h
mov ah,2 ;取系统时间
int 1ah
mov ax,0
mov bx,0
mov ah,ch ;取系统时间
mov al,cl ;保存分钟
mov bh,dh ;保存秒
mov bl,dl ;保存百分之一秒
tt:
push ax
push bx
mov ah,0
mov al,4
int 10h
mov ah,0bh
mov bh,0
mov bl,1
int 10h
mov ah,0bh
mov bh,1
mov bl,4
int 10h
MOV AH,1 ;读键盘缓冲区字符
INT 16h
JZ ww
MOV AH,8 ;从键盘输入字符
INT 21h
CMP AL,'s' ;输入s,结束程序
JE tu
ww: pop bx
pop ax
call xian ;调用显示子程序
push ax
qu: mov ah,2 ;取系统时间
int 1ah
cmp bh,dh
je qu
pop ax
inc bh ;对时间进行加1
cmp bh,100
jl tt
mov bh,0
inc al
call beep
cmp al,100
jl tt
mov al,0
inc ah
cmp ah,24
jl tt
mov ah,0
jmp tt
tu: mov ah,4ch
int 21h
ret
xian proc ;对时间值进行处理并显示的子程序
push si
push di
push dx
push cx
push bx
push ax
pop ax
push ax
mov bx,ax
mov ax,0
mov al,bh
mov cl,4
shr al,cl
mov bl,al
mov dh,10
mov dl,2
call ff
pop ax
push ax
mov bx,ax
mov ax,0
mov al, bh
and al,0fh
mov bl,al
mov dh,10
mov dl,6
call ff
mov dh,10
mov dl,10
mov bl,10
call ff
pop ax
push ax
mov cl,4
shr al,cl
mov bl,al
mov dh,10
mov dl,14
call ff
pop ax
push ax
and al ,0fh
mov bl,al
mov dh,10
mov dl,18
call ff
mov dh,10
mov dl,22
mov bl,10
call ff
pop ax
pop bx
push bx
push ax
mov ax,0
mov al,bh
mov cl,4
shr al,cl
mov bl,al
mov dh,10
mov dl,26
call ff
pop ax
pop bx
push bx
push ax
mov al,bh
and al,0fh
mov bl,al
mov dh,10
mov dl,30
call ff
mov dh,0
mov dl,15
mov bl,22
call ff
pop ax
pop bx
pop cx
pop dx
pop di
pop si
ret
xian endp
ff proc ;显示具体数值
push ax
push bx
push cx
push dx
cmp bl,0
je l0
cmp bl,1
je l1
cmp bl,2
je l2
cmp bl,3
je l3
cmp bl,4
je l4
cmp bl,5
je l5
cmp bl,6
je l6
cmp bl,7
je l7
cmp bl,8
je l8
cmp bl,9
je l9
cmp bl,10
je l10
cmp bl,22
je ld
l0: lea di,s0
jmp ty
l1 : lea di,sy
jmp ty
l2: lea di,s2
jmp ty
l3: lea di,s3
jmp ty
l4: lea di,s4
jmp ty
l5: lea di,s5
jmp ty
l6: lea di,s6
jmp ty
l7: lea di,s7
jmp ty
l8: lea di,s8
jmp ty
l9: lea di,s9
jmp ty
l10: lea di,s11
jmp ty
ld : lea di,str
ty: mov ah,0fh ;示方式
int 10h
sub cx,cx
mov cl,[di]
inc di
plot_next: add dh,[di+2]
add dl,[di+3]
mov ah,2
int 10h
mov al,[di]
mov bl,[di+1]
push cx
mov cx,1
mov ah,09
int 10h
pop cx
add di,4
loop plot_next
pop dx
pop cx
pop bx
pop ax
mov cx,100
gg: dec cx
loop gg
ret
ff endp
clear proc
push ax
push bx
push cx
push dx
mov ah,6
mov al,0
mov bh,1
int 10h
pop dx
pop cx
pop bx
pop ax
ret
clear endp
beep proc
push ax
push bx
push cx
push dx
mov al ,10110110b
out 43h,al
mov ax,533h
out 42h,al
mov al,ah
out 42h,al
in al,61h
mov ah,al
or al,03
out 61h,al
sub cx,cx
mov bl,28h
g7: loop g7
dec bl
jnz g7
mov al,ah
out 61h,al
pop dx
pop cx
pop bx
pop ax
ret
beep endp
code ends
end start
masm50编译,windows98或dos可以正常显示
;tsr例程
;功能:每按下ctrl键显示
;surported by campuslichen@yeahnet
;07/11/29
lmcmosr macro colorc,rowc,colc ;宏:获取cmos时间并显示
local lcmosrb,frc,btoa,toasc,nxt
jmp lcmosrb
pshow db ' \ \ : : ',0 ;ascii码存放区
acmos db 9,8,7,4,2,0 ;cmos端口,70h号:入口参数,9:年,8:月,7:日,4:时,2:分,0:秒,71h:出口参数,BCD码
pcmos db 7 dup(0) ;
frc:
;;无入口参数________________________
push si
push cx
mov cx,6
mov si,0
frs:
mov al,acmos[si]
out 70h,al ;将al中的参数写入al,格式为 :out 70h,al
in al,71h ;从 71h端口读取出口参数到al
mov pcmos[si],al
inc si
loop frs
pop cx
pop si
ret
btoa: ;bcd码转为ascii码
;;入口:si,di_______________________
mov cx,6
bs:
mov al,ds:[si]
call toasc
mov ds:[di],ah
mov ds:[di+1],al
inc si
inc di
inc di
inc di
loop bs
ret
toasc:
;;_________________________________;btoa的子程序,将al中的bcd码转为两个ascii码,存放在ah,al
;;al
;;ah,al
mov ah,al
shr ah,1
shr ah,1
shr ah,1
shr ah,1
and al,00001111b
add al,30h
add ah,30h
ret
lcmosrb: ;================================= 读取cmos主程序
push cs
pop ds
ifb <colorc> ;=================处理宏参数
mov bl,0eh
else
mov bl,colorc
endif
ifb <rowc>
mov dh,0
else
mov dh,rowc
endif
if <colc>
mov dl,0
else
mov dl,colc
endif
call frc
mov si,offset pcmos
mov di,offset pshow
call btoa
mov ax,ds
mov es,ax
mov bp,offset pshow
mov cx,18
mov bh,0
mov al,0
mov ah,13h
int 10h
endm
assume cs:code,ds:code
row = 0
column =0
pagen =0
color1 = 0ah
wakek = 1dh ;激活键ctrl扫描码
code segment
dm db ' Hello , this is a TSR program '
dm1 db ' current time:',0dh,0ah
dint9 dd 0
stayr:
in al,60h ;从键盘缓冲区读取一个扫描码
cmp al,wakek ;判断 是ctrl则激活tsr
je nxt1
lover: ;退出,调用原int9中断
jmp dword ptr cs:dint9
nxt1:
push ax
push bx
push dx
push es
push bp
mov ax,cs
mov es,ax
mov bp,offset dm
mov cx,offset dint9 -offset dm
mov bh,pagen
mov bl,color1
mov dh,row
mov dl,column
mov al,0
mov ah,13h
int 10h
lmcmosr 1eh,2,62
pop bp
pop es
pop dx
pop bx
pop ax
jmp lover
;<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
start:
mov ax,code
mov ds,ax
mov al,9h
mov ah,35h
int 21h
mov word ptr dint9[0],bx
mov word ptr dint9[2],es
mov dx,offset stayr
mov al,9h
mov ah,25h
int 21h
mov dx,offset start ;计算驻留长度,以节(16字节)为单位,传给入口参数dx
add dx,15
mov cl,4
shr dx,cl
add dx,10h
mov ah,31h ;调用31h号dos功能,驻留并退出
int 21h
code ends
end start
;int9
;al,60h
//定义共阴极数码管,对应显示0-F
uchar code seven_seg[] = {0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,
0x6f,0x77,0x7C,0x39,0x5e,0x79,0x71};
uchar keyState = 0 ; // 0表示没有 *** 作 1 修改秒 2 修改分钟 3 修改小时 4 定闹 小时 5定闹分钟
uint ledState =0;
uchar ledStateNum=0;
uint num = 0 ;
sbit KEY1=P3^0; //定义IO口
sbit KEY2=P3^1;
sbit KEY3=P3^2;
sbit KEY4=P3^3;
char timer[] ={ 0 , 0 , 0} ; //时,分,秒
char n_timer[2]={11,0};
//延时程序 ,当调用此函数时,需要传递参数ms,用于设置延时时间
//若为12M晶振,每条指令对应1us的时间 ,要对应1ms的时间,就要选择
//0012M的晶振,也就是12K的晶振(有吗?)
// 若要用12M的晶振,实现1ms的延时,程序需要做修改。如下面注释的语句
void DelayMS(uint ms)
{
ms = 1000; //加上此语句,实现延时1ms
while(ms--);
}
void Display()
{
uchar i = 0,flags;
uchar count = 0;
uchar temp [6] ={ 0xfe,0xfd,0xfb,0xf7,0xef,0xdf};
if( 4 == keyState || 5 == keyState )
//从程序看,应该有外部中断处理函数用于设置keystate参数
//这个if写得比较另类,正常应把参数放在前面,
//判断按键是否按下,两个有一个按下即执行
{
P2 = temp[0]; //向P2口写数据
P0 = 0x00; //有了下面一条指令,这条语句没有用
P0 = 0x40; //向P0口写数据
DelayMS(1); //延时1ms
P2 = temp[1];
P0 = 0x00;
P0 = 0x40;
DelayMS(1);
P2 = temp[2];
P0 = 0x00;
if(ledState && 4 == keyState)
P0 = seven_seg[ n_timer[0] / 10 ];
else
P0 = seven_seg[ n_timer[0] / 10 ] | 0x80;
DelayMS(1);
P2 = temp[3];
P0 = 0x00;
if(ledState && 4 == keyState)
P0 = seven_seg[ n_timer[0] % 10 ];
else
P0 = seven_seg[ n_timer[0] % 10 ] | 0x80;
DelayMS(1);
P2 = temp[4];
P0 = 0x00;
if(ledState && 5 == keyState)
P0 = seven_seg[ n_timer[1] / 10 ];
else
P0 = seven_seg[ n_timer[1] / 10 ] | 0x80;
DelayMS(1);
P2 = temp[5];
P0 = 0x00;
if(ledState && 5 == keyState)
P0 = seven_seg[ n_timer[1] % 10 ];
else
P0 = seven_seg[ n_timer[1] % 10 ] | 0x80;
DelayMS(1);
P2 = 0XFF;
return ;
}
//没有主程序和外部中断处理函数,这段程序读起来不太好读懂
//应该是根据ledstate的状态,也就是4或5来进行时间的校对。
if( 0 == keyState)
{
P2 = temp[0];
P0 = 0x00;
P0 = seven_seg[ timer[0] / 10 ];
DelayMS(1);
P2 = temp[1];
P0 = 0x00;
P0=seven_seg[ timer[0] % 10 ];
DelayMS(1);
P2 = temp[2];
P0 = 0x00;
P0 = seven_seg[ timer[1] / 10 ];
DelayMS(1);
P2 = temp[3];
P0 = 0x00;
P0 = seven_seg[ timer[1] % 10 ];
DelayMS(1);
P2 = temp[4];
P0 = 0x00;
P0 = seven_seg[ timer[2] / 10 ];
DelayMS(1);
P2 = temp[5];
P0 = 0x00;
P0 = seven_seg[ timer[2] % 10 ];
DelayMS(1);
P2 = 0XFF;
return ;
}
//若不需要设置时间,显示时间
while( i < 6 )
{
if(3- keyState == i/2 && ledState == 0)
{
flags = 0;
}
else
{
flags = 1;
}
if( flags)
{
P2 = temp[i];
P0=0x00;
if(0 == i % 2)
{
P0 = seven_seg[ timer[i/2] / 10 ];
}
else
{
P0 = seven_seg[ timer[i/2] % 10 ];
}
}
i++;
}
//这个程序不全,没有看懂
}
这个程序不复杂的。如果懂单片机和C语言很容易读懂的。
有不懂的地方,用Keil或Proteus仿真一下。就读懂了
自己动手 *** 作一下,总比在这里等强。
再说你给的悬赏分也不高啊
是电子钟程序。
是电子钟程序,M8013是PLC内部的秒时钟脉冲,C1,Cl、C2分别是秒、分、时计数器。M8013每来一个秒时钟脉冲。
使用定时器实现时钟,小时、分、秒的控制。PLC资源分配D0:秒时计时。
void CDigitalClock::DrawSingleNumber(int nNum,int nLeft)
{
switch (nNum)
{
case 0:
DrawSection1(nLeft);
DrawSection2(nLeft);
DrawSection3(nLeft);
DrawSection4(nLeft);
DrawSection5(nLeft);
DrawSection6(nLeft);
break;
case 1:
DrawSection2(nLeft);
DrawSection3(nLeft);
break;
case 2:
DrawSection1(nLeft);
DrawSection2(nLeft);
DrawSection4(nLeft);
DrawSection5(nLeft);
DrawSection7(nLeft);
break;
case 3:
DrawSection1(nLeft);
DrawSection2(nLeft);
DrawSection3(nLeft);
DrawSection4(nLeft);
DrawSection7(nLeft);
break;
case 4:
DrawSection2(nLeft);
DrawSection3(nLeft);
DrawSection6(nLeft);
DrawSection7(nLeft);
break;
case 5:
DrawSection1(nLeft);
DrawSection3(nLeft);
DrawSection4(nLeft);
DrawSection6(nLeft);
DrawSection7(nLeft);
break;
case 6:
DrawSection1(nLeft);
DrawSection3(nLeft);
DrawSection4(nLeft);
DrawSection5(nLeft);
DrawSection6(nLeft);
DrawSection7(nLeft);
break;
case 7:
DrawSection1(nLeft);
DrawSection2(nLeft);
DrawSection3(nLeft);
break;
case 8:
DrawSection1(nLeft);
DrawSection2(nLeft);
DrawSection3(nLeft);
DrawSection4(nLeft);
DrawSection5(nLeft);
DrawSection6(nLeft);
DrawSection7(nLeft);
break;
case 9:
DrawSection1(nLeft);
DrawSection3(nLeft);
DrawSection4(nLeft);
DrawSection2(nLeft);
DrawSection6(nLeft);
DrawSection7(nLeft);
break;
default:
;
}
}
void CDigitalClock::DrawSection1(int nLeft)
{
if (m_memDCm_hDC!=NULL)
{
CPoint point[4];
point[0]x=nLeft+(int)(01m_nWidth);
point[0]y=m_nYmargin;
point[1]x=nLeft+(int)(09m_nWidth);
point[1]y=m_nYmargin;
point[2]x=nLeft+(int)(07m_nWidth);
point[2]y=(int)(02m_nWidth)+m_nYmargin;
point[3]x=nLeft+(int)(03m_nWidth);
point[3]y=(int)(02m_nWidth)+m_nYmargin;
CBrush br(m_crText);
CRgn rgn;
rgnCreatePolygonRgn(point,4,ALTERNATE);
m_memDCFillRgn(&rgn,&br);
brDeleteObject();
rgnDeleteObject();
m_memDCMoveTo(point[0]);
m_memDCLineTo(point[1]);
m_memDCMoveTo(point[1]);
m_memDCLineTo(point[2]);
m_memDCMoveTo(point[2]);
m_memDCLineTo(point[3]);
m_memDCMoveTo(point[3]);
m_memDCLineTo(point[0]);
}
}
void CDigitalClock::Draw2Dot(int nLeft)
{
if (m_memDCm_hDC!=NULL)
{
CBrush br(m_crText);
CRect rect;
rectSetRect(nLeft+(int)(03m_nWidth),(int)(04m_nWidth)+m_nYmargin,
nLeft+(int)(06m_nWidth),(int)(07m_nWidth)+m_nYmargin);
m_memDCEllipse(rect);
CRgn rgn1;
rgn1CreateEllipticRgn(rectleft,recttop,rectright,rectbottom);
m_memDCFillRgn(&rgn1,&br);
rectOffsetRect(0,(int)(08m_nWidth)+m_nYmargin);
m_memDCEllipse(rect);
CRgn rgn2;
rgn2CreateEllipticRgn(rectleft,recttop,rectright,rectbottom);
m_memDCFillRgn(&rgn2,&br);
brDeleteObject();
rgn1DeleteObject();
rgn2DeleteObject();
}
}
主要代码在这~~慢看~~`
/开发环境:turbo c 20模拟时钟转动程序代码/
#include"graphicsh"
#include"mathh"
#include"dosh"
#define pi 31415926
#define X(a,b,c) x=acos(bcpi/180-pi/2)+300
#define Y(a,b,c) y=asin(bcpi/180-pi/2)+240
#define d(a,b,c) X(a,b,c);Y(a,b,c);line(300,240,x,y)
void init() /划时钟边框函数/
{
int i,l,x1,x2,y1,y2;
setbkcolor(1);
circle(300,240,200);
circle(300,240,205);
circle(300,240,5);
for(i=0;i<60;i++) /划钟点上的短线/
{
if(i%5==0)
l=15;
else
l=5;
x1=200sin(i6pi/180)+300;
y1=200cos(i6pi/180)+240;
x2=(200-l)sin(i6pi/180)+300;
y2=(200-l)cos(i6pi/180)+240;
line(x1,y1,x2,y2);
}
}
main()
{
int x,y,i,k=1;
int gdriver=9,gmode=2;
unsigned char h,m,s;
int o,p,q;
float n;
struct time t[1];
struct date d[1];
initgraph(&gdriver,&gmode,"c:\\tc");
initgraph(&gdriver,&gmode,"c:\\tc");
for(i=0;i<=6;i++)
{
settextstyle(TRIPLEX_FONT,HORIZ_DIR,i); /控制输出字符的字体,方向,大小/
cleardevice();
settextjustify(1,1); /在指定坐标上输出字符串/
outtextxy(300,80,"12") ;
outtextxy(300,390,"6");
outtextxy(140,230,"9");
outtextxy(460,230,"3");
outtextxy(380,100,"1");
outtextxy(220,100,"11");
outtextxy(430,160,"2");
outtextxy(430,310,"4");
outtextxy(380,370,"5");
outtextxy(220,370,"7");
outtextxy(160,160,"10");
outtextxy(160,310,"8");
}
init();
setwritemode(1); /设置画线的输出模式/
if(k!=0)
{
getdate(d); /获得系统日期函数/
o=d[0]da_year;
p=d[0]da_mon;
q=d[0]da_day;
gettime(t); /获得系统时间函数/
h=t[0]ti_hour;
m=t[0]ti_min;
s=t[0]ti_sec;
}
setcolor(7); /设置时针颜色/
n=(float)h+(float)m/60;
d(150,n,30); /画出时针/
setcolor(14); /设置分针颜色/
d(170,m,6); /画出分针/
setcolor(4); /设置秒针颜色/
d(190,s,6); /画出秒针/
while(!kbhit()) /控制程序按下任意键退出/
{
while(t[0]ti_sec==s)
gettime(t);
gotoxy(44,18); /使光标移动到指定坐标/
printf("\b\b\b\b\b\b\b\b\b"); /退格,使表示时间的字符串不断变化/
sound(400); /按给定的频率打开PC扬声器/
delay(70); /中断程序的执行,时间为70毫秒/
sound(200);
delay(30);
nosound(); /按给定的频率关闭PC扬声器/
setcolor(4);
d(190,s,6);
s=t[0]ti_sec;
d(190,s,6);
if(t[0]ti_min!=m)
{
setcolor(14);
d(170,m,6);
m=t[0]ti_min;
d(170,m,6);
}
if(t[0]ti_hour!=h)
{
setcolor(7);
d(150,h,30);
h=t[0]ti_hour;
d(150,h,30);
sound(1000);
delay(240);
nosound();
delay(140);
sound(2000);
delay(240);
nosound();
}
if(s<10) /用字符的形式输出时间/
{ if(m<10)
printf("%u:0%u:0%u",h,m,s);
else
printf("%u:%u:0%u",h,m,s);
}
else
{ if(m<10)
printf("%u:0%u:%u",h,m,s);
else
printf("%u:%u:%u",h,m,s);
}
gotoxy(34,19); /在指定坐标上输出日期/
printf("%d年%d月%d日",o,p,q);
printf("\b\b\b\b\b\b\b\b\b");
}
getch();
closegraph();
}
以上就是关于用汇编语言编写一个数字电子钟程序代码全部的内容,包括:用汇编语言编写一个数字电子钟程序代码、用汇编语言编写一个时钟程序、一部分用C语言编写的C51单片机时钟程序,求加注释等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)