微机原理实践教程(C语言篇)---A001闪烁灯

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.下载测试

相关推荐
Data_Journal5 小时前
用于网页抓取的 Node-unblocker
大数据·开发语言·数据库·python·scrapy
豆角焖肉5 小时前
SSM 聚合项目搭建:多 Maven 模块项目
开发语言·python·pycharm
Frank_refuel5 小时前
【C++八股】面向对象
开发语言·c++
m0_380743876 小时前
为 OpenAI 兼容接口配置教程
开发语言·python·node.js
M78佐菲7 小时前
c语言学习笔记:排序与查找方法整理
linux·c语言·笔记·学习·算法
万邦科技Lafite7 小时前
阿里巴巴拍立淘按图搜索商品API返回值实践:提升用户购物满意度的关键措施
开发语言·api·开放api·电商开放平台·京东开放平台
小小龙学IT8 小时前
Qt 6 跨平台开发完全指南:从信号槽机制到实际项目落地
开发语言·qt
leisoo80978 小时前
ig50数据落盘ClickHousevsTimescaleDBvsDuckDB实测对比 IG50免费开源股票数据API接口
开发语言·jvm·数据库·python·json
wWYy.8 小时前
C++与C的区别
c语言·c++
敢敢のwings8 小时前
智元 GO-2 与 AgiBot-World 深度解读
开发语言·后端·golang