CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

exclusive oring of port pin

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
dave.t
Guest







exclusive oring of port pin
PostPosted: Wed Apr 30, 2003 9:41 am     Reply with quote

Hi all
I have just started to use the 12f629 chip and have written a simple led flasher program which uses the overflow on timer 1 to generate an interrupt - the isr then toggles the led.
In my isr routine I initially used:

led=led^1;
(led being gp0)

I have used this with previous chips (16f877 etc.)for test purposes with no problems but it will not work with the 12f629. If I replace the statement with:

toggle=toggle^1;
led=toggle; (toggle is a short)
it works ok.
Any thoughts?
Thanks very much
Dave
___________________________
This message was ported from CCS's old forum
Original Post ID: 14082
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

Re: exclusiv oring of port pin
PostPosted: Wed Apr 30, 2003 1:13 pm     Reply with quote

:=Hi all
:=I have just started to use the 12f629 chip and have written a simple led flasher program which uses the overflow on timer 1 to generate an interrupt - the isr then toggles the led.
:=In my isr routine I initially used:
:=
:= led=led^1;
:=(led being gp0)
---------------------------------------------------------

The following sample program worked OK. It was compiled
with PCM vs. 3.148.

I myself wouldn't toggle a pin in this manner. You're
depending upon properly reading the value of the pin. It may
work in a particular case, or even in most cases, but you're
taking a hardware risk. There could be capacitance on the
pin, or you could run into the RMW problem if your PIC is
running at high speed. I mean, it's OK for a hobbiest, but
I wouldn't do it for production.

I'm not saying anything is wrong with it in this particular
case. What I'm saying is that I don't make little exceptions
when I'm writing code. I always go for what's the most safe
and the most clean.

So I would use the other method you described, with a separate
variable that holds the LED state. Toggle the variable, then
write the variable out to the pin.

But here's the working code with your original method.
<PRE>
#include <12F629.h>
#fuses INTRC, NOWDT, NOPROTECT, NOMCLR
#use delay(clock = 4000000)
<BR>
#bit LED = 5.2
<BR>
//============================================================
main()
{
setup_comparator(NC_NC_NC_NC);
set_tris_a(0x00);
<BR>
LED = 0;
<BR>
while(1)
{
LED = LED^1;
delay_ms(500);
LED = LED^1;
delay_ms(500);
}
<BR>
}
</PRE>
___________________________
This message was ported from CCS's old forum
Original Post ID: 14093
j_purbrick
Guest







Re: exclusiv oring of port pin
PostPosted: Wed Apr 30, 2003 1:55 pm     Reply with quote

:=I have just started to use the 12f629 chip and have written a simple led flasher program which uses the overflow on timer 1 to generate an interrupt - the isr then toggles the led.
:=In my isr routine I initially used:
:=
:= led=led^1;
:=(led being gp0)
:=
:=Dave

Assuming the 629 works the same as the 877 and you're running the LED by connecting it in series with a resistor between the pin and Vdd or Vss, then I think you can get around problems with the actual pin output (involving XOR operations, etc) by working with the corresponding TRIS bit instead. But this wouldn't work if you have to drive logic off the pin.
___________________________
This message was ported from CCS's old forum
Original Post ID: 14096
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group