中斷系統(tǒng)的應(yīng)用舉例 (含源程序)
6.4.1 外部中斷舉例
【例6-3】使用外部中斷0,當(dāng)每次響應(yīng)中斷時(shí),P1口依次輸出高電
平,使8個(gè)發(fā)光二極管依次循環(huán)熄滅閃爍。
1) 電路設(shè)計(jì)
ORG0000H
LJMPMAIN;轉(zhuǎn)主程序
ORG0003H;外部中斷0入口地址
LJMPEXTER;轉(zhuǎn)中斷程序
ORG1000H
MAIN:SETBIT0;外部中斷0下降沿有效
SETBEX0;外部中斷0允許
SETBEA;總中斷允許
LOOP:AJMPLOOP;等待中斷
ORG1050H;中斷程序入口
EXTER:MOVR2, #0FFH;置循環(huán)次數(shù)
MOVA, #01H;燈亮初值FLASH:RRA;右移一位
MOVR7, #0FFH;定時(shí)
LOOP1:MOVR6, #0FFH
LOOP2:NOP
NOP
DJNZR6, LOOP2
DJNZR7, LOOP1
MOVP1, A;控制燈的亮滅
DJNZR2, FLASH;循環(huán)
RETI;中斷返回
END
定時(shí)器舉例
通過定時(shí)器1來產(chǎn)生中斷,控制P1.0線上的脈沖輸出,并經(jīng)三極管驅(qū)動(dòng)揚(yáng)聲器,發(fā)出音調(diào)信號(hào)。
1) 電路設(shè)計(jì)
ORG0000H
LJMPMAIN
ORG001BH;中斷入口地址
CPLP1.0
RETI
ORG1000H
MAIN:MOVR1, #00H
MOVR0, #23H
MOVTMOD, #20H;定時(shí)器1工作方式2
MOVIE, #88H;定時(shí)器1允許中斷
L1:MOVDPTR, #3FFFH
MOVA, R0;取數(shù)
INCR0;修改指針
MOVCA, @A+PC;查表
JZMAIN
MOVR1, A;計(jì)算計(jì)數(shù)初值
MOVA, #0FFH
CLRC
SUBBA, R1
RLA
MOVTH1, A;置計(jì)數(shù)初值
SETBTR1;開始計(jì)數(shù)
L2:CLRC
MOVA, DPL;延時(shí)
SUBBA, #01H
MOVDPL, A
MOVA, DPH
SUBBA, #00H
MOVDPH, A
ORLA, DPL
JNZL2
CLRTR1
SJMPL1
END
ORG1031H;歌曲“送別”編碼
DB 33H,33H,3DH,33H,26H
DB 26H, 26H, 26H,2DH,2DH
DB 26H,2DH,33H,33H,33H
DB 33H, 33H,33H,4DH,45H
DB 45H, 45H45H, 45H, 45H
DB 45H, 45H,33H,33H,3DH
DB 33H,26H,26H,26H, 28H
DB 2DH, 2DH, 26H,26H,33H
DB 33H,33H,33H,45H,3DH
評(píng)論