8088单板机编译运行C程序的方法

  1. 硬件

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单板机下载,即可得到运行结果的检验。

  • 17
    点赞
  • 11
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

iCxhust

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值