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

What happen with this code?

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



Joined: 30 Jan 2008
Posts: 197

View user's profile Send private message

What happen with this code?
PostPosted: Fri Jan 22, 2010 4:05 pm     Reply with quote

Hi, there is something wrong with this code, the same code works OK in a pic18f4550 but it did not work correctly on a pic18f452 or a pic16f88, are not error of micro, because I have tried other programs and everything works ok, someone I could tell which is the reason for this?

Code:
#include <18F452.h>
#fuses HS,NOWDT,NOPROTECT,NOLVP,NOBROWNOUT
#use delay(clock=20MHZ)

#use fast_io(b)
#use fast_io(d)

#define PULSADOR         PIN_A0
#define LEDR            PIN_B0

int Entrada;
int Modo;

#define ON           output_high
#define OFF          output_low

void main(){

      set_tris_A(0b00011111);
   set_tris_B(0b00000000);

   setup_adc_ports(NO_ANALOGS);
   Modo = 0;
   Entrada = 0;

   ON(LEDR);
   Delay_ms(1000);
   OFF(LEDR);

while(TRUE){

      if(!input(PULSADOR) && (Entrada == 0)){ 
        Modo = 1;
      Entrada ++;

      ON(LEDR);
      delay_ms(500);
      OFF(LEDR);
   }
   

   if(!input(PULSADOR) && (Entrada == 1)){ 
        Modo = 2;
      Entrada ++;

      ON(LEDR);
      delay_ms(500);
      OFF(LEDR);
      delay_ms(500);
      ON(LEDR);
      delay_ms(500);
      OFF(LEDR);
   }   

      if(!input(PULSADOR) && (Entrada == 2)){ 
           Modo = 3;
         Entrada = 0;
         ON(LEDR);
         delay_ms(500);
         OFF(LEDR);
         delay_ms(500);
         ON(LEDR);
         delay_ms(500);
         OFF(LEDR);
         delay_ms(500);
         ON(LEDR);
         delay_ms(500);
         OFF(LEDR);
      }   

   }
}


dyeatman



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

View user's profile Send private message

PostPosted: Fri Jan 22, 2010 4:41 pm     Reply with quote

OK, so what does "not working correctly" mean?

Also, you set B and D as fast_io() but then set the TRIS for A and B.
I would eliminate both of these sections and let the compiler take care of the ports for you.
_________________
Google and Forum Search are some of your best tools!!!!
pilar



Joined: 30 Jan 2008
Posts: 197

View user's profile Send private message

PostPosted: Fri Jan 22, 2010 4:53 pm     Reply with quote

Quote:
OK, so what does "not working correctly" mean? Question


I have already removed set B and D as fast_io() , but the problem remained the same
FvM



Joined: 27 Aug 2008
Posts: 2337
Location: Germany

View user's profile Send private message

PostPosted: Fri Jan 22, 2010 5:08 pm     Reply with quote

You didn't answer the question. What do you observe?
pilar



Joined: 30 Jan 2008
Posts: 197

View user's profile Send private message

PostPosted: Sun Jan 24, 2010 6:56 pm     Reply with quote

The problem is that nothing happens, although I press PULSADOR, pic does not detect this entry !!!
icesynth



Joined: 03 Sep 2007
Posts: 32
Location: Edmonton, Alberta

View user's profile Send private message Visit poster's website

PostPosted: Sun Jan 24, 2010 7:23 pm     Reply with quote

With respect to:

Code:

ON(LEDR);
Delay_ms(1000);
OFF(LEDR);


Does the LED change state at powerup?

If you meter the pins to the PIC, can you see the signal changing?

If you sub in PIN_B1 (and change the tris for it) for PULSADOR, can you see if there is a change on the codes operation? This will help rule out a problem with the setup_adc_ports

Is the correct chip selected in the programming software?

If you only put this in your main while(true) loop, what does it do? What does it do when using PIN_B0 for the input?

