TOGGLE code space and ICD


Closed Thread
Results 1 to 4 of 4
  1. #1
    Join Date
    Oct 2004
    Location
    North Norfolk UK
    Posts
    146

    Default TOGGLE code space and ICD

    hi,

    An issue has arisen with a 16F877A with its portb linked to portb on a 16f876. This project has been working successfully for many months. I have the 16F877A set up with microcode ICD. I suspect that I will have to scrap the offending IC's however this raises a two issues which I wondered if anyone had any thoughts on.

    The actual incident is as follows using PBP2.47 and the PM assembler: TrisB on the 16F877a = 255 and TrisB on the 16F876 = 0. I have a variable bit (T_C) used as a program indicator on the 16F877a. If I use code toggle T_C whilst in ICD mode all is well, yet when I compile normally once this toggle has been executed it seems to change the direction of portb and the 16F876 goes crazy and I am forced to manually reset.

    However If I change the line from

    TOGGLE T_C

    to

    T_C = T_C ^ %1

    then all is well.

    Should one only use the toggle command when it is connected to a pin either directly or through a variable, also as I understand from the manual that TOGGLE can also change pin direction, presumably therefore TOGGLE generates longer code than bit bashing.

    and why should ICD compile be unaffected?

    any thoughts or experience?

  2. #2
    Join Date
    Jan 2006
    Location
    Istanbul
    Posts
    1,185


    Did you find this post helpful? Yes | No

    Default

    Hi DUNCAN,

    I have an example here with a button test to show how Toggle behaves.
    It is just an example and may give you some clue.

    How/where does your TOGGLE command get executed? You are most likely having an issue as below.



    Code:
    T_C VAR BIT
    ButtonX VAR PORTE.0
    
    
    Loop:
         IF BUTTONX = 0 THEN TOGGLE T_C
         'This will toggle T_C unknown number of times 
         'while the button is being pressed.
         
         
         
    GOTO LOOP

    Take a look at this code now.


    Code:
    LOOP:
         IF BUTTONX = 0 THEN
            WHILE BUTTONX = 0 : WEND
            TOGGLE T_C
         ENDIF
        'This will toggle T_C one time once 
        'the button is pressed and released.
         
    GOTO LOOP
    "If the Earth were a single state, Istanbul would be its capital." Napoleon Bonaparte

  3. #3
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    i think TOGGLE is only dedicated for i/o not register or variables.

    If you use
    Code:
    toggle TRISA.0
    it will return an error 'Invalid RAM location specified'

    So the
    Code:
    TRISA.0=TRISA.0 ^ 1
    is the way to go.
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  4. #4
    Join Date
    Jan 2006
    Location
    Istanbul
    Posts
    1,185


    Did you find this post helpful? Yes | No

    Default

    Hi Steve,

    I do not know a register but a bit variable works.


    Here is an example.

    Code:
    TRISA = 0
    TRISB = 0
    
    Test  var bit
    Relay var PORTB.0
    Test  = 0
    relay = 0
    
    start:
    
            toggle relay    'This is an I/O.
            toggle test     'This is a variable.
            pause 1000
    
    goto start
    
    
    end

    Did you mean something else?
    "If the Earth were a single state, Istanbul would be its capital." Napoleon Bonaparte

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