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 support@ccsinfo.com

Inverting the state of an output pin

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







Inverting the state of an output pin
PostPosted: Thu May 13, 2004 10:16 pm     Reply with quote

Hi, I moved from Basic to C and I'm having a little trouble...

I have this code:

Code:
#int_TIMER0
TIMER0_isr() {
   if(mms=10) {
      ms++;
      mms=0;
      read_adc(ADC_START_ONLY);
      if(ms=10) {
         tenth++;
         ms=0;
         if(tenth=10) {
            sec++;
            tenth=0;
            if(!input(PIN_C4)) output_high(PIN_C4);
               else output_low(PIN_C4);
            }
       }
   }
}


I want it to invert the state of portc.4 every second, but it is always on.

Does someone can help me?

Thank you.
Haplo



Joined: 06 Sep 2003
Posts: 659
Location: Sydney, Australia

View user's profile Send private message

PostPosted: Thu May 13, 2004 11:06 pm     Reply with quote

The equality check in C is ==, so change your 'if' statements to

if(mms==10)

and so forth.
ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

PostPosted: Fri May 14, 2004 12:14 am     Reply with quote

and more efficient is to use the function output_toggle(PIN_C4).
Guest








PostPosted: Fri May 14, 2004 4:43 am     Reply with quote

very weird if I put if(mms==10) it doesn't light at all.

with if(mms=10) it takes one second to light but stays always on.
Guest








PostPosted: Fri May 14, 2004 5:00 am     Reply with quote

Hmm the problem was mine..

TIMER0_isr() {
if(mms=10) {
ms++;
mms=0;

has to be

TIMER0_isr() {
mms++;
if(mms=10) {
ms++;
mms=0;

good to see the fast replies. thank you very much.
Haplo



Joined: 06 Sep 2003
Posts: 659
Location: Sydney, Australia

View user's profile Send private message

PostPosted: Fri May 14, 2004 5:04 am     Reply with quote

Anonymous wrote:
Hmm the problem was mine..

TIMER0_isr() {
if(mms=10) {
ms++;
mms=0;

has to be

TIMER0_isr() {
mms++;
if(mms=10) {
ms++;
mms=0;

good to see the fast replies. thank you very much.


You are still using a single = for equality check. That 'if' statement has no effect.
Guest








PostPosted: Fri May 14, 2004 7:36 am     Reply with quote

Just a single copy/paste from the forum. In my code it is already fixed.
Thank you.
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