Hi I am trying to blink LED with 18f4550, and I am getting no success.

I have defined the PORTD as output , TRISD=0;

I am trying to blink led with Some delay of 50 ms on mplabx and xc8,

I don’t want to use the LATDbits to set the led to High. Instead I am trying

PORTD=0b00000000; format.

Sample

#include<pic18f4550>
#define _XTAL_FREQ 2000000

void main(void)
{
TRISD=0; //output
while(1)
{
PORTD = 0b10000000; // Dont want to use LATDbits.RD0=1;
__delay_ms(50);
PORTD = 0b01000000;
__delay_ms(50);
}
}


If am using LATDbits.RD0=1; then its working fine the way its supposed to be. But I want to use PORTD =0b00000000; format because it is little convenient . Am I doing something wrong ?

• You write to LAT and read from PORT. What is wrong with using LATDbits.RD0=1? If you really don't want to use it, substitute LATD for PORTD, but I'll be if you look at the disassembly, it will be identical. – Matt Young Feb 5 '14 at 14:37
• If you are using RD0 for the LED, the order of your PORTD bit assignments is reversed. Change to PORTD = 0b00000001; etc. – Tut Feb 5 '14 at 14:50
• Thank you tut, It just didnt come to my mind :D .. yes the bit assignment got reversed. thanks man :) Problem Solved. :D – Sanju Feb 5 '14 at 14:54