pic18f452

Thread Starter

tintu

Joined Dec 9, 2012
1
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?
 

Attachments

hexreader

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

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

spinnaker

Joined Oct 29, 2009
7,830
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?

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.

Rich (BB code):
#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;
     }
   }
}
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:

Rich (BB code):
for(i=0;i<10;i++)
{
    PORTD=0x00;
}
This does the same:

Rich (BB code):
for(i=0;i<10;i++);
PORTD=0x00;
Or better replace the for statement with a delay.
 
Last edited:
Top