[{"createTime":1735734952000,"id":1,"img":"hwy_ms_500_252.jpeg","link":"https://activity.huaweicloud.com/cps.html?fromacct=261f35b6-af54-4511-a2ca-910fa15905d1&utm_source=V1g3MDY4NTY=&utm_medium=cps&utm_campaign=201905","name":"华为云秒杀","status":9,"txt":"华为云38元秒杀","type":1,"updateTime":1735747411000,"userId":3},{"createTime":1736173885000,"id":2,"img":"txy_480_300.png","link":"https://cloud.tencent.com/act/cps/redirect?redirect=1077&cps_key=edb15096bfff75effaaa8c8bb66138bd&from=console","name":"腾讯云秒杀","status":9,"txt":"腾讯云限量秒杀","type":1,"updateTime":1736173885000,"userId":3},{"createTime":1736177492000,"id":3,"img":"aly_251_140.png","link":"https://www.aliyun.com/minisite/goods?userCode=pwp8kmv3","memo":"","name":"阿里云","status":9,"txt":"阿里云2折起","type":1,"updateTime":1736177492000,"userId":3},{"createTime":1735660800000,"id":4,"img":"vultr_560_300.png","link":"https://www.vultr.com/?ref=9603742-8H","name":"Vultr","status":9,"txt":"Vultr送$100","type":1,"updateTime":1735660800000,"userId":3},{"createTime":1735660800000,"id":5,"img":"jdy_663_320.jpg","link":"https://3.cn/2ay1-e5t","name":"京东云","status":9,"txt":"京东云特惠专区","type":1,"updateTime":1735660800000,"userId":3},{"createTime":1735660800000,"id":6,"img":"new_ads.png","link":"https://www.iodraw.com/ads","name":"发布广告","status":9,"txt":"发布广告","type":1,"updateTime":1735660800000,"userId":3},{"createTime":1735660800000,"id":7,"img":"yun_910_50.png","link":"https://activity.huaweicloud.com/discount_area_v5/index.html?fromacct=261f35b6-af54-4511-a2ca-910fa15905d1&utm_source=aXhpYW95YW5nOA===&utm_medium=cps&utm_campaign=201905","name":"底部","status":9,"txt":"高性能云服务器2折起","type":2,"updateTime":1735660800000,"userId":3}]
今天刚学了用c语言点灯,那么我就在想可不可试一下用汇编语言来进行点灯(来自点灯攻城狮的手动狗头)
最简单的是点灯,当单片机引脚P2口连接的是LED时
CLR P2.0 ;这里的意思时将P2.0引脚置为低电平(LEDL连接方式为共阳极时点亮P2.0上的LED)
这样就可以点亮 P2.0接口上的LED了~~ (当然 这样一句汇编代码是不完整的,会有警告,但是编译输入后时可以点灯的)
茴香豆的茴 ,有几种写法,那么点灯也是如此,我们都知道在汇编语言中MOV的意思可以理解为赋值,即将源操作数赋值给目标操作数(将后面的东西赋值给前面的寄存器)
MOV P2,#0FH ;#的作用是将0FH标记为立即数,将0FH 换成 0000 1111B 也没毛病
十六进制的0F 转化成二进制是 0000 1111
这样就可以将P2.4、P2.5、P2.6、P2.7 上的LED进行点亮了~~
如此,通过修改#后面的十六进制数就可以随意的点亮某个灯了~~
细心的朋友可能会发现,不是引脚为低电平的时候亮吗?
那么进制转换后不是第前面四位为0,后面四位为1吗,不应该是前四个灯亮,后四个灯灭吗?这是我的理解是他是从高位开始赋值的,具体怎么解释我也不明白,嘤嘤~
要实现闪烁还得加延时函数空耗CPU的时间实现延时,代码如下
DELAY: MOV R7,#255 ;11.0592MHz晶振 ,让下面的D1执行255次 也就是延时255毫秒 D1:
;D1这里到最后可以延时1毫秒,R7最多只能装255,超过就会溢出,多写无用 NOP
;想增加延时的时长,只能多加R6之类的寄存器装数字嵌套在DELAY里面,或者用软 PUSH 30H ;件生成一个新的延时函数 PUSH 31H MOV
30H,#2 MOV 31H,#194 NEXT: DJNZ 31H,NEXT DJNZ 30H,NEXT POP 31H POP 30H DJNZ
R7,D1 RET
增加延时的时长可以更改R7#后面的数值,但最大仅为255,在想延时更久,可以多加一个寄存器进行循环嵌套或者用软件生成一个新的延时函数,这样就可以自定义延时的时间了。
完整的代码是这样的
MAIN: MOV P2, #0FFH LCALL DELAY MOV P2, #00H LCALL DELAY LJMP MAIN DELAY: MOV
R7,#255 D1: NOP PUSH 30H PUSH 31H MOV 30H,#2 MOV 31H,#194 NEXT: DJNZ 31H,NEXT
DJNZ 30H,NEXT POP 31H POP 30H DJNZ R7,D1 RET END
代码的功能就是可以将连接在P2口上所有的LED灯同步进行闪烁
本贴仅为记录学习