Code:

output_bit (PIN_B0 ,input(PIN_A0))


The code should make the LED reflect the state of the input pin.
_________________
Programming for the the real world.
--Chris Burchett
Sylver Technologies Inc.
pilar



Joined: 30 Jan 2008
Posts: 197

View user's profile Send private message

PostPosted: Tue Jan 26, 2010 7:49 am     Reply with quote

Question I see that the pic is continually resetting
dyeatman



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

View user's profile Send private message

PostPosted: Tue Jan 26, 2010 8:05 am     Reply with quote

Quote:
I see that the pic is continually resetting

Why do you say that?

Why are you NOT answering questions you are being asked?
Quote:

Does the LED change state at powerup?

If you meter the pins to the PIC, can you see the signal changing?

If you sub in PIN_B1 (and change the tris for it) for PULSADOR, can you
see if there is a change on the codes operation? This will help rule out a
problem with the setup_adc_ports

Is the correct chip selected in the programming software?

If you only put this in your main while(true) loop, what does it do?
What does it do when using PIN_B0 for the input?

_________________
Google and Forum Search are some of your best tools!!!!
icesynth



Joined: 03 Sep 2007
Posts: 32
Location: Edmonton, Alberta

View user's profile Send private message Visit poster's website

PostPosted: Tue Jan 26, 2010 9:28 am     Reply with quote

Quote:
I see that the pic is continually resetting


And a reason for you saying WHY you think it is continually resetting would be helpful as well...

ie: "I see that the pic is continually resetting ..... Because I see this and this and......"
_________________
Programming for the the real world.
--Chris Burchett
Sylver Technologies Inc.
pilar



Joined: 30 Jan 2008
Posts: 197

View user's profile Send private message

PostPosted: Tue Jan 26, 2010 9:45 am     Reply with quote

I am sorry..
At the beginning of my code, after of configure the ADC, the pic must to turning on the LEDR and after 500ms must turn off it, but I notice that the LED continuously flashes on and off so I say that the pic is continually resetting

Code:
void main(){

   set_tris_A(0b00011111);
   set_tris_B(0b00000000);

   setup_adc_ports(NO_ANALOGS);
   Modo = 0;
   Entrada = 0;

   ON(LEDR);
   Delay_ms(1000);
   OFF(LEDR);
Guest








PostPosted: Tue Jan 26, 2010 10:07 am     Reply with quote

What do you have connected to the MCLR pin?
dyeatman



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

View user's profile Send private message

PostPosted: Tue Jan 26, 2010 10:29 am     Reply with quote

Code:
 
   ON(LEDR);
   Delay_ms(1000);
   OFF(LEDR);

while(TRUE){

      if(!input(PULSADOR) && (Entrada == 0)){
        Modo = 1;
      Entrada ++;

      ON(LEDR);
      delay_ms(500);
      OFF(LEDR);
   }


Notice in the above code the LED will initially come on for 1 second and you expect it to then go off. However, if PULSADOR is low for the first input test you immediately drop into the routine and turn LEDR back on for another 500ms.

After the 500ms delay it exits the first routine and goes right into the second routine then into the third routine so the LED should be basically
be flashing at a 500ms rate with irregular pauses.

Try changing:

Code:

while(TRUE){

To
Code:

while(TRUE);

This will cause the PIC to flash the LED for one second and then loop
forever. If the LED comes on for just 1 second then stays off the PIC is
not resetting and the logic in your While loop is the problem. If the LED
continuously flashes it is resetting.
_________________
Google and Forum Search are some of your best tools!!!!
pilar



Joined: 30 Jan 2008
Posts: 197

View user's profile Send private message

PostPosted: Tue Jan 26, 2010 10:55 am     Reply with quote

Quote:
Pruebe a cambiar:

Código:

while (TRUE) (


Para
Código:

while (TRUE);

Now the pic is not reset, it appears that the problem is in logic of my While loop Twisted Evil
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