新闻  |   论坛  |   博客  |   在线研讨会
张明峰书例子8-2
chen3bing | 2024-05-16 14:39:47    阅读:30   发布文章

代码

#include<p16f877.inc>

	cblock 0x20
txBuff	:8
txPtr
txCount
	endc
w_temp 		equ 0x30
status_temp	equ 0x31
pch_temp	equ 0x32
fsr_temp	equ	0x33
count1		equ 0x34
count2		equ 0x35

	org 0x000
	goto	main
	
	org 0x004
	movwf	w_temp
	movf	STATUS,W
	CLRF	STATUS
	MOVWF	status_temp
	movf	PCLATH,W
	MOVWF	pch_temp
	movf	FSR,W
	MOVWF	fsr_temp
	clrf	PCLATH

	BSF		STATUS,RP0
	BTFSS	PIE1,TXIE
	GOTO	EndOfInt
	bcf		STATUS,RP0
	BTFSS	PIR1,TXIF
	GOTO	EndOfInt
	
	MOVLW	txBuff
	movwf	FSR
	MOVF	txPtr,w
	addwf	FSR,f
	movf	INDF,W
	MOVWF	TXREG
	INCF	txPtr,f
	decfsz	txCount,f
	goto	EndOfInt
	bsf		STATUS,RP0
	BCF		PIE1,TXIE
	BCF		STATUS,RP0
	GOTO	EndOfInt	

EndOfInt
	;bcf		STATUS,RP0
	clrf	STATUS
	MOVF	fsr_temp,w
	movwf	FSR
	MOVF	pch_temp,w
	movwf	PCLATH
	MOVF	status_temp,w
	movwf	STATUS
	SWAPF	w_temp,f
	SWAPF	w_temp,w
	RETFIE

	org 0x0100
main
	banksel	TXSTA
	MOVLW	B'00100100'
	MOVWF	TXSTA
	MOVLW	.25
	MOVWF	SPBRG
	CLRF	PIE1
	CLRF	STATUS
	CLRF	txCount
	movlw	b'10000000'
	movwf	RCSTA
	CLRF	INTCON
	BSF		INTCON,PEIE
	BSF		INTCON,GIE
Loop
	call 	Send_Data
	;call	senddata
	call	delay
	goto	Loop

Send_Data
	clrf	STATUS
	MOVF	txCount,w
	skpz
	return
	
	movlw	'1'
	movwf 	txBuff+0
	movlw	'2'
	movwf 	txBuff+1
	movlw	'3'
	movwf 	txBuff+2
	movlw	'4'
	movwf 	txBuff+3
	movlw	0x0d
	movwf 	txBuff+4
	movlw	0x0a
	movwf 	txBuff+5
	movlw	.6
	movwf	txCount
	clrf	txPtr
	bsf		STATUS,RP0
	BSF		PIE1,TXIE
	BCF		STATUS,RP0
	RETURN

senddata
	movlw	0x55
	MOVWF	TXREG
	call delay
	;movlw	0x0d
	;MOVWF	TXREG
	;call delay
	;movlw	0x0a
	;MOVWF	TXREG
	;call delay
	return

delay
	clrf	count1
	clrf	count2
	decfsz	count2,f
	goto	$-1
	decfsz	count1,f
	goto	$-3
	return

END
	

用proteus仿真


1710053071881.jpg

*博客内容为网友个人发布,仅代表博主个人观点,如有侵权请联系工作人员删除。

参与讨论
登录后参与讨论
1
最近文章
方波振荡电路
2024-09-14 14:59:39
6V3A电路
2024-09-14 14:18:10
推荐文章
最近访客