# why this Program doesn't work??

#### JK-FlipFlop

Joined Jul 5, 2010
111
here is the source code :

Rich (BB code):
#include <pic18.h>
#include <hitech.h>
main()
{
TRISC=0xff;
TRISD=0x00;
while(1)
{
if(RC0==1)
{
RD0 = 1;
RD1 = 0;
RD2 = 1;
}
else
{
RD0 = 0;
RD1 = 1;
RD2 = 0;
}
}
}
thanks for your help and time.

(for PIC18f4520 on MPLAB and Hitech compiler)
again thanks.

Last edited:

#### ELECTRONERD

Joined May 26, 2009
1,147
Show us the errors you get after you attempt to compile.

#### t06afre

Joined May 11, 2009
5,934
Does not work can be anything. Like have you tested in it in MPLAB sim? From your code I can see that configuration word(s) is not set. Is this done in MPLAB, or just not taken care of. Have you downloaded the data sheet. Reading the data sheet is something you have to do then programming PIC MCUs

#### JK-FlipFlop

Joined Jul 5, 2010
111
ok, this code passed compiling but when I run it on my PIC it only shows RD0=0 RD1=1 RD2=0 without changing from RC0...

to be more specific I dont realy know how to use the "RD" or "RC" and I have not changed any "configuration word(s)", and I dont know what is it.
maby because of that it isn't responding???

#### JK-FlipFlop

Joined Jul 5, 2010
111

#### t06afre

Joined May 11, 2009
5,934
Microchip MCUs are not very beginner friendly. So you must read the data sheet. You should read section 23.0 SPECIAL FEATURES OFTHE CPU first. This is the most important section. You should read the documents in \HI-TECH Software\PICC-18\PRO\9.64\docs A good start would be quickstart.pdf. Then try again, if you still struggle you can come back and ask for more help. But then you should give us some information about your setup. Is it some demo board, or is it something that you have on breadboard. If you have any schematics post it.

#### JK-FlipFlop

Joined Jul 5, 2010
111
I will try to change my compiler...

#### t06afre

Joined May 11, 2009
5,934
I will try to change my compiler...
Your problem is NOT in the compiler. The problem is that you have not yet fully understood how to configure the chip. Using a Microchip MCU require a lot of reading in the data sheet.

#### JK-FlipFlop

Joined Jul 5, 2010
111
other programs work, I read about my MCU and I know all his datasheet.
but when I want to turn on 1 bit from the Port sometimes it does it and somtimes it doesnt..

#define ShadowPortRD0    RD0