一个是字幕(用一个点阵模块),从左向右走的数字0123,使用STC89C52单片机的P0和P2口,P0口接电阻。
第二个是一首生日快乐歌曲使用单片机的P1.5口。
下边是两个汇编程序,单个可以正常使用,想把他们合起来,不知道怎么弄,因为每个程序都还看不大懂。
字幕
------------------------------------------
;8X8LED点阵流动显示
;逐列扫描
ORG 0000H
AJMP MAIN
ORG 0030H
MAIN: MOV DPTR,#TAB ;字码表初址赋值
MOV R1,#0FEH ;列控制码
MOV R3,#8 ;列数
MOV R4,#88 ;移动“及 ”“0~9”11个字符,共88列
CM: MOV R5,#10 ;每屏反复显示10次
MOV R3,#8 ;列数
C1: MOV R2,#0 ;取字指针
C8: MOV P3,#0FFH ;关显示
MOV A,R2 ;
MOVC A,@A+DPTR ;取当前列的显示字码的一个字节
MOV P0,A ;送1~8行控制口
INC R2
MOV A,R1
MOV P3,A ;送列控制码
ACALL D5MS ;显示5MS
RL A ;列控制码左移,显示下一列
MOV R1,A
DJNZ R3,C8 ;未显示8 列,继续
MOV R3,#8
DJNZ R5,C1 ;未显示10次,继续
INC DPL ;一屏反复显示10次完,字码表初值加1
DJNZ R4,CM ;88列未移动完,继续
AJMP MAIN ;88列显示完,返回,重新从“ ”开始显示
D5MS: MOV R6,#10
MOV R7,#248
DJNZ R7,$
DJNZ R6,$-4
RET
TAB: DB 00H,00H,00H,00H,00H,00H,00H,00H
DB 00H,00H,00H,7EH,81H,81H,81H,7EH;0
DB 00H,00H,00H,00H,00H,82H,0FFH,80H;1
DB 00h,00h,00h,0C6H,0A1H,91H,89H,0C6H;2
DB 00H,00H,00H,42H,81H,81H,99H,66H;3
DB 00H,00H,00H,00H,00H,00H,00H,00H
END
--------------------------------------------------------
生日快乐歌
----------------------------------------
org 0000h
ajmp main
org 000bh
jmp tim0
org 0030h
main: ;主程序
mov tmod,#01h ;设定时方式
mov ie,#82h ;开中断
start0:
mov 30h,#00h ;
next:mov a,30h
mov dptr,#table
movc a,@a+dptr ;查表取音调和节拍
mov r2,a
jz end0 ;为零,不进行处理.
anl a,#0fh
mov r5,a ;将节拍存入R5
mov a,r2
swap a
anl a,#0fh
jnz sing ;根据音调决定是否演奏.
clr tr0
jmp d1
sing:dec a
mov 22h,a ;将音调存入22H.
rl a
mov dptr,#table1
movc a,@a+dptr ;根据音调决定定时器初值.
mov th0,a ;放入TH0
mov 21h,a
mov a,22h
rl a
inc a
movc a,@a+dptr
mov tl0,a ;放入TL0
mov 20h,a
setb tr0 ;启动定时
d1: call delay
inc 30h
jmp next
end0:clr tr0
jmp start0
tim0: ;定时器中断服务程序
push acc
push psw
mov tl0,20h ;重赋初值.
mov th0,21h
cpl p1.5
pop psw
pop acc
reti
delay:mov r7,#02h ;延时子程序
d2: mov r4,#187
d3: mov r3,#248
djnz r3,$
djnz r4,d3
djnz r7,d2
djnz r5,delay
ret
table1: ;决定音调的定时初值.
dw 64260,64400,64524,64580
dw 64684,64777,64820,64898
dw 64968,65030,65058,65110
dw 65157,65178,65217
table: ;决定音调和节拍的表格,不同的歌曲只是此表不同
;1
db 82h,01h,81h,94h,84h,0b4h,0a4h,04h,82h,01h,81h,94h,84h,0c4h,0b4h,04h
;2
db 82h,01h,81h,0f4h,0d4h,0b4h,0a4h,94h,0e2h,01h,0e1h,0d4h,0b4h,0c4h,0b4h,04h
;3
db 82h,01h,81h,94h,84h,0b4h,0a4h,04h,82h,01h,81h,94h,84h,0c4h,0b4h,04h
;4
db 82h,01h,81h,0f4h,0d4h,0b4h,0a4h,94h,0e2h,01h,0e1h,0d4h,0b4h,0c4h,0b4h,04h,00
end
----------------------------------------------------------------