PIC Vietnam

Go Back   PIC Vietnam > Microchip PIC > MPASM

Tài trợ cho PIC Vietnam
Trang chủ Đăng Kí Hỏi/Ðáp Thành Viên Lịch Tìm Kiếm Bài Trong Ngày Ðánh Dấu Ðã Ðọc Vi điều khiển

MPASM Lập trình bằng hợp ngữ là một việc làm vô cùng vất vả, tuy nhiên, để hiểu và làm việc với vi điều khiển, hợp ngữ trở thành một công cụ khá đắc lực ...

 
 
Ðiều Chỉnh Xếp Bài
Prev Previous Post   Next Post Next
Old 12-06-2007, 12:53 PM   #1
phamthanhkhuyen
Đệ tử 1 túi
 
Tham gia ngày: Nov 2006
Bài gửi: 25
:
KEYPAD nhờ giúp đở....

dưới đây là trích trong Tutorial 9.1 - Nigel Goodwin 2003
tôi ghi chú lại nhưng tôi thấy trong đoạn Chk_Keys ở dòng lệnh thứ 6 hình như viết sai thì phải mong các bạn chỉ giúp

Code:
;KEYPAD16
;trich trong Tutorial 9.1 - Nigel Goodwin 2003
;Keypad reading with LCD display
;chu thich lai boi PHAM THANH KHUYEN
;ngay 11/06/2207
		LIST	p=16F628A			;tell assembler what chip we are using
		include "P16F628A.inc"		;include the deFaults For the chip
		ERRORLEVEL	0,	-302		;suppress bank selection messages
		__conFig 0x3D18				;sets the conFiguration settings (oscillator type etc.)
;...................................................................
		cblock	0x20				;start oF general purpose registers
;cac bien cua Delay
count1			;used in delay routine
counta			;used in delay routine
countb			;used in delay routine

;cac bien cua Keypad

key
rows
	
		endc
;.................................................................
KEY_PORT	Equ	PORTB			;keypad port
KEY_TRIS		Equ	TRISB
Col1		Equ	0			;pins used For keypad inputs
Col2		Equ	1
Col3		Equ	2
Col4		Equ	3
;.....................................................................
;GHI CHU : sau khi thuc hien xong doan chuong trinh Chk_Keys
;ta duoc gia tri cua phim nhan nam o trong W va trong bien Key
;Keypad subroutine

Chk_Keys			movlw	0x00			;wait until no key pressed (doi cho den khi  khong co phim nhan)
			movwF	KEY_PORT		;set all output pins low	out out out out in in in in = 0000 xxxx
			movF	KEY_PORT,	W	;read port B
			andlw	0x0F			;mask oFF high byte	(che 4 bit cua byte cao)
			sublw	0x0F

		; ??????????????????????????????????????
			btFsc	STATUS, Z		;test iF any key pressed
		;thay bang	BTFSS	STATUS,Z	     ????

			goto	Keys			;iF none, read keys	
			call	Delay20			;
			goto	Chk_Keys		;else try again
;Cac chan cua port Keypad
;			out	out	out	out	in	in	in	in	
;			col1	col2	col3	col4	row1	row2	row3	row4
;			RB7	RB6	RB5	RB4	RB3	RB2	RB1	RB0

Keys	  		call    Scan_Keys
            			movlw   .16			;check For no key pressed	16
            			subwF   key, w		;neu Key=.16 co nghia la khong co phim nao nhan
           			btFss   STATUS, Z
           			 goto    Key_Found		;Key <>.16
			call	Delay20
			goto	Keys
Key_Found  	 	movF    key, w
			andlw	0x0F
			call	Key_Table		;lookup key in table	
			movwF	key		;save back in key
			return			;key pressed now in W
;.................................................................
Scan_Keys  		clrF    key
			movlw	0xF0		;set all output lines high
           			movwF   KEY_PORT		;11110000
           			movlw   .4			;
           			movwF   rows		;set number oF rows
           			bcF     STATUS, C		;put a 0 into carry

Scan	rrF     KEY_PORT, F				;0111xxxx	1011xxxx	1101xxxx	1110xxxx
           	bsF     STATUS, C		;Follow the zero with ones		
;comment out next two lines For 4x3 numeric keypad.			
           	btFss   KEY_PORT, Col4       ;Col4 equ 3	cccc1xxx
           	goto    Press		;	             cccc0xxx	
           	incF    key, F		;		
           	btFss   KEY_PORT, Col3	;Col3 equ 2	ccccx1xx	
           	goto    Press		;	             ccccx0xx	
           	incF    key, F		;		
           	btFss   KEY_PORT, Col2	;Col2 equ 1	ccccxx1x
           	goto    Press		;	             ccccxx0x
           	incF    key, F		;
           	btFss   KEY_PORT, Col1	;Col1 equ 0           ccccxxx1
          	goto    Press		;	              ccccxxx0
           	incF    key, F		;
           	decFsz  rows, F		;
           	goto    Scan		;
Press	  	return
;khi ket thuc Scan_Keys ta duov 1 gia tri cua Key
;end oF keypad subroutines.
;....................................................................
Key_Table  	ADDWF   PCL,F
            	RETLW   0x43	;C		col1	col2	col3	col4
            	RETLW   0x42	;B	row4	C	D	E	F				
            	RETLW   0x30	;0	row3	B	9	6	3		
            	RETLW   0x41	;A	row2	0	8	5	2		
            	RETLW   0x44	;D	row1	A	7	4	1
            	RETLW   0x39	;9
            	RETLW   0x38	;8
            	RETLW   0x37	;7
            	RETLW   0x45	;E
            	RETLW   0x36	;6
            	RETLW   0x35	;5
            	RETLW   0x34	;4
            	RETLW   0x46	;F
            	RETLW   0x33	;3
            	RETLW   0x32	;2
            	RETLW   0x31	;1
;....................................................................
;DEYLAY

Delay255	movlw	0xFF			;delay 255 mS
			goto	d0
Delay100	movlw	d'100'			;delay 100mS
			goto	d0
Delay50		movlw	d'50'			;delay 50mS
			goto	d0
Delay20		movlw	d'20'			;delay 20mS
			goto	d0
Delay5		movlw	0x05			;delay 5.000 ms (4 MHz clock)
d0			movwF	count1
d1			movlw	0xC7			;delay 1mS
			movwF	counta
			movlw	0x01
			movwF	countb
Delay_0
			decFsz	counta, F
			goto	$+2
			decFsz	countb, F
			goto	Delay_0

			decFsz	count1	,F
			goto	d1
			retlw	0x00
			end
phamthanhkhuyen vẫn chưa có mặt trong diễn đàn   Trả Lời Với Trích Dẫn
 

Ðiều Chỉnh
Xếp Bài

Quyền Sử Dụng Ở Diễn Ðàn
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is Mở
Smilies đang Mở
[IMG] đang Mở
HTML đang Tắt

Chuyển đến


Múi giờ GMT. Hiện tại là 04:56 AM.


Được sáng lập bởi Đoàn Hiệp
Powered by vBulletin®
Page copy protected against web site content infringement by Copyscape
Copyright © PIC Vietnam