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

16F648A question.

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



Joined: 21 Feb 2013
Posts: 16

View user's profile Send private message

16F648A question.
PostPosted: Thu Feb 21, 2013 6:56 am     Reply with quote

Hi guys. I am trying to build code for a line following robot. First of all I am trying to test with one sensor to see what output I get. When I powered up the chip I always receive 5v on m0 and m2 regardless of s0 being 0v or 5v. I am also always getting 5v on RA6 and RA7. If possible can you look through my code and see if I have made any mistakes. Thanks!

Code:
#include <16F648A.h>
#use delay(clock=4000000)
#fuses NOWDT, INTRC_IO, NOPUT, NOPROTECT, NOLVP, NOMCLR

#byte PORTA= 0x05
#bit s0=PORTA.0
#byte PORTB= 0x06
#bit m0=PORTB.0
#bit m1=PORTB.1
#bit m2=PORTB.2
#bit m3=PORTB.3


void forward()
{
   m0=1;
   m1=0;
   m2=1;
   m3=0;
}

void main(void)
{
   SET_TRIS_A(0x01);
   SET_TRIS_B(0x00);
   
   setup_oscillator(OSC_4MHZ);

   while(1) //infinite loop
   {
         if(s0==1)
         {
            forward();   
         }
   }
}

temtronic



Joined: 01 Jul 2010
Posts: 9226
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Thu Feb 21, 2013 7:16 am     Reply with quote

You should re-read the datasheet as see what internal peripherals are also used on those pins.IE, UART, ADC,COMP,etc.
Though not etched in silicon,uChip usually defaults pins that have ADC inputs to ADC use.

Also let the compiler do all the tough stuff! When your project is open, press F11 , to gain access to the extensive HELP files that CCS supplies.In there is a wealth of knowledge.Look over some of the examples they supply in the EXAMPLES folder.99.99999% of all your questions can be answered from these 2 locations.

Looks like you've cut and pasted code.Having 2 lines to set the oscillator speed is not good programming.2nd one(in MAIN) should be deleted.
'hard coding' like ...#byte PORTA= 0x05 ... shouldn't be done unless you'll only ever use THAT PIC. CCS supplies a function that is better suited ....getenv(........

What is the hardware setup? Do RA6,RA7 have pullup resistors on them?
You an't use 'set_tris_...' without using 'fast_io'.Again check the manual, and you'll C why.


I haven't shown you all the errors....
...learn by doing
hth
jay
kidswizz



Joined: 21 Feb 2013
Posts: 16

View user's profile Send private message

PostPosted: Thu Feb 21, 2013 7:20 am     Reply with quote

Thanks! I will check them now Smile
kidswizz



Joined: 21 Feb 2013
Posts: 16

View user's profile Send private message

PostPosted: Tue Feb 26, 2013 6:07 pm     Reply with quote

Thank you very much for your reply, it has helped me very much to understand how the PIC works and also the CCS C Compiler. My motors are now working correctly alongside the sensors and the ucontroller.
temtronic



Joined: 01 Jul 2010
Posts: 9226
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Tue Feb 26, 2013 6:15 pm     Reply with quote

That is GREAT news! It's nice to hear someone can 'dive in' and figure out 'the details' in 200-300 pages of what must seem like 'dull,dreary' reading.
However you've learned 'first hand' not 'cheated' by cut and pasting others code.
I tip my soldering iron to you, you'll make a great tech!

jay
Ttelmah



Joined: 11 Mar 2010
Posts: 19515

View user's profile Send private message

PostPosted: Wed Feb 27, 2013 12:56 am     Reply with quote

and 'hurrah', somebody who listened to what a response said... Smile

Look forward to seeing some complex stuff soon from kidswizz.

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