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

HI...

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



Joined: 09 Jan 2008
Posts: 4
Location: Malaysia

View user's profile Send private message Yahoo Messenger

HI...
PostPosted: Wed Jan 09, 2008 11:20 pm     Reply with quote

Hi..
i'm new here...
i worked on project titled mobile robot using LDR sensor...
i plan to use 2 sensor using LDR for my mobile robot..
And for motor driver, i used Tamiya DC motor with gearbox...
For software, i used CCS PIC C Compiler...
I already write the program and CCS compiled it with no error...
But i cautious if the program can make my robot moves...
Can someone help me...

Here sample project i write myself...



#include <16f877a.h>//Select PIC type=PIC16F877
#USE DELAY( CLOCK=20000000 ) //Select your oscillator speed=20MHz crystal
#FUSES HS,NOWDT,NOPROTECT//Select the oscillator type
#byte port_b=6//Define the Address of PORTB
#byte port_d=8//Define the Address of PORTD

main()//Declare main program

{

set_tris_b(0b00000000);//Set port_b0 to be input
set_tris_b(0b00000001);//Set port_b1 to be input
set_tris_d(0b00000000);//Set D0, D1 as output (D0=LED, D1=Relay to Motor)
set_tris_d(0b00000001);//set D2, D3 as output (D2=LED, D3=Relay to Motor)
port_d = 0;//Initialize all PORTD output to 0 Volt

for(;;)//Do forever

{

if ( (INPUT(PIN_B0)==0)||(INPUT(PIN_B1)==0))

{
//Turn both LED and Motor ON when both Sensors activated
output_high(PIN_D0);
output_high(PIN_D1);
output_high(PIN_D2);
output_high(PIN_D3);

}

else if ( INPUT(PIN_B0) == 0 )

{
//Turn LED1 and Motor1 ON when Sensor1 activated
output_high(PIN_D0);
output_high(PIN_D1);
output_low(PIN_D2);
output_low(PIN_D3);
}

else if (INPUT(PIN_B1)==0)

{
//Turn LED2 and Motor2 ON when Sensor2 activated
output_high(PIN_D2);
output_high(PIN_D3);
output_low(PIN_D0);
output_low(PIN_D1);
}

else

{
//Turn both LED and Motor OFF when both sensors not activated
output_low(PIN_D0);
output_low(PIN_D1);
output_low(PIN_D2);
output_low(PIN_D3);
}


} // close for loop


} // close main program
_________________
Lets Rock n' Roll
deepakomanna



Joined: 06 Mar 2007
Posts: 92
Location: Pune,India

View user's profile Send private message AIM Address Yahoo Messenger

try this...
PostPosted: Thu Jan 10, 2008 3:06 am     Reply with quote

while checking condition use && operator insted ||,
you can try,
B0 B1
0 0 ====> 1st condition
0 1 ====> 2nd condition
1 0 ====> 3rd condition
1 1 ====> 4th condition
So you can define like this

if((INPUT(PIN_B0) == 0) && (INPUT(PIN_B1) == 0)) {
// add ur statements.
}
else if((INPUT(PIN_B0) == 0) && (INPUT(PIN_B1) == 1)) {
// add ur statements.
}
else if((INPUT(PIN_B0) == 1) && (INPUT(PIN_B1) == 0)) {
// add ur statements.
}
else {
// add ur statements.
}

may be this will some idea Very Happy
_________________
Thank You,
With Best Regards,
Deepak.
Cable Guy



Joined: 09 Jan 2008
Posts: 4
Location: Malaysia

View user's profile Send private message Yahoo Messenger

hi...
PostPosted: Fri Jan 11, 2008 10:08 pm     Reply with quote

i also consider to use PWM in my program...
and so to add a few delay time ==delay...
so anyone can help me...
and tq deepak...
_________________
Lets Rock n' Roll
Wayne_



Joined: 10 Oct 2007
Posts: 681

View user's profile Send private message

PostPosted: Mon Jan 14, 2008 2:40 am     Reply with quote

I am pretty sure this is wrong :-
set_tris_b(0b00000000);//Set port_b0 to be input
set_tris_b(0b00000001);//Set port_b1 to be input
set_tris_d(0b00000000);//Set D0, D1 as output (D0=LED, D1=Relay to Motor)
set_tris_d(0b00000001);//set D2, D3 as output (D2=LED, D3=Relay to Motor)

Your first set_tris_b is setting all port_b as output.
Your second set_tris_b is overwriting the first and only setting b0 as input.
The first set_tris_d sets port_d as output but then you set d0 as input in the next line.

You just need

Code:

set_tris_b(0b00000011); //Set port_b0, port_b1 to be input
set_tris_d(0b00000000); //Set D0, D1, D2, D3 as output
Ttelmah
Guest







PostPosted: Mon Jan 14, 2008 4:11 am     Reply with quote

Even worse, there needs to be the #use fast_io lines added for each port.
As it stands, the code sets:
Code:

set_tris_d(0b00000001);//set D2, D3 as output (D2=LED, D3=Relay to Motor)

Then a few lines further on, uses:
Code:

output_high(PIN_D0);

This will change the TRIS for port D, to '00000000'.

How can you 'output' to a pin set as an input?. The compiler will override the TRIS setting....
Then the tris lines themselves make no sense. On consecutive lines, you have:
Code:

set_tris_b(0b00000000);//Set port_b0 to be input
set_tris_b(0b00000001);//Set port_b1 to be input

The first sets the whole port to be output, then the second sets B0 to be an input. Nothing sets 'B1 to be an input' as the comment suggests...

Best Wishes
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