1 / 13

讨论题 3 、 4

讨论题 3 、 4. 1. 请编写程序,要求每按一次键,发光二极管位置右移 1 次。 ORG 0000H LJMP MAIN ORG 0013H LJMP ZH ORG 0100H MAIN: MOV SP, #50H SETB IT1 ; 外部中断 1 SETB EA ;CPU 开中断. SETB EX1 MOV A, #07FH

mliss
Download Presentation

讨论题 3 、 4

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. 讨论题3、4

  2. 1. 请编写程序,要求每按一次键,发光二极管位置右移1次。 ORG 0000H LJMP MAIN ORG 0013H LJMP ZH ORG 0100H MAIN: MOV SP, #50H SETB IT1 ;外部中断1 SETB EA ;CPU开中断

  3. SETB EX1 MOV A, #07FH LP: MOV P1, A ;输出 JB P3.3, ZH SJMP LP ZH: RR A MOV P1, A LCALL DEL RETI DEL: MOV R5, #20 D1: MOV R6, #20 D2: MOV R7, #250 DJNZ R7, $ DJNZ R6, D2 DJNZ R5, D1 RET END

  4. 2. 请编写程序,每按一次按键流水灯的流动方向改变一次,要求使用中断技术处理按键。 ORG 0000H ;定义下一条指令的地址LJMP MAIN ;转向主程序ORG 0013H ;安排外部中断1处理程 序的第一条指令LJMP KEYS ;直接转移到中断处理程序ORG 0100H ;主程序起点MAIN: MOV SP,#40H ;设置堆栈栈底指针SETB IT1 ;设置外部中断1的中断方式 为下降沿中断SETB EX1 ;开放外部中断1 SETB EA ;开放总中断MOV A, #01H ;#01H送累加器A

  5. L1: MOV P2, A ;累加器A中内容送P2口MOV R7, #0FFH ;#0FFH送R7寄存器L3: MOV R6, #0FFH ;#0FFH送R6寄存器L2: DJNZ R6, L2 ;R6寄存内容-1,结果≠0转移至L2 DJNZ R7, L3 ;R7寄存内容-1,结果≠0转移至L3 JNB FX, L4 ;FX=0时转移到L4 RL A ;累加器A中内容左移一位SJMP L5 ;转移至L5L4: RR A ;累加器A中内容右移一位L5: SJMP L1 ;转移至L1

  6. ;按键中断程序;入口:外部中断1;功能:确认按键后改变方向标志FX的状态KEYS: ;中断处理程序入口MOV R7,#20H ;首先延时去抖K1: MOV R6, #0FFH DJNZ R6, $ DJNZ R7,K1 JB KEY, K2 ;延时完成后再检测按键CPL FX ;确认按键按下,改变方向标志位状态

  7. K2: RETI ;中断结束返回KEY BIT P3.3 ;定义按键变量FX BIT 00H ;定义位变量,用于判断方向END ;结束

  8. 设计一个数码管显示电路,要求数码管以闪光方式轮流显示0~F共16个字符,闪光频率为2Hz,每个字符显示1s。ORG 0000H LJMP MAIN ;跳转到主程序入口ORG 000BH ;定时计数器0中断入口LJMP CTC0 ;跳转到定时计数器0中断程序ORG 0100HMAIN: MOV TMOD,#01H ;设定定时计数器0为工作方式1 MOV TH0,#CTH ;设置计数器初值MOV TL0,#CTL

  9. SETB TR0 ;启动定时计数器0 SETB ET0 ;开定时计数器0中断SETB EA ;开总中断SETB SBZ ;设置定时标志MOV S1,#0 MOV XSS,#0 MOV MS250,#0PROG1: MOV DPTR,#ZXB ;数据指针指向字 形表首地址WAIT: JBC SBZ, PROG2 SJMP WAIT

  10. PROG2: CPL SGBZ JB SGBZ,PROG3 MOV A,#00H SJMP PROG6PROG3: MOV A,XSBUFPROG6: MOV P1,A INC S1 MOV A, S1 CJNE A, #4, WAIT MOV S1,#0

  11. INC XSS MOV A, XSS CJNE A, #10, PROG5 MOV XSS, #0 MOV A,#0 PROG5: MOVC A, @A+DPTR MOV XSBUF, A PROG4: SJMP WAIT00H END

  12. ;以下为定时计数器0中断程序,中断每50mS产生一次CTC0: PUSH ACC ;保护现场MOV TH0, #CTH ;恢复计数器初值MOV TL0, #CTL INC MS250 ;中断次数累计MOV A, MS250 ;判断是否已中断5次,未到5次中断返回CJNE A, #5, CTC1 MOV MS250, #0;已到5次,计数器清0 SETB SBZ ;设置250mS计时标志CTC1: POP ACC ;恢复现场RETI ;中断返回

  13. ;以下为数据设置 MS250 DATA 30H ;250mS秒计数器S1 DATA 31H ; 1秒计数器XSBUF DATA 32H ; 存放显示字型码XSS DATA 33H ;存放显示数字SBZ BIT 00H ; 250mS时间标志SGBZ BIT 01H ;闪光标志CTH EQU 15536 / 256 ;定时计数器0初值高位CTL EQU 15536 MOD 256 ;定时计数器0初值低位ZXB: DB 0C0H,0F9H,0A4H,0B0H,99H,92H,82H,0F8H DB 80H,90H,88H,83H,0C6H,0A1H,86H,8EH END ;程序结束

More Related