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 Bài Trong Ngày 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 13-11-2007, 12:01 PM   #1
dvkkt
Đệ tử 3 túi
 
dvkkt's Avatar
 
Tham gia ngày: Oct 2007
Nơi Cư Ngụ: TPHCM
Bài gửi: 55
:
Send a message via Yahoo to dvkkt
Làm sao chỉnh đoạn code chạy trên 16f84a sang con 16f877a

tui có chỉnh chổ:
cblock 0x0c -> 0x20
cblock 0x1d -> 0x31
--------------------
movlw 0x0c ->0x20
movlw pic_ad
bác nào biết có thể giải thích rõ hơn vì sao nó không chạy? thank
Code:
<script type="text/javascript">
processor 16f84A 			;********************* mod 16f877a
include <p16f84A.inc> 		;********************* mod 16f877a
__config _XT_OSC & _WDT_OFF & _PWRTE_ON & _CP_OFF  ; them & _LVP_OFF de dung chan RB3                    

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; for PIC to LCD pin wiring and LCD line addresses
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
#define E_line 1
#define RS_line 2
#define RW_line 3
#define LCD_1 0x80
#define LCD_2 0xC0
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; variables in PIC RAM
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Reserve 16 bytes for string buffer
cblock 0x0c			 ;@@@@@@@@@ mod cho nay 0x20 **************
	strData
endc
; Leave 16 bytes and continue with local variables
cblock 0x1d 		;@@@@@@@@ mod cho nay 0x31 ****************
	count1
	count2
	count3
	pic_ad
	J
	K
	index
endc
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Program
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
	org 	0
	goto 	main
	org		0x04
main:
	movlw	b'00000000'
	tris	PORTA
	tris	PORTB
	movlw	b'00000000'
	movwf	PORTA
	movwf	PORTB
; Wait and initialize LCD
	call	delay_5ms
	call	initLCD
	call	delay_5ms
; Store base address of text buffer in PIC RAM	
	movlw	0x0c 	;@@@@@@@@@@ mod cho nay 0x20 **************
	movwf 	pic_ad
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; first LCD line
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
	call 	blank16
	movlw	d'1'
	call	storeMN
; Set DDRAM address to start of first line
	call	line1
; Call procedure to display 16 character in LCD
	call 	display16
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; second LCD line
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
	call	delay_125mcs
	call 	blank16
; in text buffer
	movlw	d'1'
	call 	storeUniv
	call	line2
	call	display16
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
loopHere:
	goto	loopHere 
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; INITIALIZE LCD PROCEDURE
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
initLCD:
; Initialization for densitron LCD module as follows:
;	8-bit interface
;	2 display lines of 16 characters each
;	cursor shift right
;	no display shift
;***************************
;	COMMAND MODE
;***************************
	bcf		PORTA, E_line
	bcf		PORTA, RS_line
	bcf		PORTA, RW_line
	call	delay_125mcs
;***************************
;	FUNCTION SET
;***************************
	movlw	0x38
	movwf	PORTB
	call 	pulseE
;***************************
;	DISPLAY OFF
;***************************
	movlw 	0x08
	movwf	PORTB
	call	pulseE
;***************************
;	DISPLAY AND CURSOR ON
;***************************
	movlw	0x0f
	movwf	PORTB
	call 	pulseE
;***************************
;	ENTRY MODE SET	
;***************************
	movlw	0x06
	movwf	PORTB
	call 	pulseE
;***************************
;	CURSOR/DISPLAY SHIFT	
;***************************
	movlw	b'00010100'
	movwf	PORTB
	call 	pulseE
	
;***************************
;	CLEAR DISPLAY
;***************************
	movlw	0x01
	movwf	PORTB
	call	pulseE
	call	delay_5ms
	return
;***************************
;	DELAY AND PULSE PROCEDURES
;***************************
;***************************
; Procedure to delay 125 microseconds
;***************************
delay_125mcs:
	movlw	D'42'
	movwf	count1
	repeat
		decfsz	count1,f
		goto	repeat
		return
