1.硬件



2.C程序
cpp#define ADR_273 0x0200 #define ADR_244 0x0400 #define LED_PORT 0x800 void outp(unsigned int addr, char data) // 输出一字节到I/O端口 { __asm { mov dx, addr mov al, data out dx, al } } char inp(unsigned int addr) // 从I/O端口输入一字节 { char result; __asm { mov dx, addr in al, dx mov result, al } return result; } char end_flag[5]={0x55,0x55,0x55,0x55,0x55}; void delay(void) // 延时函数,使用原有的双重循环延时方式 { int i; for(i=0; i<5000; i++); for(i=0; i<5000; i++); } void main(void) /* 闪烁灯程序:8位LED时亮时灭 采用共阳LED,输出0点亮,输出1熄灭 */ { int i; unsigned char led_pattern; // 初始值:1111 1110 (最低位D0=0,点亮第1个LED) led_pattern = 0x00; while (1) { // 输出当前模式到LED端口 outp(LED_PORT, led_pattern); // 延时控制流水速度 delay(); led_pattern = ~led_pattern; outp(LED_PORT, led_pattern); delay(); } // 退出时关闭所有LED(输出全1) // outp(LED_PORT, 0xFF); }
汇编
cpp
.MODEL TINY
.8086
.code
extrn _main:proc
.startup
call near ptr _main
endless:
jmp endless
.data
public __acrtused ; trick to force in startup
__acrtused = 9876h ; funny value not easily matched in SYMDEB
.stack
END
3.编译脚本
bash
..\tools\ml.exe /c /AT /Zm /Zi rtl.asm
..\tools\dmc.exe -mt -0 -c -g main.c
..\tools\optlink.exe /TINY rtl.obj main.obj, debug.com

4.下载测试



