Complete beginner - pulling hair out - 18f13k22

Thread Starter

ashumu

Joined Nov 25, 2010
3
Hello all,

I've programmed in C18 before briefly using tutorials and managed to do some basics. However, I've now got an 18F13K22 and I've found I'm not even capable of getting it to do the basics. I'm using mplab IDE v8.60 and microchips c18 compiler. I've read through the compiler, pic and mplab manuals as well as going through the entire 18f13k22.h file to try and get an idea as to what is going on.

So far I have this:

Rich (BB code):
#include <p18f13k22.h>



void main(){

TRISA = 0;
TRISB = 0;


while(1){

PORTBbits.RB7 = 1;
PORTAbits.RA0 = 1;

}
}
Now I would assume that this, being such a basic and trivial task, would be simple enough to get first try. Alas, a whole day of reading, programming and stressing out has led me to believe that I'm missing some important details as there is zero output on either of those pins when it is hooked up. I can't find a document or source of info on this PIC that doesn't seem to either be missing out all the basics that I need or simply in another language.

Can anyone please shed some light on this issue?
 

Markd77

Joined Sep 7, 2009
2,806
I don't use C (as you can probably tell)
Maybe if LATbits isn't defined something like this will work:
The output LATches are a safer way of outputting.
LATB.7 = 1;
LATA.0 = 1;
 

spinnaker

Joined Oct 29, 2009
7,830
Does anything change if you replace "PORT" with "LAT"?
Worth a shot.

Mark is right. You read ports and write to latches. Plus port A and B have analog outputs. You should make sure they are binary outputs by setting their ANS bits. See your datasheeet for ANSEL.
 

jdraughn

Joined Jan 30, 2009
33
I have always found it useful to pause the debugger, then change the values to a 1 manually (Hit enter after changing the value), and then step forward, if it changes right back to a 0, then you know that it's most likely a configuration setting. Look at your TRIS values in the watch window too, see if they are still set to outputs.
 
Top