I need to use 8086 assembly language to connect with Arduino in my assignment. When I run the assembly program, the buzzer will sound. I run the assembly program using DOSBox.
int buzzer = 11;
int val;
void setup() {
pinMode(buzzer, OUTPUT);
Serial.begin(9600);
}
void loop() {
val = Serial.read();
if(-1 != val) {
if('H' == val) {
unsigned char i;
for(i = 0; i < 80; i++) {
digitalWrite(buzzer, HIGH);
delay(1);
digitalWrite(buzzer, LOW);
delay(1);
}
for(i = 0; i < 100; i++) {
digitalWrite(buzzer, HIGH);
delay(2);
digitalWrite(buzzer, LOW);
delay(2);
}
}
}
}
Above is my Arduino code. When COM1 receives 'H', the buzzer will sound.
.MODEL SMALL
.STACK 64
.DATA
.CODE
MAIN PROC
MOV AX,@DATA
MOV DS,AX
MOV AH,00
MOV AL,11101011b
MOV DX,00
MOV AH,1
MOV AL,'H'
MOV DX,00
INT 14H
MOV AX,4C00H
INT 21H
MAIN ENDP
END MAIN
Above is my assembly code. When I run the assembly code, it is supposed to send 'H' to COM1, and the buzzer will sound. However, nothing happens when I run the assembly program. What is the problem?
答案 0 :(得分:2)
MOV AH,00 MOV AL,11101011b MOV DX,00
此代码正在尝试设置COM1串口:
但是这里缺少一条关键指令!您仍然需要请求BIOS实际执行它:
int 14h
MAIN PROC
xor dx, dx ; Select COM1
mov ah, 00h ; InitializeCommunicationsPort
mov al, 11101011b ; 9600, odd, 1, 8
int 14h
mov ah, 01h ; WriteCharacterToCommunicationsPort
mov al, 'H'
int 14h
test ah, ah
jns OK
... function failed with errorcode in bits 0-6 of AH
OK:
mov ax, 4C00h ; TerminateWithReturnCode
int 21h
MAIN ENDP
END MAIN