- 硬件
8088单板机一块,带有简单的串口Bootloader。
2.软件
C编译器:CC=dmc.exe C:\Program Files (x86)\8086 Compilers Bundle\dmc.exe
汇编器:ASM=ml.exe C:\Program Files (x86)\8086 Compilers Bundle\ml.exe
连接器:LD=optlink.exe C:\Program Files (x86)\8086 Compilers Bundle\optlink.exe
编译器、汇编器、连接器通过Proteus 8.3 下载获得
3.源程序
程序驱动8088板上的LED闪烁,并通过8088单板机上的串口,发送字符。
3.1 汇编引导程序
;====================================================================
; rtl.asm file generated by New Project wizard
;
; Created: Thu Apr 16 2015
; Processor: 8086
; Compiler: Digital Mars C
;====================================================================
.MODEL TINY
.8086
.stack
.code
extern _main:near
;org 100h
.startup
cli ; interrupt disable
call near ptr _main
endless:
jmp endless
_write_port:
push bp
mov bp,sp
mov ax,[bp+6]
mov dx,[bp+4]
out dx,al
pop bp
ret
;--------------------------------------
_read_port:
push bp
mov bp,sp
;mov ax,[bp+6]
mov dx,[bp+4]
;out dx,al
in ax,dx
pop bp
ret
;--------------------------------------
_add:
push bp
mov bp,sp
mov ax,[bp+6]
mov bx,[bp+4]
;out dx,al
add ax,bx
pop bp
ret
.data
public __acrtused ; trick to force in startup
__acrtused = 9876h ; funny value not easily matched ; ; in SYMDEB
;xyz db 55h ,55h,55h,55h,55h
;y66 db 55h ,55h,55h,55h,55h
END
3.2 C功能程序
extern void write_port(int addr,int dat);
extern int read_port(int addr);
extern int add(int x,int y);
void uart_send(char x)
{
int temp;
while(1)
{
temp=read_port(0x1f5);
if((temp&0x20)==0x20)
{
break;
}
}
write_port(0x1f0,x);
}
void uart_str_send(void)
{
int i=0;
char str[]="Hello World!\r\n";
char *p;
p=str;
while(*p!='\0')
{
uart_send(*p);
p++;
}
/*
for(i=0;i<14;i++)
{
uart_send(str[i]);
}
*/
}
char str1[]={0x55,0x55,0x55,0x55,0x55,0x55};
void main()
{
int i=0;
int zz=0;
zz=add(4,6);
while(1)
{
/*
asm{
MOV DX,0800H
MOV AL,0aaH
OUT DX,AL
}
*/
zz=read_port(0x202)&0x0f;
if(zz==0x0f)
{
write_port(0x800,0xf0);
}
else
{
write_port(0x800,0x55);
}
uart_send('A');
uart_str_send();
for(i=0;i<5000;i++);
for(i=0;i<5000;i++);
for(i=0;i<5000;i++);
for(i=0;i<5000;i++);
write_port(0x800,0x00);
for(i=0;i<5000;i++);
for(i=0;i<5000;i++);
for(i=0;i<5000;i++);
for(i=0;i<5000;i++);
i+=5;
}
}
4.编译方法
采用make命令编译方式,make会自动按照Makefile文件的约定进行目标文件的编译。
在使用make时候,需要指定make.exee的路径以及编译器、汇编器、连接器的路径。
每次都指定路径的工作,比较繁琐,可以编程一个build.bat批处理文件,文件如下:
ECHO ON
PATH C:\Program Files (x86)\8086 Compilers Bundle;%PATH%
PATH C:\Program Files (x86)\Labcenter Electronics\Proteus 8 Professional\Tools\MAKE;%PATH%
准备还Makefile文件如下:
###############################################################################
# Makefile for project
###############################################################################
## General options
PROJECT =
MCU = 8086
COMPILER = "Digital Mars C"
TARGET = Debug
SHELL = C:\WINDOWS\system32\cmd.exe
## Tools general options
ASMFLAGS=/c /Zm /Zi /Zd /Zf
CCFLAGS=-g -mt -0 -c
#CCFLAGS= -mt
#LDFLAGS=/CO /NODEF:SDS /NOD /DEB /DEBUGB /STACK:1024
LDFLAGS=/TINY
## Processing Tools
CC=dmc.exe
ASM=ml.exe
LD=optlink.exe
# C:/Users/cxhus/AppData/Local/Temp/b85b4c07cf464bdb9f9c18cabb40784e/8086/Debug/Debug.exe: TOOL=LD
# C:/Users/cxhus/AppData/Local/Temp/b85b4c07cf464bdb9f9c18cabb40784e/8086/Debug/main.obj: TOOL=CC
# C:/Users/cxhus/AppData/Local/Temp/b85b4c07cf464bdb9f9c18cabb40784e/8086/main.c
# C:/Users/cxhus/AppData/Local/Temp/b85b4c07cf464bdb9f9c18cabb40784e/8086/Debug/rtl.obj: TOOL=ASM
# C:/Users/cxhus/AppData/Local/Temp/b85b4c07cf464bdb9f9c18cabb40784e/8086/rtl.asm
# C:/Users/cxhus/AppData/Local/Temp/b85b4c07cf464bdb9f9c18cabb40784e/8086/Debug/board.obj: TOOL=CC
# C:/Users/cxhus/AppData/Local/Temp/b85b4c07cf464bdb9f9c18cabb40784e/8086/board.c
# C:/Users/cxhus/AppData/Local/Temp/b85b4c07cf464bdb9f9c18cabb40784e/8086/Debug/calc.obj: TOOL=CC
# C:/Users/cxhus/AppData/Local/Temp/b85b4c07cf464bdb9f9c18cabb40784e/8086/calc.c
# C:/Users/cxhus/AppData/Local/Temp/b85b4c07cf464bdb9f9c18cabb40784e/8086/math.lib
# Build tree:
all: Debug
Debug: Debug.COM
Debug.COM: main.obj rtl.obj ../math.lib
$(LD) $(LDFLAGS) rtl.obj+main.obj,Debug.COM
main.obj: ../main.c
$(CC) $(CCFLAGS) -omain.obj ../main.c
rtl.obj: ../rtl.asm
$(ASM) $(ASMFLAGS) ../rtl.asm
# tidy - delete all temporary files which are not involved in the target generation
tidy:
# cleanup - delete all generated files
clean: tidy
rm -rf Debug.COM
rm -rf main.obj
rm -rf rtl.obj
rm -rf board.obj
rm -rf calc.obj
5.测试方法
将编译好的Debug.com通用8088单板机下载,即可得到运行结果的检验。