USART code not sending data

Thread Starter

ozirock

Joined Jan 13, 2011
47
Hi guy's,

I was wondering if anyone can see the problem with my code, I had it set up to receive and transmit using code I found on the net, got the receive part working okay but my transmit wasn't so I cut it down to just the transmit part as you can see below

Rich (BB code):
                PROCESSOR PIC16F876
                INCLUDE   <P16F876.inc> 

#define VERSION "=Serial_Com_A===V0.1=="

	__CONFIG        _CP_OFF & _DEBUG_OFF & _LVP_OFF & _WRT_ENABLE_ON & _PWRTE_ON & _WDT_OFF & _BODEN_ON & _XT_OSC

;==========================================================================
;       Variable Definition
;==========================================================================

	CBLOCK 0x20				;Start at H'20'
	TIMER1					;Used in delay routine
	TIMER2					; "	"	"
	DATA_TO_SEND
	ENDC

		ORG	0		;Reset vector address
		GOTO	RESET		;goto RESET routine when boot.



;		*********************************************
;		*  Example of a delay routine               *
;		*********************************************

DELAY_ROUTINE   MOVLW   D'255'         ;54 Generate approx 10mS delay at 4Mhz CLK
                MOVWF   TIMER2
DEL_LOOP1       MOVLW   D'255'	       ;60	
                MOVWF   TIMER1
DEL_LOOP2       DECFSZ  TIMER1,F
                GOTO    DEL_LOOP2
                DECFSZ  TIMER2,F
                GOTO    DEL_LOOP1
		RETLW   0


; 
; ------------------------------------------------------------- 
; SEND CHARACTER IN W VIA RS232 AND WAIT UNTIL FINISHED SENDING 
; ------------------------------------------------------------- 
; 
send    	movwf 	TXREG             ; send data in W

TransWt 	bsf 	STATUS,RP0          ; RAM PAGE 1 
WtHere  	btfss 	TXSTA,TRMT        ; (1) transmission is complete if hi 
        	goto 	WtHere

        	bcf 	STATUS,RP0          ; RAM PAGE 0 
        	return 



;	       **********************************
;              **  RESET :  main boot routine  **
;              **********************************

RESET		BSF	STATUS,RP0	;Switch to register bank 1
					;Disable pull-ups
					;INT on rising edge
					;TMR0 to CLKOUT
					;TMR0 Incr low2high trans.
					;Prescaler assign to Timer0
					;Prescaler rate is 1:256
							
					
		MOVLW	B'11010111'	;Set PIC options (See datasheet).
		MOVWF	OPTION_REG	;Write the OPTION register.
					;
		CLRF	INTCON		;Disable interrupts
		
		MOVLW	B'10000001'
		MOVWF	TRISC		;bit 0 and 7 are inputs all others are outputs
		
		MOVLW	B'00000000'
		MOVWF	TRISB		;all RB ports are outputs
					
		MOVLW	B'00000000'	;all RA are outputs
		MOVWF	TRISA
		
		movlw  	d'25'  		;	
       		movwf  	SPBRG  		; set Baud rate to9600 @ 4Mhz(crystal)
		
		movlw  	B'00100110'   		;		
       		movwf  	TXSTA  		; enable 8bit data transmission
		
		BCF	STATUS,RP0	;Switch Back to reg. Bank 0
    		
    		movlw  	B'10010000'   		;
		movwf  	RCSTA 		; enable 8bit data reception


main       	movlw 	B'01100001'

		movwf	DATA_TO_SEND

		movf	DATA_TO_SEND,W

		call 	send
		
		call	DELAY_ROUTINE
		
		call	DELAY_ROUTINE
		
		goto	main
		
		
		
;****End of the program**** 		

		END
I'm pretty sure the problem is on the microcontroller side of things rather than the PC but I can't see what's wrong.
 
Top