刚开始学单片机,是个单片机小白,如果有哪里不对的请大家多多指教谢谢!
爆闪灯:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
| ORG 0000H AJMP MAIN ORG 000BH AJMP TIMER0 MAIN: CLR F0 MOV 30H,#5H MOV TH0,#3CH MOV TL0,#0B0H MOV IE,#82H SETB TR0 SJMP $ TIMER0: MOV TH0,#3CH MOV TL0,#0B0H DJNZ 30H,T001 CPL F0 MOV 30H,#5H T001: JB F0,T002 CPL P1.0 CLR P1.1 CPL P1.2 CLR P1.3 SJMP T0_EX T002: CLR P1.0 CPL P1.1 CLR P1.2 CPL P1.3 T0_EX: RETI
|
流水灯
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
| ORG 000H MOV R0,#0AH MOV A,#0FEH MOV P1,A AJMP MAIN ORG 000BH AJMP TIMERO MAIN: MOV TMOD,#10H MOV TL0,#0B0H MOV TH0,#3CH MOV R0,#0AH MOV IE,#82H SETB TR0 SJMP $ TIMERO: MOV TL0,#0B0H MOV TH0,#3CH DJNZ R0,T0_EX RL A MOV P1,A MOV R0,#0AH T0_EX:RETI
|
最后放一个老师写的流水灯(我稍微改了下参数)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
| ORG 0000H AJMP MAIN ORG 000BH AJMP TIMER0 MAIN: MOV P1,#0FEH CLR F0 MOV 30H,#10H MOV 31H,#0FDH MOV 32H,#10H MOV TMOD,#01H MOV TH0,#3CH MOV TL0,#0B0H MOV IE,#82H SETB TR0 SJMP $ TIMER0: MOV TH0,#3CH MOV TL0,#0B0H DJNZ 32H,T0_EX MOV 32H,#10H DJNZ 30H,T001 CPL F0 MOV 30H,#15 T001: MOV A,31H JB F0,T002 RL A SJMP T003 T002: RR A T003: MOV 31H,A MOV P1,A T0_EX: RETI
|
返回