发布者: 未知 来源:网络
p0口定义为输出口.
org 0000h /*起始地址*/
ajmp main
org 0030h/*从地址0030H开始执行程序*/
main: acall yy
acall yy
acall yy
acall can
acall can
acall can
ajmp main
can: mov scon,#00h/*设置UART为方式0,即使SBUF相当于一个并入串出同步移位寄存器*/
start: mov dptr,#tab/*使数据指针指向TAB的开头*/
loop: clr a/*清累加器*/
movc a,@a+dptr/*从TAB中取出数据*/
cjne a,#0ah,a1/*取到结束码吗,不是则跳A1*/
ajmp MAIN/*跳到开始*/
a1: cpl a/*将数据反相*/
mov 30h,a/*结果暂存30H中*/
mov sbuf,30h/*开始发送数据*/
loop1: jbc ti,loop2/*发送完毕吗,完毕则清TI,未完则等待*/
sjmp loop1
loop2: acall delay/*延时200MS*/
inc dptr/*数据指针加1*/
ret
tab: db 01h,02h,04h,08h /*左移*/
db 10h,20h,40h,80h
db 01h,02h,04h,08h /*左移*/
db 10h,20h,40h,80h
db 80h,40h,20h,10h/*右移*/
db 08h,04h,02h,01h
db 80h,40h,20h,10h/*右移*/
db 08h,04h,02h,01h
db 00h,0ffh,00h,0ffh/*闪动*/
db 0aH /*结束码*/
yy: mov a,#0ffh/*左移初值*/
clr c
mov r2,#08h/*设左移8次*/
lop: rlc a /*左移一位*/
mov p0,a/*输出到P0口*/
acall delay/*延时0.2秒*/
djnz r2,loop/*判断左移次数是否到7次*/
mov r2,#07h
lop1: rrc a /*右移一位*/
mov p0,a/*输出到P0口*/
acall delay
djnz r2,MAIN/*右移7次?*/
ret
delay: mov r3,#20/*延时0.2秒*/
dl0: mov r4,#20
dl1: mov r5,#248
djnz r5,$
djnz r4,dl1
djnz r3,dl0
ret
end