View previous topic :: View next topic |
Author |
Message |
kidswizz
Joined: 21 Feb 2013 Posts: 16
|
16F648A question. |
Posted: Thu Feb 21, 2013 6:56 am |
|
|
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();
}
}
}
|
|
|
![](templates/subSilver/images/spacer.gif) |
temtronic
Joined: 01 Jul 2010 Posts: 9178 Location: Greensville,Ontario
|
|
Posted: Thu Feb 21, 2013 7:16 am |
|
|
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 |
|
![](templates/subSilver/images/spacer.gif) |
kidswizz
Joined: 21 Feb 2013 Posts: 16
|
|
Posted: Thu Feb 21, 2013 7:20 am |
|
|
Thanks! I will check them now ![Smile](images/smiles/icon_smile.gif) |
|
![](templates/subSilver/images/spacer.gif) |
kidswizz
Joined: 21 Feb 2013 Posts: 16
|
|
Posted: Tue Feb 26, 2013 6:07 pm |
|
|
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. |
|
![](templates/subSilver/images/spacer.gif) |
temtronic
Joined: 01 Jul 2010 Posts: 9178 Location: Greensville,Ontario
|
|
Posted: Tue Feb 26, 2013 6:15 pm |
|
|
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 |
|
![](templates/subSilver/images/spacer.gif) |
Ttelmah
Joined: 11 Mar 2010 Posts: 19384
|
|
Posted: Wed Feb 27, 2013 12:56 am |
|
|
and 'hurrah', somebody who listened to what a response said...
Look forward to seeing some complex stuff soon from kidswizz.
Best Wishes |
|
![](templates/subSilver/images/spacer.gif) |
|