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.

pic16f EUSART problem in RF link

Status
Not open for further replies.

biswajitdas49

Member level 3
Joined
May 17, 2012
Messages
55
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,286
Location
WEST BENGAL,INDIA
Activity points
1,726
Recently I am doing a project on RF link using PIC16F1936 EUSART. So first I started with simple Eusart code, only a Tx send a 8bit data(eg B'01010101') through 433Mhz RF transmitter at 9600bps baud and a RF receiver receive it and decode the 8bit data through pic uc thats it. Here the problem start, when I check portb of rx uC with LED, I found which bit value is 1 that glows well but which containing 0 bits are blinking. But when I connect both this uC Tx and Rx pin with a wire that worked fine as I want and also my 433MHz Tx-Rx pair works fine with HT12E and HT12D but I don't want to use HT12E & D.
So I don't understand what's wrong with my code, or do I need any necessary changes in my code.

PLEASE somebody help me to solve this, I think this will be very helpfull for others too...

Thanks,

Tx code is here-
Code:
;******************************************************************************
;   This file is a basic code template for code generation on the             *
;   PIC16F1936. This file contains the basic code building blocks to build    *
;   upon.                                                                     *
;                                                                             *
;   Refer to the MPASM User's Guide for additional information on             *
;   features of the assembler.                                                *
;                                                                             *
;   Refer to the respective data sheet for additional                         *
;   information on the instruction set.                                       *
;                                                                             *
;******************************************************************************
;                                                                             *
;    Filename:        xxx.asm                                                 *
;    Date:                                                                    *
;    File Version:                                                            *
;                                                                             *
;    Author:                                                                  *
;    Company:                                                                 *
;                                                                             *
;                                                                             *
;******************************************************************************
;                                                                             *
;    Files Required: P16F1936.INC                                             *
;                                                                             *
;******************************************************************************
;                                                                             *
;    Notes:                                                                   *
;                                                                             *
;******************************************************************************
;                                                                             *
;    Revision History:                                                        *
;                                                                             *
;******************************************************************************


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

;------------------------------------------------------------------------------
;
; CONFIGURATION WORD SETUP
;
; The 'CONFIG' directive is used to embed the configuration word within the 
; .asm file. The lables following the directive are located in the respective 
; .inc file.  See the data sheet for additional information on configuration 
; word settings.
;
;------------------------------------------------------------------------------    

    __CONFIG _CONFIG1, _FOSC_INTOSC & _WDTE_OFF & _PWRTE_OFF & _MCLRE_ON & _CP_OFF & _CPD_OFF & _BOREN_OFF & _CLKOUTEN_ON & _IESO_OFF & _FCMEN_OFF
    __CONFIG _CONFIG2, _WRT_OFF & _VCAPEN_OFF & _PLLEN_OFF & _STVREN_OFF & _BORV_19 & _LVP_OFF

;------------------------------------------------------------------------------
; VARIABLE DEFINITIONS
;
; Available Data Memory divided into Bank 0-15.  Each Bank may contain 
; Special Function Registers, General Purpose Registers, and Access RAM 
;
;------------------------------------------------------------------------------

    CBLOCK 0x20 ; Define GPR variable register locations
        ADC_TEMP
        CounterA  ; 
        MYVAR3  ; 
    ENDC

SAMPLE1        EQU    0x7D        ; Sample user registers
SAMPLE2        EQU    0x7E        ; 
SAMPLE3        EQU    0x7F        ; 

;------------------------------------------------------------------------------
; EEPROM INITIALIZATION
;
; The 16F1936 has 256 bytes of non-volatile EEPROM, starting at address 0xF000
; 
;------------------------------------------------------------------------------



DATAEE    ORG  0xF000
    DE    "MCHP"  ; Place 'M' 'C' 'H' 'P' at address 0,1,2,3

;------------------------------------------------------------------------------
; RESET VECTOR
;------------------------------------------------------------------------------

    ORG     0x0000            ; processor reset vector
    PAGESEL START
    GOTO    START             ; When using debug header, first inst.
                              ; may be passed over by ICD2.  

;------------------------------------------------------------------------------
; INTERRUPT SERVICE ROUTINE
;------------------------------------------------------------------------------

    ORG      0x0004

;------------------------------------------------------------------------------
; USER INTERRUPT SERVICE ROUTINE GOES HERE
;------------------------------------------------------------------------------

; Note the 16F1936 family automatically handles context restoration for 
; W, STATUS, BSR, FSR, and PCLATH where previous templates for 16F families
; required manual restoration

    RETFIE                    ; return from interrupt
    
