当前位置:编程学习 > 汇编语言 >>

麻烦各位帮我这段程序翻译成汇编语言啊,实在麻烦了!着急要用的自己试了好久都不行...

#include<reg52.h> #define uchar unsigned char #define uint unsigned int sbit k1=P1^0; sbit k2=P1^1; sbit k3=P1^2; sbit k4=P1^3; sbit buz=P3^0; uchar code duan[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x00}; uchar count,shi,ge,dcount,dicount; void delay(int ms) { uchar i,j; for(i=ms;i>0;i--) for(j=200;j>0;j--); } void init() { P0=0x6f; P2=0x6f; P1=0xff; buz=0; TMOD=0x01; IE=0x82; TH0=(65536-50000)/256; TL0=(65536-50000)%256; TR0=1; dcount=99; } void keyscan() { if(k1==0) { delay(5); if(k1==0) { TR0=0; } } if(TR0==0) { if(k2==0) { delay(5); if(k2==0) { dcount++; if(dcount==100) dcount=0; while(!k2) { shi=dcount/10; ge=dcount%10; P0=duan[shi]; P2=duan[ge]; } } } if(k3==0) { delay(5); if(k3==0) { dcount--; if(dcount==-1) dcount=99; while(!k3) { shi=dcount/10; ge=dcount%10; P0=duan[shi]; P2=duan[ge]; } } } } if(k4==0) { delay(5); if(k4==0) { TR0=1; } } } void timer0() interrupt 1 { TH0=(65536-50000)/256; TL0=(65536-50000)%256; if(++count==20) { count=0; dcount--; if(dcount==-1) { TR0=0; while(k1!=0) { P0=0x00; P2=0x00; buz=1; delay(1000); P0=0xff; P2=0xff; buz=0; delay(1000); } dcount=99; } shi=dcount/10; ge=dcount%10; P0=duan[shi]; P2=duan[ge]; } } void main() { init(); while(1) { keyscan(); } } 图为原理图,实现99秒倒计时,并有四个按键控制
追问:这是您自己翻译出来的么?要求用汇编啊那个生成的有点乱,看不懂...一个按键是设定,就是运行以后暂停计数,还有一个按键是加一,另一个是减一,最后一个是确认,就是从设定好的数字继续开始倒计时这个我看过,但是和我那个不大一样啊...还是希望能帮我翻译一下我发的那个程序
答案:试试看

		org 0000H
		jmp Start
		org 000bh
		jmp TIMER0

Start:
		call	INIT
		mov		count,#20
		mov		dcount,#99h
		mov		a,dcount
		anl		a,#0fh
		mov		ge_buf,a
		mov		a,dcount
		swap	a
		anl		a,#0fh
		mov		shi_buf,a
loop:
		call	key_scan
		jmp 	loop

key_scan:
		jb		k1,chk_tr0
		call	delay
		jb		k1,chk_tr0
		clr		tr0 ;
chk_tr0:		
		jb		tr0,chk_k4
chk_k2:
		jb		k2,chk_k3
		call	delay;
		jb		k2,chk_k3
		mov		a,dcount
		cjne	a,#99h,not_to_99
		jmp		chk_k3
not_to_99:
		mov		a,ge_buf
		cjne	a,#09h,ge_not_9
		mov		a,shi_buf
		cjne	a,#09h,shi_not_9
		jmp		k2_end
shi_not_9:
		inc		shi_buf
		mov		ge_buf,#00h
		call	ge_shi_dcnt
		jmp		k2_end
ge_not_9:
		inc		ge_buf
		call	ge_shi_dcnt
k2_end:
		call	display
		jnb		k2,k2_end

chk_k3:
		jb		k3,chk_k4
		call	delay;
		jb		k3,chk_k4
		call	dcnt_shi_ge
		mov		a,ge_buf
		cjne	a,#00h,dec_ge
		mov		a,shi_buf
		cjne	a,#00h,dec_shi
		mov		dcount,#0h
		jmp		chk_k4
