A very simple PIC18F4620 example

This is a very simple example program for the PIC18F4620 microcontroller. It just toggles the voltage on pin 19 (RD0) every 400ms to flash an LED on and off. This code is for Microchip’s C18 compiler. The circuit to use with this example is shown after the code listing.

// Very simple PIC18F4620 example
// Written by Ted Burke (ted.burke@dit.ie)
// Last update 8-2-2012

#include <p18f4620.h>
#include <delays.h>

// Use internal oscillator. Disable reset pin,
// watchdog timer and low voltage programming.
#pragma config OSC = INTIO67
#pragma config MCLRE = OFF
#pragma config WDT = OFF
#pragma config LVP = OFF

void main(void)
	// Set RD0-3 as digital outputs, RD4-7 digital inputs
	TRISD = 0b11110000;

	// Keep flashing an LED on pin RD0 indefinitely
		LATDbits.LATD0 = 1; // Set RD0 high
		Delay10KTCYx(10);   // delay for 10x40ms
		LATDbits.LATD0 = 0; // Set RD0 low
		Delay10KTCYx(10);   // delay for 10x40ms

Here’s the circuit:

Circuit diagram for connecting the PICkit 2 to a 18F4620 microcontroller

This entry was posted in Uncategorized and tagged , , , , . Bookmark the permalink.

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 )

Google+ photo

You are commenting using your Google+ 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 )

Connecting to %s