Using as many internal peripherals as possible.


Closed Thread
Results 1 to 12 of 12

Hybrid View

  1. #1
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,623


    Did you find this post helpful? Yes | No

    Default Re: Using as many internal peripherals as possible.

    How about this?
    Code:
    Main:
      n = n + INTCON.2
      INTCON.2 = 0
    
      IF n.3 THEN
          LATA = LATA ^ %000011
          n=0
      ENDIF
    
      goto Main
    It won't produce exactly the same frequency as your example but it's 12% smaller (37 words). I suppose there's also the odd chance/risk of the TMR0 interrupt bit being set in between checking it and clearing it. You COULD also do away with the n=0 at the start with the drawback of the FIRST iteration taking longer depending on the start value of n. AND, possibly, get rid of the GOTO Main and let the PC freerun and start over from the top.

    Adding DEFINE NO_CLRWDT 1 saves one or two words depending on which version.

    Using TMR1, which is 16 bits with its 8:1 prescaler instead of counting overflows should achieve similar results
    Code:
    T1CON = %00110001
    
    Main:
    IF PIR1.0 THEN
        PIR1.0 = 0
        LATA = LATA ^ %000011
    ENDIF
    
    Goto Main
    Combining these I got it down to 34 words but have not checked if it actually works.

    /Henrik.

  2. #2


    Did you find this post helpful? Yes | No

    Default Re: Using as many internal peripherals as possible.

    I tested your codes, both works. The second example with TMR1 I like the most because maintain 4MHz clock. And yes, it compiles only 34 words. Just one more word than mine when I manipulate the clock speed.
    Nice.

Similar Threads

  1. New cool PIC peripherals
    By HenrikOlsson in forum General
    Replies: 1
    Last Post: - 21st September 2016, 21:50
  2. Replies: 8
    Last Post: - 21st March 2015, 18:21
  3. Replies: 4
    Last Post: - 11th June 2014, 23:53
  4. Replies: 0
    Last Post: - 7th August 2008, 10:02
  5. Internal Oscillator
    By jhorsburgh in forum General
    Replies: 2
    Last Post: - 10th December 2007, 03:13

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