;------------------------------------------------------------------------------
; MAIN PROGRAM
;------------------------------------------------------------------------------

START

	BANKSEL OSCCON
	MOVLW B'01111010'
	MOVWF OSCCON			;Fosc 16MHz

	BANKSEL PORTA
	BCF PORTA,0
	BANKSEL LATA
	BCF LATA,0
	BANKSEL ANSELA		
	BSF ANSELA,0				;ANALOG INPUT AN0(PIN 2)	
	BANKSEL TRISA		
	BSF TRISA,0
	
	BANKSEL TRISC
	BCF TRISC,6		;TX
	BSF TRISC,7		;RX
	BSF TRISC,0
	BANKSEL PORTC
	BCF PORTC,6		;TX (pin 17)
	BCF PORTC,7		;RX (pin 18)
	BCF PORTC,0
	
	BANKSEL ADCON1		;A/D CONTROL REGISTER 1
	BSF ADCON1,ADFM		;A/D Result Format Select bit(RIGHT JUSTIFIED)
	BCF ADCON1,ADCS2		;A/D Conversion Clock Select bits 
	BSF ADCON1,ADCS1		;IS Fosc/32
	BCF ADCON1,ADCS0
	BCF ADCON1,ADNREF	;VREF- is connected to AVSS
	BCF ADCON1,ADPREF1	;VREF+ is connected to AVDD
	BCF ADCON1,ADPREF0	
	
	BANKSEL ADCON0
	MOVLW B'00000001'
	MOVWF ADCON0
	
	BANKSEL SPBRGH
	CLRF SPBRGH
	BANKSEL SPBRG
	MOVLW .25
	MOVWF SPBRG

	BANKSEL BAUDCON		;BAUD RATE CONTROL REGISTER
	MOVLW B'00001000'	;16-bit Baud Rate Generator bit
	MOVWF BAUDCON
	
	BANKSEL TXSTA		;TRANSMIT STATUS AND CONTROL REGISTER
	MOVLW B'00100100'	;set Transmit Enable bit,High Baud Rate Select bit
	MOVWF TXSTA
	
	BANKSEL RCSTA		;RECEIVE STATUS AND CONTROL REGISTER
	MOVLW B'10010000'	;set Serial Port Enable bit,Continuous Receive Enable bit
	MOVWF RCSTA

HERE1
;	CALL DELAY
;	BANKSEL ADCON0
;	BSF ADCON0,GO 		;Start conversion
;	BTFSC ADCON0,GO 		;Is conversion done?
;	GOTO $-1
;
;	BANKSEL ADRESL
;	MOVF ADRESL,W	
;	BANKSEL ADC_TEMP
;	MOVWF ADC_TEMP	

SEND_USART
	BANKSEL TXREG
	MOVLW B'01010101'				;B'01010101'
	MOVWF TXREG
	BANKSEL TXSTA
	BTFSS TXSTA,TRMT		;Transmit Shift Register is full(0) or empty(1)
	GOTO $-1
GOTO HERE1

DELAY

	movlw D'131'
	movwf CounterA
loop
	decfsz CounterA,F
	goto	loop
	retlw 0

    END

Rx code is here-
Code:
.;******************************************************************************
;   This file is a basic code template for code generation on the             *
;   PIC16F1936. This file contains the basic code building blocks to build    *
;   upon.                                                                     *
;                                                                             *
;   Refer to the MPASM User's Guide for additional information on             *
;   features of the assembler.                                                *
;                                                                             *
;   Refer to the respective data sheet for additional                         *
;   information on the instruction set.                                       *
;                                                                             *
;******************************************************************************
;                                                                             *
;    Filename:        xxx.asm                                                 *
;    Date:                                                                    *
;    File Version:                                                            *
;                                                                             *
;    Author:                                                                  *
;    Company:                                                                 *
;                                                                             *
;                                                                             *
;******************************************************************************
;                                                                             *
;    Files Required: P16F1936.INC                                             *
;                                                                             *
;******************************************************************************
;                                                                             *
;    Notes:                                                                   *
;                                                                             *
;******************************************************************************
;                                                                             *
;    Revision History:                                                        *
;                                                                             *
;******************************************************************************


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

