rfPIC Serin problem


Closed Thread
Results 1 to 40 of 53

Hybrid View

  1. #1
    Join Date
    Jul 2003
    Posts
    2,405


    Did you find this post helpful? Yes | No

    Default

    Hi Gavin,

    I'm just guessing, but are you using a Microchip rfPIC dev kit?
    Regards,

    -Bruce
    tech at rentron.com
    http://www.rentron.com

  2. #2
    Join Date
    Jul 2003
    Posts
    2,405


    Did you find this post helpful? Yes | No

    Smile

    I'm assuming this is the hardware you have, so I broke out my rfPIC eval kit, and played
    a bit. Give these a try.

    Receiver example;
    Code:
    '****************************************************************
    '*  Name    : rfPIC_RX.BAS                                      *
    '*  Author  : B. Reynolds                                       *
    '*  Notice  : Copyright (c) 2007 Reynolds Electronics           *
    '*          : All Rights Reserved                               *
    '*  Date    : 10/09/2007                                        *
    '*  Version : 1.0 (Momentary decoder version)                   *
    '*  Notes   : 2-Bit decoder for Microchip RF dev system         *
    '*          : with rfRXD0420 module installed in PICkit 1 board *
    '****************************************************************
    @ DEVICE PIC16F676,MCLR_OFF,INTRC_OSC_NOCLKOUT,WDT_OFF,BOD_OFF
    @ DEVICE PWRT_ON,PROTECT_OFF
        
        DEFINE OSC 4
        DEFINE NO_CLRWDT 1      ' Watchdog timer is disabled, so we don't need to reset it
        DEFINE OSCCAL_1K 1      ' load factory calibration value
        DEFINE INTHAND RESET_VT ' Interrupt on Timer1 overflow to reset outputs in 65.5mS
                                ' if no serial data received in this time period
        SYMBOL  D_IN = PORTC.1  ' data input pin
        SYMBOL  TMR1IF = PIR1.0 ' Timer1 overflow interrupt flag (reset in int handler)
        SYMBOL  TMR1IE = PIE1.0 ' Timer1 interrupt enable bit
        
        'Variables for saving state in interrupt handler
        wsave   VAR	BYTE $5F system	   ' Saves W
        ssave   VAR	BYTE bank0 system  ' Saves STATUS
        psave   VAR	BYTE bank0 system  ' Saves PCLATH
        fsave   VAR	BYTE bank0 system  ' Saves FSR
        
        ' Working variables
        MATCH     VAR BYTE bank0 system ' Match variable
        DAT_OUTB  VAR BYTE  ' Holds decoded data for output
        DAT_IN1   VAR BYTE  ' 1st Data byte
        DAT_IN2   VAR BYTE  ' 2nd Data byte for verify
        CHK_SUM   VAR BYTE  ' Holds checksum received
        CheckSum  VAR BYTE  ' Computed checksum of all bytes received
        LOOPS     VAR BYTE  ' Loop var
        
        ' Constants
        Synch    CON "~"    ' 01111110 synch byte
        N2400    CON 16780  ' 2400 bps inverted
        N4800    CON 188    ' 4800 bps inverted
        
         ' hardware init
        PORTA = 0
        TRISA = %00111001   ' RA1 and RA2 are LED outputs
        PORTC = 0           ' Clear outputs on power-up
        TRISC = %00111110   ' RC1 = RF input
        IOC = 0             ' Interrupt on change disabled
        VRCON = 0           ' Comparator Vref disabled
        CMCON = 7           ' Disable comparators
        ANSEL = 0           ' disable A/D
        OPTION_REG = 128    ' Pull-ups off
        
        ' Setup Timer1 for resets after ~65.5mS
        T1CON = %00000000   ' Internal clock, 1:1 prescale, Timer1 off for now
        TMR1L = 0 
        TMR1H = 0           ' Timer1 low & high bytes cleared
        TMR1IF = 0          ' Clear Timer1 overflow flag before enabling interrupt
        TMR1IE = 1          ' Enable Timer1 overflow interrupt
        INTCON = %11000000  ' Global & peripheral ints enabled
        MATCH = 0           ' Clear match count
        GOTO    MAIN        ' Jump over int handler
        
    ASM  ; Timer1 overflow interrupt resets outputs when no valid key press
         ; is detected within ~65mS
    RESET_VT
        movwf  wsave	 ; Save W
        swapf  STATUS, W     ; Swap STATUS to W (swap avoids changing STATUS)
        clrf   STATUS	 ; Clear STATUS
        movwf  ssave	 ; Save swapped STATUS
        movf   PCLATH, W     ; Move PCLATH to W
        movwf  psave	 ; Save PCLATH
        movf   FSR, W	 ; Move FSR to W
        movwf  fsave         ; Save FSR
        
        ; Do interrupt stuff here
        bcf    T1CON,TMR1ON  ; Stop Timer1
        clrf   TMR1L         ; Clear low byte
        clrf   TMR1H         ; Clear high byte
        bcf    PIR1,TMR1IF   ; Clear Timer1 interrupt flag bit
        clrf   PORTA         ; Clear outputs on button release
        clrf   MATCH         ; Clear match variable
        
        ; Restore FSR, PCLATH, STATUS and W registers
        movf    fsave, W	 ; retrieve FSR value
        movwf   FSR		 ; Restore it to FSR
        movf    psave, W	 ; Retrieve PCLATH value
        movwf   PCLATH	 ; Restore it to PCLATH
        swapf   ssave, W     ; Get swapped STATUS value (swap to avoid changing STATUS)
        movwf   STATUS	 ; Restore it to STATUS
        swapf   wsave, F	 ; Swap the stored W value
        swapf   wsave, W	 ; Restore it to W (swap to avoid changing STATUS)
        bsf     T1CON,TMR1ON ; Re-enable Timer1 before exiting interrupt handler
        retfie		 ; Return from the interrupt
    ENDASM
     
    MAIN:          
        ' Fire up Timer1 before entry to serial input routine
        T1CON.0 = 1
        
        ' at 4MHz Timer1 overflows in 65536 * 1uS (~65.5mS) if no Synch byte
        ' and serial data arrive on time. SERIN2 timeout & label options
        ' are useless with a noisy RF receiver output - as noise continually
        ' resets the timeout period causing it to hang forever.
        
        ' Wait for Synch byte, then get new inbound data & checksum
        SERIN2 D_IN,N2400,[WAIT(Synch),DAT_IN1,DAT_IN2,CHK_SUM]
        
        T1CON.0 = 0    ' Stop Timer1 once we've received data
        TMR1L = 0      ' Clear low byte
        TMR1H = 0      ' Clear high byte
        
        ' / **** Begin data validation **** /
        
        ' Calculate checksum by adding 2 data bytes together
        CheckSum = DAT_IN1 + DAT_IN2
        
        ' Test new checksum against one received in CHK_SUM
        IF CheckSum != CHK_SUM THEN MAIN ' Failed checksum, return
        
        ' Test data bytes for match
        IF (DAT_IN1) != (DAT_IN2) THEN MAIN ' Failed data comparison, return
        
        MATCH = MATCH + 1        ' We have a match so increment match count
        IF MATCH = 2 THEN DECODE ' Everything matched twice, we're good
        GOTO Main                ' Else do it all over
        
        ' Everything looking good - so place new data on outputs
    DECODE:
        ' Place decoded values on port pins..
        PORTA = DAT_IN1 & %00000110
        DAT_IN1 = !DAT_IN2  ' Destroy the match
        MATCH = 0 
        GOTO MAIN
            
        END
    Transmitter example;
    Code:
    '****************************************************************
    '*  Name    : rfPIC_TX.BAS                                      *
    '*  Author  : B. Reynolds                                       *
    '*  Notice  : Copyright (c) 2007 Reynolds Electronics           *
    '*          : All Rights Reserved                               *
    '*  Date    : 10/09/2007                                        *
    '*  Version : 1.0                                               *
    '*  Notes   : 2-BIT Encoder for remote control with the         *
    '*          : rfPIC12F675 on Microchip rfPIC demo board         *
    '****************************************************************
    @ DEVICE PIC12F675,MCLR_OFF,INTRC_OSC_NOCLKOUT,WDT_OFF,BOD_OFF
    @ DEVICE PWRT_ON,PROTECT_OFF
        
        ' With rfRXD0420 module installed in PICkit 1 board;
        ' SW1 toggles LED D6 on PICkit 1 board
        ' SW2 toggles LED D7 on PICkit 1 board
        DEFINE OSC 4
        DEFINE NO_CLRWDT 1
        DEFINE OSCCAL_1K 1
        
        SYMBOL D_OUT = GPIO.2 ' RF serial data output
        SYMBOL E_OUT = GPIO.5 ' RF transmitter enable output
        
        DAT_OUT VAR BYTE    ' Holds 8-bit data byte
        LOOPS   VAR BYTE    ' Loop var
        CHK_SUM VAR BYTE    ' Holds calculated checksum of outbound data
        BAUD    VAR WORD    ' Holds baud rate
        
        ' Constants
        PreAmble CON $A5    ' 10100101 preamble
        Synch    CON "~"    ' 01111110 synch byte
        N4800    CON 188    ' 4800 bps 
        N2400    CON 16780  ' 2400 bps
        GUARD    CON 5      ' 5mS guard time pause
        
        ' hardware init 
        GPIO = 0            ' Everything off on boot
        ' GPIO.2=data out, GPIO.5=RF enable, GPIO.3,4=SW1/SW2 switch inputs (rfPIC board)
        TRISIO = %00011011  '
        ANSEL = 0           ' Disable A/D
        INTCON = %00001000  ' Enable port change wakeup from sleep
        WPU = %00010000     ' pull-up on for GPIO.4 (external pull-up already on GPIO.3)
        IOC = %00011000     ' Wakeup on change enabled for GPIO.3,4
        VRCON = 0           ' Disable internal Vref
        CMCON = 7           ' Disable comparators
        OPTION_REG = 0      ' Pull-ups on
        
        D_OUT = 0           ' Idles low for inverted serial output
        E_OUT = 0           ' Enable for RF transmitter=0 (transmiter off)
        BAUD = N2400        ' Set baud rate here
        
    Main:    
        ' Read port to clear missmatch, if with no buttons pressed, then
        ' clear int-on-change flag & snooze until wake up on change. This
        ' conserves battery power on the demo board with 3V coin cell.
        IF (GPIO.3=1) AND (GPIO.4=1) THEN ' pins will be 0 only when buttons are pressed
         E_OUT=0         ' Disable transmitter
         INTCON.0 = 0    ' No buttons down, so clear int on change flag
         @ SLEEP         ' and start snoozin..zzzzzzzzzzz
         @ NOP           ' Do nothing for 1st instruction on wake-up
        ENDIF
        E_OUT=1          ' Enable transmitter (+ lights RFEN LED on demo board)
        PAUSEUS 25       ' Allow RF stage to stabilize
        
        ' Button pressed (or being held down), so keep going   
    Encode:  
        ' Only DAT_OUT bits 1 and 2 are used. We add a few 1's in bit
        ' positions 0,3,5,7 to balance out the data packet being sent.
        DAT_OUT = %10101001
        ' Get data on button inputs & invert 0's to 1's
        DAT_OUT.0[1]=~GPIO.3
        DAT_OUT.0[2]=~GPIO.4
        INTCON.0 = 0  ' Clear int on change flag
          
        ' Build checksum of 2 data bytes
        CHK_SUM = (DAT_OUT * 2)
        
    Transmit:
        SEROUT2 D_OUT,BAUD,[PreAmble,Synch,DAT_OUT,DAT_OUT,CHK_SUM]
        PAUSE GUARD ' 5mS guard time gives decoder time to respond,calculate,change,etc.
        
        GOTO Main
            
        END
    You should be able to modify these pretty easily for your own application.
    Regards,

    -Bruce
    tech at rentron.com
    http://www.rentron.com

  3. #3
    Join Date
    Sep 2005
    Posts
    53


    Did you find this post helpful? Yes | No

    Default RFSerin Problem

    Hi Bruce,

    Many thanks I will give it a bash ;-), regards, Gavin

  4. #4
    Join Date
    Nov 2007
    Posts
    9


    Did you find this post helpful? Yes | No

    Unhappy

    Hi,

    I'm a beginner in PIC programming and now struggling to program rfPIC12F675. I'm confused on how TRISIO assign input and output.

    movlw b'00010000' ; set GP<4> as digital inputs and other bits as output
    movwf trisio ; and set others as outputs/mclr/clkout/osc

    However, when I try to simulate it, and try to observe the output (we fire the GP4 as high),
    it seems that the output is 0 all the time.

    Other than setting the trisio, do I need to call any other instructions to make sure the data is being read in - send to modulation - and then output accordingly.

    I'm a bit lost now. Hope that you can help

  5. #5
    Join Date
    Jul 2003
    Posts
    2,405


    Did you find this post helpful? Yes | No

    Default

    The data sheet has everything you're looking for.

    And if you're looking for examples in Microchip assembler, then check the Microchip website for rfPIC examples. Here's a direct link to rfPIC examples; http://www.microchip.com/stellent/id...cName=en010060
    Regards,

    -Bruce
    tech at rentron.com
    http://www.rentron.com

  6. #6
    Join Date
    Nov 2007
    Posts
    9


    Did you find this post helpful? Yes | No

    Default

    Thanks for that. It is useful!

  7. #7
    Join Date
    Nov 2007
    Posts
    11


    Did you find this post helpful? Yes | No

    Default tranmitter demo program

    im looking at the demo program for development kits transmitter and receiver rfpic12675 and receiver rf rxd XXX. im trying to apply the same program to my telemtry project but with digital input.

    i dont understand the part of program which under head transmitter loop. do we need to do the loop if our input is digital? and what about the '' rrf ' and 'bnz' instruction? rotate right flag?

    i don't understand the TZnextbit too? im so lost right now. can anyone explain this to me?

    thanks

Similar Threads

  1. Serin Problem with 12F629/PBP
    By Flyingms in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 9th March 2009, 14:59
  2. Serin Problem 16f819
    By jjohannson in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 22nd March 2007, 22:50
  3. Serin serout problem
    By lerameur in forum mel PIC BASIC Pro
    Replies: 336
    Last Post: - 6th February 2007, 04:25
  4. Problem with PBP interrupt and Serin, please help
    By rgregor in forum mel PIC BASIC
    Replies: 0
    Last Post: - 22nd August 2006, 19:02
  5. serout and serin problem
    By nicolelawsc in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 11th April 2006, 19:44

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts