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 is wrong with this robot code ?

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







What is wrong with this robot code ?
PostPosted: Mon Jun 30, 2008 10:59 am     Reply with quote

HI
I HAVE BUILT A BIG ROBOT WHICE WORK FINE MECHANICLY BUT THE SOFTWARE IS NOT GOOD AT ALL.

THE ROBOT SHOULD START GOING STRAIGHT AND BLINK A LED, AND IF HE GETS A HIGH VOLTAGE AT A2 HE GO BACK LITTLE AND THEN TURN TO A RANDOM SIDE,THEN CONTINUE GO FORWARD
MY INTERRUPT IS REALLY STRANGE....ITS DONE EVEN IF NOT ON HIGH....
I ADD MY CODE AND SORRY FOR MY ENGLISH.
THANX.


Code:
#include <16F690.h>       
#fuses XT,NOWDT,NOPROTECT,put
#use delay(clock=8000000)
#include <stdlib.h>
#define RAND_MAX 2


#int_ext
int y;


void button_isr() {

  delay_ms (40);  //debounce
  if( input(PIN_A2)==1 )
  {
    output_low(PIN_C2); //stop engines
    output_low(PIN_C3);
    output_low(PIN_C4);
    output_high(PIN_C3);

    delay_ms(50);

    output_high(PIN_C3); // go back 20 cm
    output_low(PIN_C2);
    output_high(PIN_C4);
    output_low(PIN_C5);
    delay_ms(1000);
   
    y=rand();   // y gets a random number to decide where to turn
   
      if(y==0)
   
        { output_high(PIN_C3); //turn RIGHT
          output_low(PIN_C2);
          output_high(PIN_C5);
          output_low(PIN_C4);
          delay_ms(500) ;
        }
   
      else
        { output_high(PIN_C2); //turn LEFT
          output_low(PIN_C3);
          output_high(PIN_C4);
          output_low(PIN_C5);
          delay_ms(500) ;
        }
   
  }
 
 
                         }                               
 



void main() {


enable_interrupts(global);
enable_interrupts(int_ext);
ext_int_edge( H_TO_L );




output_high(pin_b6);  //TURN ON THE LED FOR A WHILE
delay_ms(5000);
output_low(pin_b6);



   while(1)
   {

        output_high(PIN_C2);  //go straight
        output_low(PIN_C3);
        output_high(PIN_C5);
        output_low(PIN_C4);
       
       
        output_high(pin_b6); //BLINK A LED
        delay_ms(300);
        output_low(pin_b6);
        delay_ms(300);
       
       
               
   
   }
   
           }
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Jun 30, 2008 11:30 am     Reply with quote

Quote:
#int_ext
int y;

void button_isr() {

Don't put any lines of code between the #int_ext and the function
declaration.

Do it like this:
Code:
#int_ext
void button_isr() {
Guest








THATS ALL ???
PostPosted: Mon Jun 30, 2008 12:31 pm     Reply with quote

what about my interrupt?
i am sure its not ok...
can you see something wrong ?
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Jun 30, 2008 12:47 pm     Reply with quote

Your interrupt routine was not even put into the HEX output file,
because you put the "int y;" variable in between the #int_ext
and the interrupt function.

Fix the problem that I stated in my post and then try it again.
Ttelmah
Guest







PostPosted: Mon Jun 30, 2008 1:59 pm     Reply with quote

Also, you should change the edge used, then clear the interrupt, and only enable it after this. If you read the chip's data sheet, you will see that changing the selection for the 'edge', can result in the interrupt being trigered.

Best Wishes
ckielstra



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

View user's profile Send private message

PostPosted: Mon Jun 30, 2008 4:29 pm     Reply with quote

Besides all the above:
Code:
#fuses XT,NOWDT,NOPROTECT,put
#use delay(clock=8000000)
The XT fuse only supports crystals up to 4MHz. For your 8MHz crystal set the HS fuse instead.

Code:
    output_low(PIN_C2); //stop engines
    output_low(PIN_C3);
    output_low(PIN_C4);
    output_high(PIN_C3);
This looks wrong to me:
- you set PIN_C3 two times
- you don't set PIN_C5.
- Assuming you are driving a standard H-bridge the output_high in the last line should be an output_low instead.

The start of your main is missing code for disabling the analog ports, comparators and weak pull-up resistors. Many of these internal devices have priority over the use of the pin as an I/O pin. So when you think the port is an output port it might actually be configured as analog input. Check the shared functions of each I/O pin you are using against the datasheet.
An easy method to get all required setup-functions is by using the CCS project wizard to create a new project. Copy all generated start-up code to your program.
Guest








wow...thanx a lot ! one more..
PostPosted: Tue Jul 01, 2008 1:12 am     Reply with quote

I have learn so many things from your answers..
Thanx a lot !

Also one more question, why i cant debug my program without this ICE thing? I just want to enter F8 and see the debugger line go over my code line by line, as i could do in visual basic.
When i try debugger he says things about ice and etc.
I just want a simple debugging to go over my code.
Ttelmah
Guest







PostPosted: Tue Jul 01, 2008 2:32 am     Reply with quote

MPLAB, contains a simulator, which should do what you want.
If you think about it, in VB, you are writing the code 'on' a processor, that can run it. Hence this processor can be used to debug. With the PIC, the processor is a completely different device. Hence you need either a software 'simulation' of this processor (which is what MPLAB contains), or an external processor, which can send debugging information to the PC (ICE, or ICD).

Best Wishes
Guest








THANX A LOT !
PostPosted: Wed Jul 02, 2008 11:32 am     Reply with quote

THANX !
THE MPLAB IS ASEMBLER CAN I LOAD 'C' ?
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