;***************************
; Procedure to delay 5 milliseconds
;***************************
delay_5ms
	movlw	D'41'
	movwf	count2
	delay	
		call	delay_125mcs
		decfsz	count2,f
		goto	delay
		return
;============================
; Pulse E line
;============================
pulseE	
	 
	bsf		PORTA, E_line
	bcf		PORTA, E_line
 	call	delay_125mcs
	return
;============================
; long delay sub-routine
;============================
long_delay
	movlw	d'200'
	movwf	J
jloop:
	movwf	K
kloop:
	decfsz	K,f
	goto 	kloop
	decfsz	J,f
	goto	jloop
	return
;============================
; LCD display procedure
;============================
display16:
	 
;set up for data
	bcf		PORTA,E_line
	bsf		PORTA,RS_line
	call	delay_125mcs
;set up counter for 16 characters
	movlw	d'16'
	movwf	count3
;get display address from local variable pic_ad
	movf	pic_ad,w
	movwf	FSR
getchar:
	 
	movf	INDF,w
	movwf	PORTB
	call	pulseE
	decfsz	count3,f
	goto	nextchar
	return
nextchar:	
	incf	FSR,f
	goto	getchar
; blank buffer
blank16:
	movlw	d'16'
	movwf	count1
	movf	pic_ad,w
	movwf	FSR			; ad
	movlw	0x20
storeit:
	movwf	INDF
	decfsz	count1,f
	goto	incfsr
	return
incfsr:
	incf	FSR,f
	goto	storeit

;============================
; Set Address register to 
;	LCD line 1
;============================
line1:
	 
	bcf		PORTA,E_line
	bcf		PORTA,RS_line
	
	call	delay_125mcs
; set to second display line
	movlw	LCD_1
	 
	movwf	PORTB
	call	pulseE
; set RS line for data
	bsf		PORTA,RS_line
	call	delay_125mcs
	return
;============================
; Set Address register to 
;	LCD line 2
;============================
line2:
	bcf		PORTA,E_line
	bcf		PORTA,RS_line
	call	delay_125mcs
	movlw	LCD_2
	movwf	PORTB
	call	pulseE
	bsf		PORTA,RS_line
	call	delay_125mcs
	return
;============================
; first text string procedure
;============================
storeMN:	
	movwf	index
	movf	pic_ad,w
	addwf	index,w
	movwf	FSR
	movlw 	0
	movwf	index
get_msg_char:
	call	msg1
	andlw	0x0ff
	btfsc	STATUS,Z
	goto	endstr1
	movwf	INDF
	incf	FSR,f
	movf	index,w
	addlw	1
	movwf	index
	goto	get_msg_char
endstr1:
	return

msg1:
		addwf	PCL,f
		retlw	'P'
		retlw	'I'
		retlw	'C'
		retlw	0x20
		retlw	'P'
		retlw	'r'
		retlw	'o'
		retlw	'g'
		retlw	'r'
		retlw	'a'
		retlw	'm'
		retlw	'm'
		retlw	'i'
		retlw	'g'
		retlw	0
;============================
;	second text string procedure
;============================
storeUniv:
	movwf	index
	movf	pic_ad,0
	addwf	index,0
	movwf	FSR
	movlw	0
	movwf	index
get_msg_char2:
	call	msg2
	andlw	0x0ff
	btfsc	STATUS,Z
	goto	endstr2
	movwf	INDF
	incf	FSR,f
	movf	index,w
	addlw	1
	movwf	index
	goto	get_msg_char2
endstr2:	
	return
msg2:
	addwf	PCL,f
	retlw	'V'
	retlw	'i'
	retlw	'd'
	retlw	'u'
	retlw	0
end
</script>
File Kèm Theo
File Type: txt LCDtest1.txt (6.4 KB, 10 lần tải)
dvkkt vẫn chưa có mặt trong diễn đàn   Trả Lời Với Trích Dẫn
 


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à 08:23 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