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.

PIC16F886 EUSART problem on TX

Status
Not open for further replies.

crAsh_

Newbie level 2
Joined
Oct 6, 2012
Messages
2
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,328
Hi all,

I would appreciate if someone familiar with 16F886 could assist me.
Basically i'm trying to transmit data which is just based on a push button respond and ouput it through TX pin of 16F886 and to Xbee S1 DIN and light up a led on the receiver side. However i am unable to transmit any data at all. I am using MPLAB 8.7
Below is my TX program:

list p=16f886 ; list directive to define processor
#include <p16f886.inc> ; processor specific variable definitions

; '__CONFIG' directive is used to embed configuration data within .asm file.
; The labels following the directive are located in the respective .inc file.
; See respective data sheet for additional information on configuration word.

__CONFIG _CONFIG1, _LVP_OFF & _FCMEN_ON & _IESO_OFF & _BOR_OFF & _CPD_OFF & _CP_OFF & _MCLRE_ON & _PWRTE_ON & _WDT_OFF & _INTRC_OSC_NOCLKOUT
__CONFIG _CONFIG2, _WRT_OFF & _BOR21V

; example of using Shared Uninitialized Data Section
INT_VAR UDATA_SHR
w_temp RES 1 ; variable used for context saving
status_temp RES 1 ; variable used for context saving
pclath_temp RES 1 ; variable used for context saving

; example of using Uninitialized Data Section
TEMP_VAR UDATA ; explicit address specified is not required
temp_count RES 1 ; temporary variable (example)

;**********************************************************************
RESET_VECTOR CODE 0x0000 ; processor reset vector
nop
goto start ; go to beginning of program

INT_VECTOR CODE 0x0004 ; interrupt vector location

INTERRUPT

movwf w_temp ; save off current W register contents
movf STATUS,w ; move status register into W register
movwf status_temp ; save off contents of STATUS register
movf PCLATH,w ; move pclath register into w register
movwf pclath_temp ; save off contents of PCLATH register

; isr code can go here or be located as a call subroutine elsewhere

movf pclath_temp,w ; retrieve copy of PCLATH register
movwf PCLATH ; restore pre-isr PCLATH register contents
movf status_temp,w ; retrieve copy of STATUS register
movwf STATUS ; restore pre-isr STATUS register contents
swapf w_temp,f
swapf w_temp,w ; restore pre-isr W register contents
retfie ; return from interrupt

;==========================================================================
; Transmitter side
;==========================================================================

;--------------------------------------------------------------------------
; PORT Initialization
;--------------------------------------------------------------------------

BANKSEL PORTA ;
CLRF PORTA ; Init PORTA
BANKSEL ANSEL ;
CLRF ANSEL ; digital I/O

BANKSEL PORTC ;
CLRF PORTC ; Init PORTC
BANKSEL ANSEL ;
CLRF ANSEL ; digital I/O

BCF STATUS,RP1 ; bank 1

banksel TRISA
movlw 0xFF ; set PORTA as input
movwf TRISA
movlw 0x00 ; set PORTC as output
movwf TRISC

;--------------------------------------------------------------------------
; UART Initialization
;--------------------------------------------------------------------------

banksel SPBRG ; select bank1
movlw 0x19 ; baudrate = 9600K
movwf SPBRG ; load baudrate config. into SPBRG register
movlw b'00100100' ; TXEN = 1, BRGH = 1, Asynch. mode
movwf TXSTA ; load the value into TXSTA register

banksel RCSTA ; select bank0
movlw b'10000000' ; SPEN = 1 configures TX pin as output
movwf RCSTA ; load the values into RCSTA register
bcf STATUS,5 ; return to bank 0

;--------------------------------------------------------------------------
; Main Programme
;--------------------------------------------------------------------------

MAIN_PROG CODE

start

again call get_input
call transmit
goto again

;--------------------------------------------------------------------------
; Get Input
;--------------------------------------------------------------------------

get_input

wait btfsc PORTA, 0 ; read PORTA bit 0. if input=0, proceed else wait
goto wait
movf PORTA, W ; move values in PORTA to W register
return

;--------------------------------------------------------------------------
; Transmit Data
;--------------------------------------------------------------------------

transmit

send movwf TXREG ; transmit data stored in W register
banksel TXSTA
busy btfss TXSTA,TRMT ; check if transmission completed
goto busy
bcf STATUS, 5
return

; example of preloading EEPROM locations

EE code 0x2100
DE 5,4,3,2,1

END ; directive 'end of program'


Is there any configuration that i have missed out? btw I am using the default oscillator which is at 4MHz, do i also need to configure OSCON register?
Appreciate your help.

Newbie here.
 

Hi,

Good try, you are nearly there.

Had modified your code slightly, the changes should be clear.

The two main things, have changed your user registers for Absolute code rather than relocatable, much simpler this way.

Your biggest error was not giving labels/names and a Return to your subroutines.

Have also added a delay routine so you have change for things to be 'seen'

Have included a pic of it running in case you have not got the switch and two resistors needed.

BTW - when you post your code, please use the # tags so it retains its format.
 

Attachments

  • 886usart.rar
    25.4 KB · Views: 33

Hi,

Thank you so much for your help and advise. Appreciate it.

I will try again with amended code and feedback later.

ok, sorry will use # tags in future.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top