Writing your first program for your microcontroller

code1It is a dream for anyone to burn their first program into their microcontroller. Well, I have a suggestion to start with you first program. Any microcontroller lesson starts with LED blinking. The LED’s could be connected to any of the I/O pins of your microcontroller.  In the PIC microcontroller, I would prefer using the PORTB.

                        PORTA needs to be configured for normal I/O operation. Whereas, PORTC contains communication pins. The figure above shows a program using MPLAB ide software. I have attached a code for LED blinking using PORTB.

void delay_ms(int n);
void delay_us(int n);
int i;
void main()
{
  PORTB = 0X00;
  TRISB= 0X00;
while(1)
{
  PORTB = 0X00;
  delay_ms(3000);
  PORTB = 0XFF;
  delay_ms(3000);
}
}
void delay_ms(int n)
{
 delay_us(n);
}
void delay_us(int n)
{
  for(i=1;i<=n;i++)
{
}
}

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: