1.设计内容
此次课程设计的基础内容为设计一个交通情报板,可用于对道路车辆进行道路现状提示。作为拓展添加8259主片及从片进行切换显示,主要设计内容有:
(1)使用16*16的LED点阵来显示交通标志语
(2)利用8259的MIR7中断来切换点阵显示的具体内容
(3)利用8259的MIR6、MIR7以及从片的SIR1来切换点阵显示的具体内容
2.设计要求
(1)通过本次课程设计,使学生综合运用《微机原理与接口技术》课程中的所学知识,为今后从事计算机检测与控制工作奠定一定的基础
(2)掌握接口芯片8255、8259等可编程器件、点阵显示器件的使用
(3)学会用汇编语言编写一个较完整的实用程序
3.芯片选择
在本系统中,主要采用的芯片有8259中断芯片以及点阵LED显示单元。
8259中断芯片用于对交通提示语进行切换。
点阵LED显示单元负责显示交通提示语。
4. 基本功能描述
(1)利用8259的MIR7中断来切换点阵显示的具体内容
运行程序后,初始点阵无字符显示。按一次KK1(KK1+与中断已连接)后产生一次中断,切换到显示第一句交通标志语,每按一次会切换一句标志语。共有4句交通标志语,全部显示完后再按KK1键可让点阵回到无字符显示的状态。
(2)利用8259的MIR6、MIR7以及从片的SIR1来切换点阵显示的具体内容
运行程序后,初始点阵无字符显示。推动对应的开关后产生相应的不同的中断,程序根据中断的不同来显示不同的标志语。
5.总体设计思路
(1)点阵字符的显示
本次程序实现的是点阵向上卷动显示具体内容。本次使用的点阵大小为16*16,且行为1,列为0时对应的LED灯点亮。利用视觉暂留效应,逐行进行显示,显示完一遍后将所要显示的内容的地址+2,实现向上的卷动显示。当标志语全部显示一遍后,再将地址设为初始地址,重新进行显示,如无中断发生则会一直循环下去。
(2)利用中断切换显示内容
程序在执行完初始化后进入一个死循环,死循环中通过判断CX的值来进一步确定是否发生过中断(中断子程序的主要作用是改变CX的值),若发生过中断则跳到显示内容的死循环中,每个显示内容的死循环都会检测CX的值是否改变,若改变则跳出死循环重新进行判断。
6.点阵LED显示单元介绍
实验系统中的16x16 LED点阵由四块8x8 LED点阵组成,如图4.11.1所示,8X8点阵内部结构图如图4.11.2所示。图4.11.2可知,当行为“0”, 列为“1”,则对应行、列上的LED点亮。图4.11.3为点阵外部引脚图。汉字显示如图4.11.4所示。
点阵实验单元电路图如图4.11.5所示。由于2803输出反向,所以行为1,列为0时对于点的LED点亮。
7.硬件连线图
硬件连线图如图所示,运行程序后,初始点阵无字符显示。推动对应的开关后产生相应的不同的中断,程序根据中断的不同来显示不同的标志语。由于MIR7、MIR6及SIR1均为圆口,而开关为方口,故需要转换单元进行转换显示,LED点阵显示单元需要IOYO-IOY3四个端口,故只能用8259中断来控制交通标志语的显示。
8.代码设计
(1)利用8259的MIR7中断来切换点阵显示的具体内容
首先要对主片8259进行初始化,ICW2初始化(00001000)后确定了MIR7的中断矢量地址为003CH,段地址为003EH。OCW1初始化后确定了7号串口不被屏蔽,可产生中断。
;初始化主片8259MOV AL, 11HOUT 20H, AL;ICW1MOV AL, 08HOUT 21H, AL;ICW2MOV AL, 04HOUT 21H, AL;ICW3MOV AL, 01HOUT 21H, AL;ICW4MOV AL, 6FH;OCW1 0110 1111 开放4号中断串口用,7号中断实验用OUT 21H, ALSTI中断子程序如下,主要实现了将CX-1的功能,若CX原来为零则改为4MIR7:STI;允许中断CALL DELAYCMP CX,0JNZ AA2;如果不为0就跳到AA2MOV CX,5AA2:DEC CXMOV AX, 0137HINT 10H;显示字符7MOV AX, 0120HINT 10HMOV AL, 20HOUT 20H, AL;中断结束命令IRET
以显示第一句话为例:首先比较比较CX是否为4,若是则显示第一句话,不是则进行接下来的比较。然后根据字数的多少来确定大的循环次数。第一句话为“请保持车距”,总共有5个字,每个字需要有32个字节用来显示,由于最后一个字显示后就回重新显示,所以AX的值为32*4/2=64。
此外还应该注意,在调用显示函数DISP时,里面会用到CX的值,第一我们需要预先对原先的CX值进行保护,第二我们需要在执行这一段子程序的时候将中断禁止,否则如果在执行这个子程序时有中断产生,也不会切换显示内容。
N0:CMP CX,4JNZ N1BG0: MOV AX, 64MOV SI, OFFSET HZDOTht0BG1:CLICALL DELAY1CALL DISPSTIADD SI, 2 ;跳到下一个CMP CX,4;看CX的值有没有改变JNZ AA1;如果改变就说明发生过中断,就跳回AA1进行判断DEC AX;如果没有改变就继续执行死循环JZ BG0JMP BG1
(2)利用8259的MIR6、MIR7以及从片的SIR1来切换点阵显示的具体内容
首先要对主片8259和从片8259进行相应的初始化工作,
MOV AX, OFFSET SIR1MOV SI, 00C4HMOV [SI], AXMOV AX, CSMOV SI, 00C6HMOV [SI], AXCLIPOP DS;初始化主片8259MOV AL, 11HOUT 20H, AL;ICW1MOV AL, 08HOUT 21H, AL;ICW2MOV AL, 04HOUT 21H, AL;ICW3MOV AL, 01HOUT 21H, AL;ICW4;初始化从片8259MOV AL, 11HOUT 0A0H, AL;ICW1MOV AL, 30HOUT 0A1H, AL;ICW2MOV AL, 02HOUT 0A1H, AL;ICW3MOV AL, 01HOUT 0A1H, AL;ICW4MOV AL, 0FDHOUT 0A1H,AL;OCW1 = 1111 1101MOV AL, 2BHOUT 21H, AL;主8259 OCW1STI
然后根据推不同的开关,产生不同的CX值,由不同的CX值来显示相对应的交通标志语即可。
交通标志语显示代码:
;======显示汉字子程序=====;入口参数: SI = 存放汉字起始地址DISP:PUSH CXMOV CX, 000FHPUSH AXML0:PUSH CXMOV BL, 01HMOV CX, 0008HML1:MOV DX, ROW1;控制0--7行MOV AL, 00HOUT DX, ALMOV AL, [SI]NOT ALMOV DX, COL1;0--7列OUT DX, ALINC SIMOV AL, [SI]NOT ALMOV DX, COL2;8--15列OUT DX, ALINC SIMOV DX, ROW1;控制0--7行MOV AL, BLOUT DX, ALROL BL, 1CALL DELAY1LOOP ML1MOV DX, ROW1MOV AL, 00HOUT DX, ALMOV CX, 0008HML2:MOV DX, ROW2;控制8--15行MOV AL, 00HOUT DX, ALMOV AL, [SI]NOT ALMOV DX, COL1;0--7列OUT DX, ALINC SIMOV AL, [SI]NOT ALMOV DX, COL2;8--15列OUT DX, ALINC SIMOV DX, ROW2;控制8--15行MOV AL, BLOUT DX, ALROL BL, 1CALL DELAY1LOOP ML2MOV DX, ROW2MOV AL, 00HOUT DX, ALSUB SI, 32POP CXLOOP ML0POP AXPOP CXRET
9.实验结果
9.1 实验箱连线图
9.2 程序运行结果
(1)利用8259的MIR7中断来切换点阵显示的具体内容
程序运行后无显示,用户按下KK1键后,显示第一条标志语“请保持车距”,之后每按一次KK1键显示不同的标志语,依次为“雨天路滑,谨慎驾驶”“全程监控,减速慢行”“台风天气,谨慎驾驶”,显示到第四条后若再按KK1则回到初始无显示的状态。
(2)利用8259的MIR6、MIR7以及从片的SIR1来切换点阵显示的具体内容
程序运行后无显示,用户按下推上K1后,显示第一条标志语“请保持车距”,之后每推K1-K3键显示不同的标志语,依次为“雨天路滑,谨慎驾驶”“全程监控,减速慢行”。
10.代码附录如下
;=========================================================; 文件名: A82591.ASM; 功能描述: 8259中断实验,中断源为主片8259的IRQ7; 每产生一次中断输出显示一个字符7;=========================================================ROW1EQU 0600H;端口定义IOY0ROW2EQU 0640H;端口定义IOY1COL1EQU 0680H;端口定义IOY2COL2 EQU 06C0H;端口定义IOY3STACK1SEGMENT STACKDW 256 DUP(?)STACK1ENDSDATA SEGMENT;DTABLEDB 3FH,06H,5BH,4FH,66H,6DH,7DH,07H;DB 7FH,6FH,77H,7CH,39H,5EH,79H,71HHZDOTht0 DB 000H,002H,002H,002H,0E4H,03FH,004H,002HDB 0C0H,01FH,000H,002H,0E7H,07FH,004H,000HDB 0C4H,01FH,044H,010H,0C4H,01FH,044H,010HDB 0D4H,01FH,04CH,010H,044H,014H,040H,008H;保 CB1A3DB 010H,000H,0D0H,01FH,050H,010H,048H,010HDB 048H,010H,0CCH,01FH,00CH,002H,00AH,002HDB 0E9H,03FH,008H,007H,088H,00AH,048H,012HDB 028H,022H,018H,042H,008H,002H,008H,002H;持 CB3D6DB 008H,004H,008H,004H,008H,004H,088H,03FHDB 03FH,004H,008H,004H,0C8H,07FH,008H,010HDB 018H,010H,0CCH,07FH,00BH,010H,008H,011HDB 008H,012H,008H,010H,00AH,014H,004H,008H;车 CB3B5DB 040H,000H,040H,000H,040H,000H,0FEH,03FHDB 020H,000H,090H,000H,088H,000H,084H,000HDB 0FCH,01FH,080H,000H,080H,000H,0FFH,07FHDB 080H,000H,080H,000H,080H,000H,080H,000H;距 CBEE0DB 000H,000H,0BEH,07FH,0A2H,000H,0A2H,000HDB 0A2H,000H,0BEH,03FH,088H,020H,088H,020HDB 0BAH,020H,08AH,020H,08AH,03FH,08AH,000HDB 0BAH,000H,087H,000H,080H,07FH,000H,000H;*********************************************HZDOTht1 DB 000H,000H,0FFH,07FH,080H,000H,080H,000HDB 080H,000H,0FEH,03FH,082H,020H,082H,020HDB 092H,022H,0A2H,024H,082H,020H,092H,022HDB 0A2H,024H,082H,020H,082H,028H,002H,010H;天 CCCECDB 000H,000H,0FCH,01FH,080H,000H,080H,000HDB 080H,000H,080H,000H,0FFH,07FH,080H,000HDB 040H,001H,040H,001H,020H,002H,020H,002HDB 010H,004H,008H,008H,004H,010H,003H,060H;路 CC2B7DB 000H,002H,03EH,002H,022H,01EH,022H,011HDB 0A2H,00AH,03EH,004H,008H,00AH,008H,011HDB 088H,060H,03AH,01FH,00AH,011H,00AH,011HDB 00AH,011H,03AH,011H,007H,01FH,000H,011H;滑 CBBACDB 000H,000H,0C4H,01FH,048H,010H,0C8H,013HDB 041H,012H,0F2H,07FH,012H,040H,0C8H,01FHDB 048H,010H,0C4H,01FH,047H,010H,0C4H,01FHDB 044H,010H,044H,010H,044H,014H,040H,008H;, CA3ACDB 000H,000H,000H,000H,000H,000H,000H,000HDB 000H,000H,000H,000H,000H,000H,000H,000HDB 000H,000H,000H,000H,000H,000H,00CH,000HDB 00CH,000H,008H,000H,004H,000H,000H,000H;谨 CBDF7DB 080H,008H,082H,008H,0F4H,07FH,084H,008HDB 080H,00FH,000H,002H,0E7H,03FH,024H,022HDB 0E4H,03FH,004H,002H,0F4H,07FH,004H,002HDB 0F4H,03FH,00CH,002H,0F4H,07FH,000H,000H;慎 CC9F7DB 004H,002H,004H,002H,0E4H,03FH,004H,002HDB 0CCH,01FH,055H,010H,0C5H,01FH,045H,010HDB 0C5H,01FH,044H,010H,0C4H,01FH,044H,010HDB 0F4H,07FH,084H,008H,044H,010H,024H,020H;驾 CBCDDDB 010H,000H,010H,000H,0FEH,03EH,088H,022HDB 088H,022H,0A4H,03EH,042H,000H,0F8H,007HDB 000H,004H,010H,004H,010H,004H,0F0H,03FHDB 000H,020H,0FEH,023H,000H,028H,000H,010H;驶 CCABBDB 000H,004H,01FH,004H,010H,004H,092H,03FHDB 092H,024H,092H,024H,092H,024H,0BEH,024HDB 0A0H,03FH,020H,004H,038H,005H,027H,006HDB 022H,006H,020H,009H,094H,010H,048H,060HHZDOTht2 DB 080H,000H,080H,000H,040H,001H,020H,002HDB 010H,004H,008H,008H,0F4H,017H,083H,060HDB 080H,000H,080H,000H,0F8H,00FH,080H,000HDB 080H,000H,080H,000H,0FEH,03FH,000H,000H;程 CB3CCDB 010H,000H,0B8H,03FH,08FH,020H,088H,020HDB 088H,020H,0BFH,03FH,008H,000H,00CH,000HDB 09CH,07FH,02AH,004H,02AH,004H,089H,03FHDB 008H,004H,008H,004H,0C8H,07FH,008H,000H;监 CBCE0DB 020H,002H,024H,002H,024H,03EH,024H,002HDB 024H,009H,024H,011H,0A4H,010H,020H,000HDB 000H,000H,0FCH,01FH,024H,012H,024H,012HDB 024H,012H,024H,012H,0FFH,07FH,000H,000H;控 CBFD8DB 008H,002H,008H,004H,008H,004H,0C8H,07FHDB 05FH,040H,028H,029H,088H,010H,058H,020HDB 00CH,000H,08BH,03FH,008H,004H,008H,004HDB 008H,004H,008H,004H,0EAH,07FH,004H,000H;, CA3ACDB 000H,000H,000H,000H,000H,000H,000H,000HDB 000H,000H,000H,000H,000H,000H,000H,000HDB 000H,000H,000H,000H,000H,000H,00CH,000HDB 00CH,000H,008H,000H,004H,000H,000H,000H;减 CBCF5DB 000H,028H,002H,048H,004H,008H,0E4H,07FHDB 020H,008H,020H,008H,0A8H,00BH,028H,048HDB 024H,048H,0A7H,02BH,0A4H,02AH,0A4H,012HDB 0A4H,05BH,024H,054H,014H,062H,008H,041H;速 CCBD9DB 000H,002H,004H,002H,0E8H,03FH,008H,002HDB 0C0H,01FH,040H,012H,04FH,012H,0C8H,01FHDB 008H,007H,088H,00AH,048H,012H,028H,022HDB 008H,002H,014H,000H,0E2H,07FH,000H,000H;慢 CC2FDDB 0C4H,01FH,044H,010H,0C4H,01FH,04CH,010HDB 0D5H,01FH,005H,000H,0E5H,03FH,025H,025HDB 024H,025H,0E4H,03FH,004H,000H,0C4H,01FHDB 084H,008H,004H,007H,0C4H,018H,034H,060H;行 CD0D0DB 010H,000H,090H,03FH,008H,000H,004H,000HDB 012H,000H,010H,000H,0C8H,07FH,00CH,004HDB 00AH,004H,009H,004H,008H,004H,008H,004HDB 008H,004H,008H,004H,008H,005H,008H,002H;*******************************************;台风天气,谨慎驾驶;台 CCCA8HZDOTht3 DB 040H,000H,040H,000H,020H,000H,010H,004HDB 008H,008H,004H,010H,0FEH,03FH,004H,020HDB 000H,000H,0F8H,00FH,008H,008H,008H,008HDB 008H,008H,008H,008H,0F8H,00FH,008H,008H;风 CB7E7DB 000H,000H,0FCH,00FH,004H,008H,004H,008HDB 014H,00AH,024H,00AH,044H,009H,044H,009HDB 084H,008H,084H,008H,044H,009H,044H,049HDB 024H,052H,012H,052H,002H,060H,001H,040H;天 CCCECDB 000H,000H,0FCH,01FH,080H,000H,080H,000HDB 080H,000H,080H,000H,0FFH,07FH,080H,000HDB 040H,001H,040H,001H,020H,002H,020H,002HDB 010H,004H,008H,008H,004H,010H,003H,060H;气 CC6F8DB 008H,000H,008H,000H,0FCH,03FH,004H,000HDB 0F2H,00FH,001H,000H,0FCH,00FH,000H,008HDB 000H,008H,000H,008H,000H,008H,000H,008HDB 000H,050H,000H,050H,000H,060H,000H,040H;, CA3ACDB 000H,000H,000H,000H,000H,000H,000H,000HDB 000H,000H,000H,000H,000H,000H,000H,000HDB 000H,000H,000H,000H,000H,000H,00CH,000HDB 00CH,000H,008H,000H,004H,000H,000H,000H;谨 CBDF7DB 080H,008H,082H,008H,0F4H,07FH,084H,008HDB 080H,00FH,000H,002H,0E7H,03FH,024H,022HDB 0E4H,03FH,004H,002H,0F4H,07FH,004H,002HDB 0F4H,03FH,00CH,002H,0F4H,07FH,000H,000H;慎 CC9F7DB 004H,002H,004H,002H,0E4H,03FH,004H,002HDB 0CCH,01FH,055H,010H,0C5H,01FH,045H,010HDB 0C5H,01FH,044H,010H,0C4H,01FH,044H,010HDB 0F4H,07FH,084H,008H,044H,010H,024H,020H;驾 CBCDDDB 010H,000H,010H,000H,0FEH,03EH,088H,022HDB 088H,022H,0A4H,03EH,042H,000H,0F8H,007HDB 000H,004H,010H,004H,010H,004H,0F0H,03FHDB 000H,020H,0FEH,023H,000H,028H,000H,010H;驶 CCABBDB 000H,004H,01FH,004H,010H,004H,092H,03FHDB 092H,024H,092H,024H,092H,024H,0BEH,024HDB 0A0H,03FH,020H,004H,038H,005H,027H,006HDB 022H,006H,020H,009H,094H,010H,048H,060HDATA ENDSCODE SEGMENTASSUME CS:CODE,DS:DATASTART: PUSH DSMOV AX, 0000HMOV DS, AXMOV AX, OFFSET MIR7;取中断入口地址MOV SI, 003CH;中断矢量地址MOV [SI], AX;填IRQ7的偏移矢量MOV AX, CS;段地址MOV SI, 003EHMOV [SI], AX;填IRQ7的段地址矢量MOV AX, OFFSET MIR6MOV SI, 0038HMOV [SI], AXMOV AX, CSMOV SI, 003AHMOV [SI], AXMOV AX, OFFSET SIR1MOV SI, 00C4HMOV [SI], AXMOV AX, CSMOV SI, 00C6HMOV [SI], AXCLIPOP DS;初始化主片8259MOV AL, 11HOUT 20H, AL;ICW1MOV AL, 08HOUT 21H, AL;ICW2MOV AL, 04HOUT 21H, AL;ICW3MOV AL, 01HOUT 21H, AL;ICW4;初始化从片8259MOV AL, 11HOUT 0A0H, AL;ICW1MOV AL, 30HOUT 0A1H, AL;ICW2MOV AL, 02HOUT 0A1H, AL;ICW3MOV AL, 01HOUT 0A1H, AL;ICW4MOV AL, 0FDHOUT 0A1H,AL;OCW1 = 1111 1101MOV AL, 2BHOUT 21H, AL;主8259 OCW1STIRESTART:MOV CX,8AA1:NOP;*********************************************;判断部分CMP CX,8JZ AA1;如果为8则跳转到AA1JNZ N0;如果不为8则跳转到N0N0:CMP CX,7JNZ N1BG0: MOV AX, 64MOV SI, OFFSET HZDOTht0BG1:CLICALL DELAY1CALL DISPSTIADD SI,2 ;跳到下一个CMP CX,7;看CX的值有没有改变JNZ AA1;如果改变就说明发生过中断,就跳回AA1进行判断DEC AX;如果没有改变就继续执行死循环JZ BG0JMP BG1N1:CMP CX,6JNZ N2 BG2:MOV AX, 128MOV SI, OFFSET HZDOTht1BG3:CLICALL DELAY1 CALL DISPSTIADD SI, 2CMP CX,6;看CX的值有没有改变JNZ AA1;如果改变就说明发生过中断,就跳回AA1进行判断DEC AX;如果没有改变就继续执行死循环JZ BG2JMP BG3N2:CMP CX,5JNZ AA1 BG4:MOV AX, 128MOV SI, OFFSET HZDOTht2BG5:CLICALL DELAY1 CALL DISPSTIADD SI, 2CMP CX,5;看CX的值有没有改变JNZ AA1;如果改变就说明发生过中断,就跳回AA1进行判断DEC AX;如果没有改变就继续执行死循环JZ BG4JMP BG5MIR7:STI;允许中断CALL DELAYMOV CX,7MOV AX, 0137HINT 10H;显示字符7MOV AX, 0120HINT 10HMOV AL, 20HOUT 20H, AL;中断结束命令IRETMIR6:STI;允许中断CALL DELAYMOV CX,6MOV AX, 0136HINT 10H;显示字符6MOV AX, 0120HINT 10HMOV AL, 20HOUT 20H, AL;中断结束命令IRETSIR1:STICALL DELAYMOV CX,5MOV AX, 0153HINT 10H;显示字符SMOV AX, 0131HINT 10H;显示字符1MOV AX, 0120HINT 10HMOV AL, 20HOUT 0A0H, ALOUT 20H, ALIRET;======显示汉字子程序======;入口参数: SI = 存放汉字起始地址DISP:PUSH CXMOV CX, 000FHPUSH AXML0:PUSH CXMOV BL, 01HMOV CX, 0008HML1:MOV DX, ROW1;控制0--7行MOV AL, 00HOUT DX, ALMOV AL, [SI]NOT ALMOV DX, COL1;0--7列OUT DX, ALINC SIMOV AL, [SI]NOT ALMOV DX, COL2;8--15列OUT DX, ALINC SIMOV DX, ROW1;控制0--7行MOV AL, BLOUT DX, ALROL BL, 1CALL DELAY1LOOP ML1MOV DX, ROW1MOV AL, 00HOUT DX, ALMOV CX, 0008HML2:MOV DX, ROW2;控制8--15行MOV AL, 00HOUT DX, ALMOV AL, [SI]NOT ALMOV DX, COL1;0--7列OUT DX, ALINC SIMOV AL, [SI]NOT ALMOV DX, COL2;8--15列OUT DX, ALINC SIMOV DX, ROW2;控制8--15行MOV AL, BLOUT DX, ALROL BL, 1CALL DELAY1LOOP ML2MOV DX, ROW2MOV AL, 00HOUT DX, ALSUB SI, 32POP CXLOOP ML0POP AXPOP CXRET;*************************DELAY1:PUSH CX;延时子程序MOV CX, 0100HDL1:PUSH AXPOP AXLOOP DL1POP CXRETDELAY:PUSH CXMOV CX, 0F00HAA0:PUSH AXPOP AXLOOP AA0POP CXRETCODEENDSEND START
如果觉得《微机原理与接口技术课程设计——点阵LED交通情报板设计》对你有帮助,请点赞、收藏,并留下你的观点哦!