why this Program doesn't work??

Thread Starter

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:

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:D
 

Thread Starter

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???
 

t06afre

Joined May 11, 2009
5,934
anyone please??
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.
 

Thread Starter

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..

thanks for your time.
 

beeson76

Joined Apr 19, 2010
204
I had a similar problem when I first began with Microchip chips. Try using what they call Shadow Registers. It all has to do with what they call "Read Modify Write". Whether the problem really exists, it would be wiser for me to let more knowledgeable people answer that--there is quite a debate about it. A shadow register is simply another name for your port. Usually you use it in a #define statement at the beginning of you program. For this program, being pretty simple, I would code something pretty simple too, such as

Rich (BB code):
#define ShadowPortRD0    RD0
so on and so forth. Whether you capitalize the Shadow Register or not is matter of preference but many good programmers say that you should, just to differentiate. Use Shadow Registers whenever you can.
 
Top