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

output_high() in a "for(;;)" cycle

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



Joined: 21 Aug 2010
Posts: 7

View user's profile Send private message

output_high() in a "for(;;)" cycle
PostPosted: Sat Aug 21, 2010 8:02 am     Reply with quote

Hello to all,
I've this stupid doubt. In this code:
Code:

void main(){
   ...
   set_tris_c(0b00000000);
   ...
   for(;;){
      delay_ms(1000);
      output_high(PIN_C0);
      delay_ms(1000);
   }
}

PIN_C0 is blinking with a 1 second rate. Why?
Why in this for-cycle the PIN_C0 turns off?
(I don't write "output_low(PIN_C0)" )
Thanks a lot to all.
Claudio
FvM



Joined: 27 Aug 2008
Posts: 2337
Location: Germany

View user's profile Send private message

PostPosted: Sat Aug 21, 2010 8:21 am     Reply with quote

May be a case of the well-known RMW problem. Increase the load resistor connected to the output to achieve a legal logic "1" level at the pin.

Or did you enable the watchdog timer?
cmussoni



Joined: 21 Aug 2010
Posts: 7

View user's profile Send private message

output_high() in a "for(;;)" cicle
PostPosted: Sat Aug 21, 2010 10:25 am     Reply with quote

Hello,
I've no WDog (#fuses XT, NOWDT...). I don't try to change the output load but when I bring out the code :
Code:

delay_ms(1000);
output_high(PIN_C0);
delay_ms(1000);

from the infinite loop for(;;) the output blinks no more.
Any other idea ?
Thanks a lot
Claudio
cmussoni



Joined: 21 Aug 2010
Posts: 7

View user's profile Send private message

output_high() in a "for(;;)" cicle
PostPosted: Sat Aug 21, 2010 10:28 am     Reply with quote

...ooops... I remind I' m working with a PIC16F876A.
Bye.
dyeatman



Joined: 06 Sep 2003
Posts: 1934
Location: Norman, OK

View user's profile Send private message

PostPosted: Sat Aug 21, 2010 10:52 am     Reply with quote

Why don't you post the entire (compilable) program so we can test it rather than play guessing games?
_________________
Google and Forum Search are some of your best tools!!!!
cmussoni



Joined: 21 Aug 2010
Posts: 7

View user's profile Send private message

PostPosted: Sat Aug 21, 2010 11:08 am     Reply with quote

Ok there it is :
Code:

#include <16F876A.h>

#fuses   XT, NOWDT, NOPROTECT, NOPUT, NOBROWNOUT, NOLVP
#use delay (clock=4000000)

#define  TX232 PIN_A2
#define  RX232 PIN_A5

#define  INTSP PIN_A4

#use rs232(baud=9600, xmit=TX232, rcv=RX232)

BYTE int_count;

#define INTS_PER_2_SECOND 20   
#INT_TIMER0

int FLAGOK=0;
int timeout=0;
int DATOIN=0;
int current_b=0;
int current_c=0;

void  READDATA(){
   FLAGOK=0;
   delay_us(100);
   timeout=0;
   while(!kbhit() && (++timeout<5000)){   // 0,05 second
   delay_us(10);
   }

   if(kbhit()){
      DATOIN=getc();
      FLAGOK=1;
   }
   else {
      FLAGOK=0;
   }
}

void main(){

   set_tris_a(0b00110010);
   set_tris_b(0b11111111);
   set_tris_c(0b00000000);

   port_b_pullups(TRUE);
   delay_ms(100);

   for(;;){
      READDATA();
      delay_ms(200);
      output_high(PIN_C0);
      delay_ms(1000);
    }
}
FvM



Joined: 27 Aug 2008
Posts: 2337
Location: Germany

View user's profile Send private message

PostPosted: Sat Aug 21, 2010 11:19 am     Reply with quote

And the CCS version, please.
cmussoni



Joined: 21 Aug 2010
Posts: 7

View user's profile Send private message

PostPosted: Sat Aug 21, 2010 11:41 am     Reply with quote

IDE 4.093
PCB 4.093
PCM 4.093
PCH 4.093
PCD 4.093
Cool
cmussoni



Joined: 21 Aug 2010
Posts: 7

View user's profile Send private message

PostPosted: Sat Aug 21, 2010 11:52 am     Reply with quote

Sorry, sorry. The complete for-cycle is the sequence:
Code:

for(;;){
      current_b=input_b();
      delay_us(100);
      current_c=input_c();
      delay_us(100);

      READDATO();
      delay_ms(200);
      output_high(PIN_C0);
      delay_ms(1000);
}
FvM



Joined: 27 Aug 2008
Posts: 2337
Location: Germany

View user's profile Send private message

PostPosted: Sat Aug 21, 2010 1:17 pm     Reply with quote

Quote:
Sorry, sorry. The complete for-cycle is the sequence:

O.K. input_c() sets all port c pins to tri-state, because default #USE STANDARD_IO is in effect.
Ttelmah



Joined: 11 Mar 2010
Posts: 19535

View user's profile Send private message

PostPosted: Sat Aug 21, 2010 2:57 pm     Reply with quote

OK.
Several problems.
You have a #int declaration, without interrupt handler code after it. Either get rid of this declaration, or put a handler there...
You have a timeout counter, going to 5000, declared as an integer. An int, in CCS, can hold 255 max. This will never timeout.
This is why you don't get a blink.
Then, if the timeout was working, your delay here will be several instructions more than 10uSec. In fact the time will probably be nearly twice this.
You do realise that using a software UART, you _must_ poll the pin at intervals no longer than 0.5 a bit time. Any data that arrives in the 1200mSec comprising the rest of your loop, _will_ be lost. The actual 'odds' of seeing a serial character, are extremely poor indeed.

Best Wishes
cmussoni



Joined: 21 Aug 2010
Posts: 7

View user's profile Send private message

PostPosted: Sun Aug 22, 2010 1:26 am     Reply with quote

FvM...THAAANKS for the solutions: input_c() set PORTC to input !!!

Thank also Ttelmah for all the other my oversights. Rolling Eyes

Bye
Claudio
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