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.

please help with USART code for p16f873

Status
Not open for further replies.

ahme0307

Member level 1
Joined
May 14, 2009
Messages
40
Helped
2
Reputation
4
Reaction score
2
Trophy points
1,288
Location
Ethiopia
Activity points
1,526
p16f873.inc

i am working my final year project.but i'm having problem.i write assembly code to
display just A using UART,but i am having multiple A s.please any one what is wrong with the code? here is the code
LIST P=16F873
#include "P16F873.INC"
#DEFINE BANK0 BCF STATUS,5
#DEFINE BANK1 BSF STATUS,5

;PORT INITIALIZATION
BCF STATUS,6

BANK0
CLRF PORTC

BANK1
BSF TRISC,7
BCF TRISC,6
START
;SERIAL INITIALIZATION
BSF TXSTA,4
BCF TXSTA,7
BSF TXSTA,5
;NEW
BCF TXSTA,6


BANK0
BSF RCSTA,7
BCF RCSTA,4
BCF RCSTA,5

MOVLW d'65'
MOVWF TXREG
BANK1
WAIT BTFSS TXSTA,1
GOTO WAIT
BANK0
GOTO START
END
 

include p16f873.inc

Your code runs to the end then starts again! It has no end point so keeps repeating.
You could make the init and transmit into subroutines and have an end point in the code.
I cant see where you write to the SPBRG register to set baud rate unless this is synchronous mode.

Something like this:



Code:
LIST P=16F873 
#include "P16F873.INC" 
#DEFINE BANK0 BCF STATUS,5 
#DEFINE BANK1 BSF STATUS,5 

;PORT INITIALIZATION 
		BCF 	STATUS,6 
		BANK0 
		CLRF    PORTC 
		call	INIT_UART
 
START 	
		BANK0 
		MOVLW 	d'65'
		call	TRANSMIT

DONE
		GOTO 	DONE  

;--- SERIAL INITIALIZATION 

INIT_UART
		BANK1 
		BSF 	TRISC,7 
		BCF 	TRISC,6

		BSF 	TXSTA,4     ;This bit should be clear for asynchronous mode
		BCF 	TXSTA,7 
		BSF 	TXSTA,5  
		BCF 	TXSTA,6 

		BANK0 
		BSF 	RCSTA,7 
		BCF 	RCSTA,4 
		BCF 	RCSTA,5 
		return 

;--- Transmit char

TRANSMIT 		
		MOVWF 	TXREG 
		BANK1 
WAIT 	BTFSS 	TXSTA,1 
		GOTO 	WAIT 
		return
		
		END
 

p16f873.inc

Thanks for your response.i have modified the code to the following.
LIST P=16F873
#include "P16F873.INC"
#DEFINE BANK0 BCF STATUS,5
#DEFINE BANK1 BSF STATUS,5

;PORT INITIALIZATION
BCF STATUS,6

BANK0
CLRF PORTC
CLRF PORTA
BSF RCSTA,7 ; ENABLE SERIAL PORT

BANK1
BSF TRISC,7
BCF TRISC,6
;BSF TRISA,3

;==================SERIAL INITIALIZATION===================================
BSF TXSTA,2 ; HIGH BAUD RATE
MOVLW 81H
MOVWF SPBRG ; 9600 BAUD RATE
BCF TXSTA,4 ; ASYNCHRONOUS MODE
;BSF TXSTA,5 ; TRANSMIT ENABLE
BCF TXSTA,5 ; TRANSMIT DISABLE

;START
;PRESS BTFSS PORTA,3
; GOTO PRESS
BANK0
MOVLW 41H
MOVWF TXREG ; CHAR 'A'

BANK1
BSF TXSTA,5 ; TRANSMIT ENABLE
WAIT BTFSS TXSTA,1
GOTO WAIT
BCF TXSTA,5 ; TRANSMIT DISABLE

;GOTO START
END

but still am having multiple of character A instead of single A
 

txsta

When the program ends, it just starts again. If you want it to stop, do

Stop goto stop

You need to debounce the button push.
Put a delay of about 50mS in after the button is pressed, then look again after the delay to make sure it is still pressed.
Then wait untill it is released before looking if it has been repressed.

Psuedo code.

Button pressed
Wait 50mS
is Button still pressed?

no, go to start

yes, output char
output char
is button still pressed?
yes, wait for release.
no, go to start.
 

Re: please help

ahme0307 said:
BANK1
BSF TXSTA,5 ; TRANSMIT ENABLE
WAIT BTFSS TXSTA,1
GOTO WAIT
BCF TXSTA,5 ; TRANSMIT DISABLE

GOTO START
END

Instead of GOTO START, make it as below

LOOP

GOTO LOOP

This will transmit one A and then wait doing nothing.

Cheers

Ravi
 

Re: please help

Thank you all.you have solved my problem!!
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top