老师的作业是要求用汇编语言写 可是没有学过汇编 就用C写了 只是很短的一点 哪位大哥大姐可以帮忙翻译成汇编语言 先谢谢各位了(用的是AT89C52)
第一个:
//利用2个独立按键分别控制2组8位LED灯闪烁
#include<reg51.h>
#define LEDs1 P1
#define LEDs2 P2
sbit btn1 = P3^0;
sbit btn2 = P3^1;
delay(char t){
char i,j;
for(i=0;i<t;i++){
for(j=0;j<100;j++);
}
}
void main(void){
char i=0;
P3=0xff;
while(1){
if(btn1==0){
delay(2);
LEDs1=0xfe;
for(i=0;i<8;i++){
LEDs1>>1;
delay(10);
}
}
if(btn2==0){
delay(2);
LEDs2=0xfe;
for(i=0;i<8;i++){
LEDs2>1;
delay(10);
}
}
}
第二个:
//利用4个按键控制4个数码管显示不同的数码
#include"reg51.h"
#define BUTTON P1
#define SEG7 P2
#define ScanSEG P3
char tab[5]={0xc0,0xf9,0xa4,0xb0,0x99};//段码
char sel[4]={0x01,0x02,0x04,0x08};//位选码
void scanLED(char storige){
char k;
for(k=0;k<4;k++){
ScanSEG=sel[k];
SEG7=tab[storige];
}
}
void main(){
char storige=0;
BUTTON = 0xff;
while(1){
if(BUTTON==~0x01)
storige=1;
if(BUTTON==~0x02)
storige=2;
if(BUTTON==~0x04)
storige=3;
if(BUTTON==~0x08)
storige=4;
scanLED(storige);
}
}
}
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
18: char i = 0;
C:0x0800 E4 CLR A
C:0x0801 FC MOV R4,A
19: P3 = 0xff;
C:0x0802 75B0FF MOV P3(0xB0),#0xFF
20: while(1){
21: if(btn1==0){
C:0x0805 20B013 JB btn1(0xB0.0),C:081B
22: delay(2);
C:0x0808 7F02 MOV R7,#0x02
C:0x080A 120838 LCALL delay(C:0838)
23: LEDs1 = 0xfe;
C:0x080D 7590FE MOV P1(0x90),#0xFE
24: for(i=0;i<8;i++){
C:0x0810 E4 CLR A
C:0x0811 FC MOV R4,A
25: LEDs1 >> 1;
26: delay(10);
C:0x0812 7F0A MOV R7,#0x0A
C:0x0814 120838 LCALL delay(C:0838)
27: }
C:0x0817 0C INC R4
C:0x0818 BC08F7 CJNE R4,#0x08,C:0812
28: }
29:
30: if(btn2==0){
C:0x081B 20B1E7 JB btn2(0xB0.1),C:0805
31: delay(2);
C:0x081E 7F02 MOV R7,#0x02
C:0x0820 120838 LCALL delay(C:0838)
32: LEDs2 = 0xfe;
C:0x0823 75A0FE MOV PPAGE_SFR(0xA0),#0xFE
33: for(i=0;i<8;i++){
C:0x0826 E4 CLR A
C:0x0827 FC MOV R4,A
C:0x0828 C3 CLR C
C:0x0829 EC MOV A,R4
C:0x082A 6480 XRL A,#P0(0x80)
C:0x082C 9488 SUBB A,#TCON(0x88)
C:0x082E 50D5 JNC C:0805
34: LEDs2 >> 1;
35: delay(10);
C:0x0830 7F0A MOV R7,#0x0A
C:0x0832 120838 LCALL delay(C:0838)
36: }
C:0x0835 0C INC R4
C:0x0836 80F0 SJMP C:0828
9: delay(char t)
10: {
11: char i,j;
12: for(i=0;i<t;i++){
C:0x0838 E4 CLR A
C:0x0839 FE MOV R6,A
C:0x083A C3 CLR C
C:0x083B EF MOV A,R7
C:0x083C 6480 XRL A,#P0(0x80)
C:0x083E F8 MOV R0,A
C:0x083F EE MOV A,R6
C:0x0840 6480 XRL A,#P0(0x80)
C:0x0842 98 SUBB A,R0
C:0x0843 5009 JNC C:084E
13: for(j=0;j<100;j++);
C:0x0845 E4 CLR A
C:0x0846 FD MOV R5,A
C:0x0847 0D INC R5
C:0x0848 BD64FC CJNE R5,#0x64,C:0847
14: }
C:0x084B 0E INC R6
C:0x084C 80EC SJMP C:083A
15: }
C:0x084E 22 RET
133: MOV R0,#IDATALEN - 1
C:0x084F 787F MOV R0,#0x7F
134: CLR A
C:0x0851 E4 CLR A
135: IDATALOOP: MOV @R0,A
C:0x0852 F6 MOV @R0,A
136: DJNZ R0,IDATALOOP
C:0x0853 D8FD DJNZ R0,IDATALOOP(C:0852)
185: MOV SP,#?STACK-1
186:
187: ; This code is required if you use L51_BANK.A51 with Banking Mode 4
188: ;<h> Code Banking
189: ; <q> Select Bank 0 for L51_BANK.A51 Mode 4
190: #if 0
191: ; <i> Initialize bank mechanism to code bank 0 when using L51_BANK.A51 with Banking Mode 4.
192: EXTRN CODE (?B_SWITCH0)
193: CALL ?B_SWITCH0 ; init bank mechanism to code bank 0
194: #endif
195: ;</h>
C:0x0855 758107 MOV SP(0x81),#0x07
196: LJMP ?C_START
C:0x0858 020800 LJMP main(C:0800)
C:0x085B 00 NOP
C:0x085C 00 NOP
C:0x085D 00 NOP
C:0x085E 00 NOP
一周热门 更多>