Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

UART configuration help for PIC16F877A

Status
Not open for further replies.

sora5563

Newbie level 5
Joined
Dec 13, 2006
Messages
10
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,402
pic16f877a hyperterminal

I recently try to send data to and from PIC16F877A via uart and the result show
in the hyperterminal, but there is the problem that nothing comes out
at the hyperterminal.

here is my source code,
--------------------------------------------
LIST P=16F877A
#INCLUDE <P16F877A.inc>
__CONFIG 0x3F32

SCRATCH EQU 0x20
TMP EQU 0x21

ORG 0x200
GOTO START

ORG 0x204
GOTO START

ORG 0x205

START:
; turn off the comparater for portA
BANKSEL CMCON
MOVLW 0x07
MOVWF CMCON

;turn off the voltage reference module
BANKSEL CVRCON
MOVLW 0x00
MOVWF CVRCON

CALL UART_INIT

AGAIN:
MOVLW BANNER-1
CALL WRITE
CALL UART_GETCHAR
CALL UART_PUTCHAR
GOTO AGAIN

;------------------------------------
; UART ROUTINE
;------------------------------------
UART_INIT:
BANKSEL SPBRG
MOVLW D'129' ;set baud rate 9600
MOVWF SPBRG
MOVLW 0x20 ;transmitter enabled
MOVWF TXSTA
BCF PIE1, TXIE
BCF PIE1, RCIE
BANKSEL RCSTA
MOVLW 0x90
MOVWF RCSTA
RETURN

UART_PUTCHAR:

CHARWAIT1:
BTFSS PIR1, TXIF
GOTO CHARWAIT1
MOVWF TXREG
RETURN

UART_GETCHAR:

CHARWAIT2:
BTFSS PIR1, RCIF
GOTO CHARWAIT2
MOVWF RCREG
RETURN

;----------------------------------
;TEXT FOR USER INTERFACE
;----------------------------------
BANNER:
DT "\n\rHow are you?\n\r",0h

;----------------------------------
;WRITE A STRING TO UART
;----------------------------------

WRITE:
MOVWF SCRATCH
GoWrite:
CALL PCLsub
ADDLW 0h ; IF CONTENTS IS ZERO, Z WILL BE SET
BTFSC STATUS,Z
RETURN
CALL UART_PUTCHAR
GOTO GoWrite

;-----------------------------------
;PCLsub USED FOR INDIRECT ADDRESSING
;-----------------------------------

PCLsub:
INCF SCRATCH,F
MOVF SCRATCH,W
MOVWF PCL
RETURN

END

-------------------------------------------------------------
Can anyone tells me what is going wrong. the baud rate is 9600 for hyperterminal.
 

uart pic16f877

Hi sora5563,
Best way to debug is to start with only transmission.
Just write the code for continuously transmitting a known character on
UART. You should see the character appearing on hyperterminal.
That verifies that UART is transmitting and also settings in hyperterminal are correct. Next try only reception in a similar fashion.
Later you can integrate both in order to complete your application.

Regards,
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top