Friday, May 1, 2015

PIC18F4550 Make All Outputs Blink

PIC18F4550 LED Blink

In this topic we are going to make all the available outputs on the PIC18F4550 blink. 
The PIC18F4550 has 40 pin of which 34 pin can be used as inputs and from this 40 pins we can use 31 as outputs. The USB pins D- and D+ which are at RC4 and RC5 respectively can be used as inputs only as well as MCLR (RE3). There is no RC3 on the PIC18F4550 and it is replaced with a pin called Vusb, this pin can not be used as input or output.
The analog pins must be configured as digital.
The following circuit schematic shows a microcontroller PIC18F4550 connected with 31 LED through 470Ohm resistors:

Note  that there are only 31 LED connected.
The internal crystal of the microcontroller is used at 8MHz and the MCLR function is disabled.
The proteus simulation will not give an actual result of this circuit.
LED Blink MikroC Code:
The code is written using MikroC PRO for PIC version 6.4.0 compiler.

void main() {
 ADCON1 = 0x0F;        // Configure AN pins as digital
 PORTA = 0; TRISA = 0;
 PORTB = 0; TRISB = 0;
 PORTC = 0; TRISC = 0;
 PORTD = 0; TRISD = 0;
 PORTE = 0; TRISE = 0;