why this Program doesn't work??

Discussion in 'Embedded Systems and Microcontrollers' started by JK-FlipFlop, Sep 14, 2010.

  1. JK-FlipFlop

    Thread Starter Member

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

    Code ( (Unknown Language)):
    1.  
    2. #include <pic18.h>
    3. #include <hitech.h>
    4. main()
    5. {
    6.  TRISC=0xff;
    7.  TRISD=0x00;
    8.  while(1)
    9.   {
    10.    if(RC0==1)
    11.     {
    12.      RD0 = 1;
    13.      RD1 = 0;
    14.      RD2 = 1;
    15.     }
    16.    else
    17.     {
    18.      RD0 = 0;
    19.      RD1 = 1;
    20.      RD2 = 0;
    21.     }
    22.   }
    23. }
    24.  
    thanks for your help and time.

    (for PIC18f4520 on MPLAB and Hitech compiler)
    again thanks.
     
    Last edited: Sep 15, 2010
  2. ELECTRONERD

    Senior Member

    May 26, 2009
    1,146
    16
    Show us the errors you get after you attempt to compile.
     
  3. t06afre

    AAC Fanatic!

    May 11, 2009
    5,939
    1,222
    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
     
  4. JK-FlipFlop

    Thread Starter Member

    Jul 5, 2010
    111
    0
    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???
     
  5. JK-FlipFlop

    Thread Starter Member

    Jul 5, 2010
    111
    0
    anyone please??
     
  6. t06afre

    AAC Fanatic!

    May 11, 2009
    5,939
    1,222
    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.
     
  7. JK-FlipFlop

    Thread Starter Member

    Jul 5, 2010
    111
    0
    I will try to change my compiler...
     
  8. t06afre

    AAC Fanatic!

    May 11, 2009
    5,939
    1,222
    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.
     
  9. JK-FlipFlop

    Thread Starter Member

    Jul 5, 2010
    111
    0
    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.
     
  10. beeson76

    Member

    Apr 19, 2010
    185
    1
    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

    Code ( (Unknown Language)):
    1.  
    2. #define ShadowPortRD0    RD0
    3.  
    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.
     
Loading...