12f1822, serial RX under interrupt, echo program doesn't want to play


Results 1 to 9 of 9

Threaded View

  1. #4
    Join Date
    Aug 2005
    Location
    Michigan, USA
    Posts
    224


    Did you find this post helpful? Yes | No

    Default Re: 12f1822, serial RX under interrupt, echo program doesn't want to play

    Quote Originally Posted by Darrel Taylor View Post
    When you're working with PBP, it's easy to forget that there are "BANKs" in the RAM because it's all handled for you.
    But when you are writing at the ASM level, you have to remember about the BANKs. And on the F1 type parts, there are a lot of them. (32 to be exact).

    In your case, RCREG is in BANK3.
    And since you only have 1 variable in your program, it will obviously end up in BANK0. But when the program gets bigger, that may not be the case.
    It should be able to find your variables no matter what bank they end up in.

    Also, when you get an interrupt on an F1 part. You have no idea what bank it is in when it gets to the ISR.
    It's up to you to change it to BANK0 (if that's the bank your ISR needs).
    Really? I'm surprised! The BoostC compiler I use (sorry, still no PBP to play with here) apparently keeps track of the variables and registers used in my assembly language instructions and automatically inserts the 'movlb x' instructions for me. Now you have me wondering if that feature is unique to BoostC or if other compilers have it as well? Anyway, please notice how I had to comment out all of my bank select instructions after I discovered they were redundant;

    Code:
      /*                                                                  *
       *  (C) 2012, K8LH - low level One-Wire R/W (Carry) Bit Driver      *
       *  (hard coded for "owpin" defines and 8-MHz clock)  (30 words)    *
       *                                                                  */
       void owrw()                  // read/write Carry bit
       { intcon.GIE = 0;            // interrupts off
       //asm movlb  owport          // bank 0 (inserted by compiler)
         asm bcf    owport,owpin    // clear owpin output latch
       //asm movlb  owtris          // bank 1 (inserted by compiler)
         asm bcf    owtris,owpin    // owpin low (falling edge)
         asm movf   _pcl,F          // pseudo bra $+1 (2 cycles)
         asm movf   _pcl,F          //   "
         asm movf   _pcl,F          //   "
         asm skpnc                  // if a '1' (C=1)
         asm bsf    owtris,owpin    // set owpin to hi-z '1'
         asm movlw  18/3            //
       dly1:
         asm decfsz _wreg,W         // DelayCy(14*usecs-10)
         asm bra    dly1            //
       //asm movlb  owport          // bank 0 (inserted by compiler)
         asm btfss  owport,owpin    // exactly 14-us from falling edge
         asm clrc                   // clear Carry if 'owpin' was low
         asm movlw  84/3            // balance of 60-usec "r/w slot"
       dly2:
         asm decfsz _wreg,W         // DelayCy(47*usecs-10)
         asm bra    dly2            //
       //asm clrf   _wreg           // wreg already 0 (see above)
         asm rlf    _wreg,W         // save C (wreg = 0x00 or 0x01)
         asm xorwf  _crc,F          // xor b0 bits, result in 'crc'
         asm rrf    _crc,F          // xor result 0 (C=0)?
         asm skpnc                  // yes, skip, else
         asm iorlw  0x18            // wreg = x8+x5+x4+1 poly and b0 bit
         asm rrf    _wreg,W         // restore C (wreg = 0x8C or 0x00)
         asm xorwf  _crc,F          // apply the polynomial, or not
       //asm movlb  owtris          // bank 1 (inserted by compiler)
         asm bsf    owtris,owpin    // set owpin to hi-z '1' @ 61-usecs
         intcon.GIE = 1;            // interrupts on
       }                            //
    
      /*                                                                  *
       *  (C) 2012, K8LH - One-Wire R/W Byte Function       (11 words)    *
       *                                                                  */
       char owrw(u08 pbyte)         // read/write byte
       { u08 i = 0;                 // bit counter
         do                         //
         { asm rrf _pbyte,W         // put output bit b0 in Carry
           owrw();                  // write then read bit
           asm rrf _pbyte,F         // save input bit from Carry
           i++;                     //
         } while(i.3 == 0);         //
         return pbyte;              //
       }                            //
    Last edited by Mike, K8LH; - 4th December 2012 at 18:03.

Similar Threads

  1. Two interrupt sources in one program
    By Art in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 25th January 2012, 16:12
  2. confused problem with interrupt in a working program
    By illuminator4 in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 14th November 2008, 18:01
  3. Play with LCD on PICDEM
    By The IceMan in forum mel PIC BASIC
    Replies: 5
    Last Post: - 22nd August 2008, 17:56
  4. How can i use Interrupt in my program??
    By alabbadi in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 17th November 2007, 14:28
  5. Simple Interrupt Program
    By eoasap in forum General
    Replies: 5
    Last Post: - 28th October 2005, 17:22

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