dec_ge:
		dec		ge_buf
		call	ge_shi_dcnt
		jmp		k3_end
dec_shi:
		dec		shi_buf
		mov		ge_buf,#09h
		call	ge_shi_dcnt
k3_end:
		call	display
		jnb		k3,k3_end
chk_k4:
		jb		k4,key_ret
		call	delay;
		jb		k4,key_ret
		setb	tr0
key_ret:
		ret

delay:
		mov 	r2,#20
D1:
		mov 	r3,#100
D2:			 	
		djnz 	r3,D2
		djnz 	r2,D1
		ret
delay_1:
		mov 	r2,#250
D1_1:
		mov 	r3,#250
D2_1:			 	
		djnz 	r3,D2_1
		djnz 	r2,D1_1
		ret
INIT:
		mov 	p0,#6FH ;
		mov		p2,#6Fh ;
		mov 	p1,#0FFh ;
		clr 	buz;
		mov 	tmod,#01;
		mov 	ie,#82h;
		mov 	th0,#3Ch ;=(65536-50000)/256;
		mov 	tl0,#00h ;=(65536-50000)%256;
		setb	tr0 ;
		mov		dcount,#99h ;
		ret
TIMER0:
		push 	acc
      	push 	psw
	  	djnz 	count,D0
		mov		count,#20
		call	dcnt_shi_ge
		mov		a,ge_buf
		cjne	a,#00h,ge_not_0
		mov		a,shi_buf
		cjne	a,#00h,shi_not_0
		jmp     dcount_end
ge_not_0:
		dec		ge_buf
		jmp		not_end
shi_not_0:
		dec		shi_buf
		mov		ge_buf,#09
		jmp		not_end
dcount_end:

		clr		tr0;
		jnb 	k1,k1_press;while(k1!=0)
		mov		P0,#00 ;
		mov		P2,#00 ;
		setb	buz;
		call    delay_1;
		call    delay_1;
		call    delay_1;
		call    delay_1;
		mov		P0,#0ffh;
		mov		P2,#0ffh;
		clr		buz;
		call	delay_1;
K1_press:
		mov		dcount,#99h;
		call	dcnt_shi_ge
not_end:
		call	display
		call	ge_shi_dcnt
D0:   	
		mov 	th0,#3Ch
      	mov 	tl0,#0B0h
	  	pop 	psw
	  	pop 	acc
	  	reti
display:
	   	call	ge_shi_dcnt
		mov		dptr,#duan
		mov		a,shi_buf
		movc	a,@a+dptr
		mov		p0,a
		mov		a,ge_buf
		movc	a,@a+dptr
		mov		p2,a
		ret
dcnt_shi_ge:
		mov		a,dcount
		anl		a,#0fh
		mov		ge_buf,a
		mov		a,dcount
		swap	a
		anl		a,#0fh
		mov		shi_buf,a
		ret	
ge_shi_dcnt:
		mov		a,shi_buf
		swap	a
		orl		a,ge_buf
		mov		dcount,a
		ret		

k1		EQU P1.0;
k2		EQU P1.1;
k3		EQU P1.2;
k4		EQU P1.3;
buz		EQU P3.0;
count 	EQU 20h
shi_buf	EQU 21h
ge_buf	EQU 22h
dcount	EQU 23h
dicount	EQU 24h

duan: DB 3Fh,06h,5Bh,4Fh,66h,6Dh,7Dh,07h,7Fh,6Fh,00h


 END
其他:有C了还翻译成汇编做什么?不麻烦吗? Keil里面编译一下,生成的文件里就有一个是汇编语言的 四个按键,控制什么? 怎么复杂  边看VS的反汇编 边写 

上一个:要用汇编语言编写一个24时数字钟,用到51单片机和8279芯片的读入,读出功能,8位LED显示数码管,要求:...
下一个:给个程序 ~~!是单片机汇编语言程序 单片机2010B学习板

CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,