PDA

View Full Version : TOGGLE code space and ICD



duncan303
- 24th October 2006, 15:30
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?

sayzer
- 24th October 2006, 16:29
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.






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.





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

mister_e
- 25th October 2006, 15:26
i think TOGGLE is only dedicated for i/o not register or variables.

If you use


toggle TRISA.0

it will return an error 'Invalid RAM location specified'

So the


TRISA.0=TRISA.0 ^ 1

is the way to go.

sayzer
- 25th October 2006, 16:08
Hi Steve,

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


Here is an example.



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?