Chào các bạn! Hôm nay chip chia sẻ một số code chip lập trình kết hợp với phím bấm đơn, viết theo cách đơn giản dễ hiểu, mọi thắc mắc các bạn chém gió phía dưới nhé..^^
1. Phím + Led đơn: Bấm phím nào led hiển thị nút đó.
ORG 00H; Designer By ChipKool
MAIN:
MOV P2,#00000000B
KEY1:
JNB P1.4,KEY1OK
CLR P2.0
CALL DELAY
JMP KEY2
KEY1OK:
SETB P2.0
CALL DELAY
KEY2:
JNB P1.5,KEY2OK
CLR P2.1
CALL DELAY
JMP KEY3
KEY2OK:
SETB P2.1
CALL DELAY
KEY3:
JNB P1.6,KEY3OK
CLR P2.2
CALL DELAY
JMP KEY4
KEY3OK:
SETB P2.2
CALL DELAY
KEY4:
JNB P1.7,KEY4OK
CLR P2.3
CALL DELAY
JMP KEY1
KEY4OK:
SETB P2.3
CALL DELAY
JMP KEY1
JMP MAIN
DELAY:
MOV R0,#200
LOOP:
MOV R1,#150
LOOP1:
DJNZ R1,LOOP1
DJNZ R2,LOOP
RET
END
2.Phím + 7 đoạn : Bấm nút tăng dần từ 0 - 9
ORG 00H; Designer By ChipKool
MAIN:
KEY0:
JNB P1.7,KEY0OK
JMP KEY1
KEY0OK:
CALL CTHT
INC R0
KEY1:
JNB P1.6,KEY1OK
JMP KEY0
KEY1OK:
CALL CTHT
DEC R0
JMP KEY0
JMP MAIN
CTHT:
MOV R7,#5
QUET:
MOV A,R0
MOV B,#10
DIV AB
MOV DPTR,#MALED
MOVC A,@A+DPTR
MOV P3,A
CALL DELAY
MOV A,B
MOVC A,@A+DPTR
MOV P2,A
CALL DELAY
DJNZ R7,QUET
RET
MALED:DB 0C0H,0F9H,0A4H,0B0H,99H,92H,82H,0F8H,80H,90H
DELAY:
MOV R2,#150
LOOP:
MOV R1,#200
LOOP1:
DJNZ R1,LOOP1
DJNZ R2,LOOP
RET
END
3. Phím + Động cơ
ORG 0000H; Designer By ChipKool
MAIN:
JNB P1.0,THUAN_R
JNB P1.1,NGHICH_R
JNB P1.2,THUAN_H
JNB P1.3,NGHICH_H
JNB P1.4,STOP
JMP MAIN
THUAN_R:
SETB P3.0
CLR P3.1
JMP MAIN
NGHICH_R:
CLR P3.0
SETB P3.1
JMP MAIN
THUAN_H:
SETB P3.2
CLR P3.3
JMP MAIN
NGHICH_H:
CLR P3.2
SETB P3.3
JMP MAIN
STOP:
CLR P3.0
CLR P3.1
CLR P3.2
CLR P3.3
JMP MAIN
CALL DELAY
DELAY:
MOV R0,#200
LOOP:
MOV R1,#250
LOOP1:
NOP
DJNZ R1,LOOP1
DJNZ R0,LOOP
RET
END
4. Phím + LCD
5. Phím + 74HC151
1. Phím + Led đơn: Bấm phím nào led hiển thị nút đó.
ORG 00H; Designer By ChipKool
MAIN:
MOV P2,#00000000B
KEY1:
JNB P1.4,KEY1OK
CLR P2.0
CALL DELAY
JMP KEY2
KEY1OK:
SETB P2.0
CALL DELAY
KEY2:
JNB P1.5,KEY2OK
CLR P2.1
CALL DELAY
JMP KEY3
KEY2OK:
SETB P2.1
CALL DELAY
KEY3:
JNB P1.6,KEY3OK
CLR P2.2
CALL DELAY
JMP KEY4
KEY3OK:
SETB P2.2
CALL DELAY
KEY4:
JNB P1.7,KEY4OK
CLR P2.3
CALL DELAY
JMP KEY1
KEY4OK:
SETB P2.3
CALL DELAY
JMP KEY1
JMP MAIN
DELAY:
MOV R0,#200
LOOP:
MOV R1,#150
LOOP1:
DJNZ R1,LOOP1
DJNZ R2,LOOP
RET
END
2.Phím + 7 đoạn : Bấm nút tăng dần từ 0 - 9
ORG 00H; Designer By ChipKool
MAIN:
KEY0:
JNB P1.7,KEY0OK
JMP KEY1
KEY0OK:
CALL CTHT
INC R0
KEY1:
JNB P1.6,KEY1OK
JMP KEY0
KEY1OK:
CALL CTHT
DEC R0
JMP KEY0
JMP MAIN
CTHT:
MOV R7,#5
QUET:
MOV A,R0
MOV B,#10
DIV AB
MOV DPTR,#MALED
MOVC A,@A+DPTR
MOV P3,A
CALL DELAY
MOV A,B
MOVC A,@A+DPTR
MOV P2,A
CALL DELAY
DJNZ R7,QUET
RET
MALED:DB 0C0H,0F9H,0A4H,0B0H,99H,92H,82H,0F8H,80H,90H
DELAY:
MOV R2,#150
LOOP:
MOV R1,#200
LOOP1:
DJNZ R1,LOOP1
DJNZ R2,LOOP
RET
END
ORG 0000H; Designer By ChipKool
MAIN:
JNB P1.0,THUAN_R
JNB P1.1,NGHICH_R
JNB P1.2,THUAN_H
JNB P1.3,NGHICH_H
JNB P1.4,STOP
JMP MAIN
THUAN_R:
SETB P3.0
CLR P3.1
JMP MAIN
NGHICH_R:
CLR P3.0
SETB P3.1
JMP MAIN
THUAN_H:
SETB P3.2
CLR P3.3
JMP MAIN
NGHICH_H:
CLR P3.2
SETB P3.3
JMP MAIN
STOP:
CLR P3.0
CLR P3.1
CLR P3.2
CLR P3.3
JMP MAIN
CALL DELAY
DELAY:
MOV R0,#200
LOOP:
MOV R1,#250
LOOP1:
NOP
DJNZ R1,LOOP1
DJNZ R0,LOOP
RET
END
4. Phím + LCD
5. Phím + 74HC151
Đăng nhận xét