1. tintu

    Thread Starter New Member

    Dec 9, 2012
    1
    0
    hi....i am new to pic18f452...i have written a simple c code to generate pulses in port D of it...i used mplab c18 compiler and pickit 3 to program the pic....the program is as follows....


    #include<p18f452.h>
    #pragma config OSC=HS
    #pragma config OSCS=OFF
    #pragma config WDT =OFF
    void main()
    {
    int i;
    TRISD=0;
    PORTD=0x00;
    while(1)
    {
    for(i=0;i<10;i++)
    {
    PORTD=0x00;
    }
    for(i=0;i<10;i++)
    {
    PORTD=0xff;
    }
    }
    }


    the output expected is a continuous pulses from every pin of PORTD.

    i'm attaching the output which i got in oscilloscope...
    the 1st figure shows the output of a pin of the port D....i am getting pulses for a short duration, then the output remains low for a short interval, then again i obtain pulses....this cycle repeats...
    why is the output low for a short interval?
     
  2. hexreader

    Active Member

    Apr 16, 2011
    250
    82
    You need to disable Low Voltage Programming (LVP) in config settings.

    Your PGM pin is floating, and picking up 50Hz mains hum.
     
  3. spinnaker

    AAC Fanatic!

    Oct 29, 2009
    4,887
    1,016

    You are showing 3 images. Which is the right one?

    You should post in png format and do not resize the BMPs smaller. PNG is a compressed format and you should be able to upload the full size.

    Please use the code tags when posting code.

    It is a left square bracket the word code followed by a right square bracket. The ending tag is the same except a / character after the bracket.

    Code ( (Unknown Language)):
    1.  
    2. #include<p18f452.h>
    3. #pragma config OSC=HS
    4. #pragma config OSCS=OFF
    5. #pragma config WDT =OFF
    6. void main()
    7. {
    8.        int i;
    9.       TRISD=0;
    10.       PORTD=0x00;
    11.       while(1)
    12.      {
    13.          for(i=0;i<10;i++)
    14.        {
    15.            PORTD=0x00;
    16.        }
    17.       for(i=0;i<10;i++)
    18.      {
    19.           PORTD=0xff;
    20.      }
    21.    }
    22. }
    23.  
    Please use capital letters at the start of your sentences and stop the ... Please save the text language for twitter.


    You normally should read ports and set latches.

    Try this LATD=0x00 and LATD=0xFF instead.


    What have you done to debug your code? Did you step through it and check the outputs?

    There is no need to do something like this:

    Code ( (Unknown Language)):
    1.  
    2. for(i=0;i<10;i++)
    3. {
    4.     PORTD=0x00;
    5. }
    6.  
    This does the same:

    Code ( (Unknown Language)):
    1.  
    2. for(i=0;i<10;i++);
    3. PORTD=0x00;
    4.  
    Or better replace the for statement with a delay.
     
    Last edited: Dec 9, 2012
Loading...