Skip to main content

LED Blinking project using PIC Microcontroller using PICC,miKroC and proteus

Blinking LED using PIC Microcontroller(PIC18F4580)

All digital I/O’s are grouped together into “Ports”, called A, B ,D. Here GPIO means “general purpose input output”. The PIC18F4580 features a total of 36 I/O-pins, called PORTA to PORTD. But there’s more. The device comes with so many additional internal units, that not all features could be connected to dedicated pins of the device package at any one time. The solution is: multiplex. This means, one single physical pin of the device can be used for different functions and it is up to the programmer to decide which function is selected.

Proteus simulation for blinking LED  project

Before going to the programming you should understand the following things.


When a digital I/O operation is required, then register TRIS defines the direction of the I/O. Setting  a bit position to zero configures the line as an input, setting the bit position to 1 configures the line as an 'output'. For instance, PORTA0 or RA0 to Output Pin, one can use the instruction:
                                                            
                                                                TRISA.RA0 = 0;

A data write to an required port can also be performed with PORT register. Logic one(1) indicates the pin is at logic high and logic zero(0) indicates the pin is logic low.  

Additionally, PORT register can be utilized to read digital logic from an Input pin. 

CSS Programming Code for Blinking Led. 


Blinking led code for pic microcontroller

#inc


The following CSS program blinks an LED with a delay of 1 second
void main()
{
   setup_adc_ports(NO_ANALOGS|VSS_VDD);
   setup_adc(ADC_OFF|ADC_TAD_MUL_0);
   setup_psp(PSP_DISABLED);
   setup_spi(SPI_SS_DISABLED);
   setup_wdt(WDT_OFF);
   setup_timer_0(RTCC_INTERNAL);
   setup_timer_1(T1_DISABLED);
   setup_timer_2(T2_DISABLED,0,1);
   setup_comparator(NC_NC_NC_NC);
   setup_vref(FALSE);

while(1)
{
output_toggle(PIN_A0);
delay_ms(1000);
}
}



mikroC Programming Code for Blinking Led. 

Blinking led code for pic microcontroller

 

The following mikroC program blinks an LED with a delay of 1 second
void main()
{

   ADCON1 = 0xff; //Configure Analog Pin as a digital IO
   CMCON  = 0;   // Disable Comparators
 
 

  TRISA.RA0 = 0; //Makes PORTA0 or RA0 Output Pin

  while(1) //Infinite Loop
  {
    PORTA.RA0 = 1; //LED ON
    Delay_ms(1000); //1 Second Delay
    PORTA.RA0 = 0; //LED OFF
    Delay_ms(1000); //1 Second Delay
  }
}

How To Test Blinking led Project  Using Oscilloscope 

Have you ever found yourself troubleshooting a circuit, needing additional info than an easy multimeter will provide? If you would like to uncover info like frequency, noise, amplitude, or the other characteristic which may some variations over time, oscilloscope is one of that instrument.  

Now so as to feature the cathode-ray oscilloscope within the circuit, 1st click on the Virtual Instruments Mode as shown within the below figure.





Oscilloscope display in proteus

                  



Now drag that cathode-ray oscilloscope and place it within the space, as you'll be able to see below this element has total four legs means that you'll be able to read total four differing kinds of signals and  might additionally compare them, if you would like to.


             Testing Blinking Led



How To Select Series Resistor for led 

This question gets asked on a daily basis by the students: What resistance do I connect with my LED? Therefore I've place how to work it out.

  • Consider the Following Electrical Parameter: 

  • LED Voltage generally "Forward Voltage" however sometimes simply abbreviated "V".
  • LED Current generally "Forward Current". This is often listed in milliamps or "mA"
  • Supply voltage This is often what proportion power you're connecting with the LED, in our case 5V are there if Microcontroller pin goes high.

LED Voltage and current will be found on the packaging for your product or on your supplier's provided datasheet. If they list ("20-30mA") decide  a current value(mA) in the middle (25 mA in this case). Here we used some generic values, but use your own values to take care you don't blow your LEDs!:

Red LED: 2V 15mA
Green LED: 2.1V 20mA
Blue LED: 3.2V 25mA
While LED: 3.2V 25mA


Okay, lets get started!
in our case consider the following schematic

I have led with the following electrical specification

LED_Red: 2V ,7.5mA

Now we have to calculate R1.

imp Note(Before going to calculate resistor you must check Absolute maximum ratings of Electrical specification for "Maximum current Sourced by any I/O pin" ,of microcontroller form its datasheet in our case see fig below) 




From Datasheet we can see that Current(mA) Requirement in our case is less than maximum output current sourced by I/O pin.

                     

Friends for further learning about PIC18 checkout:

Comments

Popular posts from this blog

How to use SPI Debugger

  SPI Debugger Hi Friends, in this post, we will discuss how to use SPI Debugger available in proteus for serial peripheral interface (SPI) which is a built-in feature of PIC microcontroller to communicate and data exchange between PIC and other devices. SPI Debugger Introduction to SPI Guys, SPI can be considered as a programmable shift  register, The SPI module is a synchronous serial I/O port that shifts a serial bit stream of variable length and data rate between the PIC and other peripheral devices. Here “synchronous” means that the data transmission is synchronized to a clock signal. To avoid further delay, let's see some important connections and different configurations to effectively use SPI Debugger. How to use SPI Debugger in MASTER & SLAVE configuration Select the virtual instrument and from the instrument, list selects "SPI Debugger". SPI Debugger Insert two SPI Debugger on the working area, select any one of them,

PIC18f4580 Timer0 calculation using miKroC , CSS and proteus

PIC18f4580 TIMER PROGRAMMING The PIC18f4580 has four timers. they're named as Timers zero, one, two, and three. they will be used either as timers to come up with a time delay or as counters to count events happening outside the microcontroller. First, we see however Timers zero is employed to come up with time delays. Every timer wants a clock pulse to tick. The clock supply will be internal or external. If we have a tendency to use the inner clock supply, then 1/ fourth of the frequency of the crystal oscillator on the OSC1 and OSC2 pins (Fosc/4) is fed into the timer. Therefore, it's used for time delay generation and for that reason is termed a timer. By selecting the external clock choice, we have a tendency to feed pulses through one among the PIC18's pins: this is often known as a counter. GIF  taken from  https://exploreembedded.com Basic registers of the timer Majority of t timers in 18F are 16 bits wide. Because the PIC 18 has an 8- bit ar

Frequency Counter using Interrupts PIC18f4580 Project

Frequency Counter  using PIC18f458 0 Proje ct This POST describes the construction of small frequency counter with a cheap PIC18f4580 microcontroller with 16 x 2 LCD.   Prerequisites: PIC18F4580 TIMER Programming. PIC18F4580 COUNTER Programming. PIC18F4580 Interfacing with 16x2 LCD. PIC18F4580 Interrupts Programming  ( we will cover in this POST) Concept: Frequency  is the number of occurrences of a repeating event per unit time. in our case we will measure a number of clocks generated by clock source per unit time. In this project, LCD is used to display the frequency and PIC timer 1 to measure the input signal and Timer0 to generate an indication that one second has gone. System software utilizes Timer-1 in the 16-bit counter mode to count the input signal and overflows of the counter are added to provide the aggregate count in multiples of 65536. Totaling the existing value of the counter at the conclusion provides the full count.