go away spammer

Author Topic: using integers for previous value  (Read 3922 times)

0 Members and 1 Guest are viewing this topic.

Offline junior000Topic starter

  • Full Member
  • ***
  • Posts: 59
  • Helpful? 0
using integers for previous value
« on: February 20, 2008, 12:45:58 PM »
hi,

  i am using 18f4550 and c18 compiler.one sensor is connected to the port E0.motors are coneected to rc1 rd0 and rd3 rd4.

  problem statement:whenever the sensor detects a black line or switches off, integer i has to increment by 1(all other times the sensor is high).

  PATH:black tapes are arranged horizontally with gap of 20 cm on white surface
 
 
 
here goes my program.......
 
   define an PORTEbits.RE0
   void main()
   {
      int i=0;
      TRISE = 0b00000001;
      TRISC = 0;
       TRISD = 0;
 
       while(1)
      {
 
         while(an==1)
         {
         PORTC = 0b00000000;  //run motors forward
         PORTD = 0b00001001;
 
        }
 
         if(an==0)
         {
          i++;
          }
        while(i==3)
         {
 
        PORTC = 0b00000000; //turn left
        PORTD = 0b00000101;
        some delay;
         i=0;
         }
   }
}
 
         
problem:the bot is running properly.....but it is not responding to the integer i(the direction is not changing)
 
view my tutorials at


www.myfirstbot.blogspot.com

Offline junior000Topic starter

  • Full Member
  • ***
  • Posts: 59
  • Helpful? 0
Re: using integers for previous value
« Reply #1 on: February 22, 2008, 01:21:23 AM »
should i use local or global variable???
should i specify "unsigned" int i???
view my tutorials at


www.myfirstbot.blogspot.com

Offline Admin

  • Administrator
  • Supreme Robot
  • *****
  • Posts: 11,703
  • Helpful? 173
    • Society of Robots
Re: using integers for previous value
« Reply #2 on: February 23, 2008, 03:04:11 PM »
Are you sure your variable 'an' ever changes to 0?

Also if an starts out as 1, then this is an infinite loop:
Code: [Select]
while(an==1)
         {
         PORTC = 0b00000000;  //run motors forward
         PORTD = 0b00001001;
        }

paulstreats

  • Guest
Re: using integers for previous value
« Reply #3 on: February 23, 2008, 07:19:57 PM »
This is solved in a PM. The code simulates fine - its a problem with either sensor input or lack of power.

Hey Junior000, Im not getting on your back or anything but if you have a problem thats resolved you really should post a solution for other people that have the same problem

Offline junior000Topic starter

  • Full Member
  • ***
  • Posts: 59
  • Helpful? 0
Re: using integers for previous value
« Reply #4 on: February 26, 2008, 07:08:22 AM »
yeah..i should have posted this earlier

the problem was with the power supply.the bot is working fine.
view my tutorials at


www.myfirstbot.blogspot.com

 


Get Your Ad Here

data_list