;------------------------------------------------------------------------------
;
; CONFIGURATION WORD SETUP
;
; The 'CONFIG' directive is used to embed the configuration word within the 
; .asm file. The lables following the directive are located in the respective 
; .inc file.  See the data sheet for additional information on configuration 
; word settings.
;
;------------------------------------------------------------------------------    

    __CONFIG _CONFIG1, _FOSC_INTOSC & _WDTE_OFF & _PWRTE_OFF & _MCLRE_ON & _CP_OFF & _CPD_OFF & _BOREN_OFF & _CLKOUTEN_ON & _IESO_OFF & _FCMEN_OFF
    __CONFIG _CONFIG2, _WRT_OFF & _VCAPEN_OFF & _PLLEN_OFF & _STVREN_OFF & _BORV_19 & _LVP_OFF

;------------------------------------------------------------------------------
; VARIABLE DEFINITIONS
;
; Available Data Memory divided into Bank 0-15.  Each Bank may contain 
; Special Function Registers, General Purpose Registers, and Access RAM 
;
;------------------------------------------------------------------------------

    CBLOCK 0x20 ; Define GPR variable register locations
        MYVAR1  ; User variables allocated contiguously
        MYVAR2  ; 
        MYVAR3  ; 
    ENDC

SAMPLE1        EQU    0x7D        ; Sample user registers
SAMPLE2        EQU    0x7E        ; 
SAMPLE3        EQU    0x7F        ; 

;------------------------------------------------------------------------------
; EEPROM INITIALIZATION
;
; The 16F1936 has 256 bytes of non-volatile EEPROM, starting at address 0xF000
; 
;------------------------------------------------------------------------------



DATAEE    ORG  0xF000
    DE    "MCHP"  ; Place 'M' 'C' 'H' 'P' at address 0,1,2,3

;------------------------------------------------------------------------------
; RESET VECTOR
;------------------------------------------------------------------------------

    ORG     0x0000            ; processor reset vector
    PAGESEL START
    GOTO    START             ; When using debug header, first inst.
                              ; may be passed over by ICD2.  

;------------------------------------------------------------------------------
; INTERRUPT SERVICE ROUTINE
;------------------------------------------------------------------------------

    ORG      0x0004

;------------------------------------------------------------------------------
; USER INTERRUPT SERVICE ROUTINE GOES HERE
;------------------------------------------------------------------------------

; Note the 16F1936 family automatically handles context restoration for 
; W, STATUS, BSR, FSR, and PCLATH where previous templates for 16F families
; required manual restoration

    RETFIE                    ; return from interrupt
    
;------------------------------------------------------------------------------
; MAIN PROGRAM
;------------------------------------------------------------------------------

START

	BANKSEL OSCCON
	MOVLW B'01111010'
	MOVWF OSCCON	;Fosc 16MHz

	BANKSEL TRISC
	BCF TRISC,6		;TX
	BSF TRISC,7		;RX
	BANKSEL PORTC
	BCF PORTC,6		;TX
	BCF PORTC,7		;RX

	BANKSEL PORTB
	CLRF PORTB
	BANKSEL ANSELB
	CLRF ANSELB
	BANKSEL TRISB
	CLRF TRISB

	BANKSEL INTCON
	BSF INTCON,PEIE
	BSF INTCON,GIE
	BANKSEL SPBRGH
	CLRF SPBRGH
	BANKSEL SPBRG
	MOVLW .25
	MOVWF SPBRG

	BANKSEL BAUDCON		;BAUD RATE CONTROL REGISTER
	MOVLW B'00001000'	;16-bit Baud Rate Generator bit
	MOVWF BAUDCON
	
	BANKSEL TXSTA	;TRANSMIT STATUS AND CONTROL REGISTER
	MOVLW B'00100100'
	MOVWF TXSTA
	
	BANKSEL RCSTA
	MOVLW B'10010000'
	MOVWF RCSTA

HERE
	BANKSEL PIR1
	BTFSS PIR1,RCIF
	GOTO $-1
	
	BANKSEL RCREG
	MOVF RCREG,W
	BANKSEL PORTB
	MOVWF PORTB

GOTO HERE

    END
 

When your bit is '1' the transmitter is turned on and the receiver picks it up.
When your bit is '0' the transmitter is turned off - consider what the receiver is then picking up. It will be random noise, possibly with other 433MHz transmissions mixed in with it.

Brian.
 

To maximize the throughput of a ASK/OOK TX/RX pair, you will need to implement an appropriate encoding scheme, such as Manchester encoding. Details of this benefit are discussed in the thread recommended by FvM and other threads posted on this forum. Also, a baud rate of 9600 bps is most likely over optimistic, the range of 1200 or 2400 bps is more realistic.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top