Monday, February 29, 2016

PIC16F84A PORTB interrupt on change (IOC) example


This topic shows how to use PORTB change interrupt, this interrupt occurs when an input port changes its state. The pins responsible for this interrupt are RB4, RB5, RB6 and RB7.
PIC16F84A PORTB interrupt on change (IOC) example circuit:
pic16f84a portb change interrupt ccs pic c
As shown in the circuit schematic above there is an LED and 4 pushbuttons. The interrupt occurred when a pushbutton is pressed or depressed. When the interrupt occurred the LED toggles its state. The video below describes the circuit and the code.
PIC16F84A PORTB interrupt on change (IOC) example CCS C code:
// PIC16F84A PORTB interrupt on change example
// http://ccspicc.blogspot.com/
// electronnote@gmail.com

#include <16F84A.h>
#fuses HS,NOWDT,PUT,NOPROTECT
#use delay(crystal=8000000)

#INT_RB
void rb_isr(void)
{
 clear_interrupt(INT_RB);    // Clear RB port change interrupt flag bit
 output_toggle(PIN_A0);
}

void main()
{
  set_tris_b(0xF0);
  clear_interrupt(INT_RB);   // Clear RB port change interrupt flag bit
  enable_interrupts(INT_RB); // Enable RB port change interrupt
  enable_interrupts(GLOBAL); // Enable all unmasked interrupt
  output_low(PIN_A0);

  while(TRUE) ;              // Endless loop
}

PIC16F84A PORTB interrupt on change (IOC) example video:

Sunday, February 28, 2016

PIC16F84A external interrupt example


The microcontroller PIC16F84A has a unique external interrupt at RB0 pin (hardware interrupt). When an interrupt occurred, the microcontroller immediately executes the code attached with the interrupt, after finishing the interrupt code the microcontroller returns to the main code.
This topic is a small example shows how to use PIC16F84A external interrupt.
PIC16F84A external interrupt example circuit:
pic16f84a external interrupt ccs picc 
In the circuit schematic above we have just a button and an LED , the button is connected to the external interrupt RB0/INT pin and the LED is connected to RA0 pin. When the button pressed, an interrupt occurred and the LED will toggle its state.
PIC16F84A external interrupt example CCS C code:
// PIC16F84A external interrupt example
// http://ccspicc.blogspot.com/
// electronnote@gmail.com

#include <16F84A.h>
#fuses HS,NOWDT,PUT,NOPROTECT
#use delay(crystal=8000000)

#INT_EXT
void ext_isr(void)
{
 output_toggle(PIN_A0);
}

void main()
{
  output_low(PIN_A0);
  ext_int_edge(H_TO_L);       // Interrupt on falling edge of RB0/INT pin
  clear_interrupt(INT_EXT);   // Clear RB0/INT external interrupt flag bit
  enable_interrupts(INT_EXT); // Enable RB0/INT external interrupt
  enable_interrupts(GLOBAL);  // Enable all unmasked interrupt

  while(TRUE) ;               // Endless loop
}

PIC16F84A external interrupt example video:
The following video has some details about the circuit and the CCS C code.

Thursday, February 25, 2016

PIC16F84A blink LED using push button


This topic shows how to turn on and off 2 LEDs connected to PIC16F84A using 2 push buttons.
LED blink using push button circuit:
pic16f84 led bink button ccs pic c
The circuit is simple there 2 LEDs and 2 buttons each button toggles one LED for example when the first push button which is connected to RB0 is pressed, the first LED which is connected to RA0 turns ON, and when the same button pressed again the same LED turns OFF, and the same thing for the second button and the second LED.
LED blink using push button CCS PIC C code:
// PIC16F84A LED blink example
// http://ccspicc.blogspot.com/
// electronnote@gmail.com

#include <16F84A.h>
#fuses HS,NOWDT,PUT,NOPROTECT
#use delay(crystal=8000000)

void main()
{
   while(TRUE)    // Endless loop
   {
     if(input(PIN_B0) == 0)
     {
       output_toggle(PIN_A0);
       delay_ms(500);
     }
     if(input(PIN_B1) == 0)
     {
       output_toggle(PIN_A1);
       delay_ms(500);
     }
   }
}

Wednesday, February 24, 2016

PIC16F84A LED blink


PIC16F84A LED flasher
Blink an LED using PIC16F84A and CCS PIC C compiler
This topic shows how to make an LED blinking using PIC16F84A and PIC C compiler.
It is easy to make an LED blinking, a few program lines is required and the microcontroller PIC16F84A is a simple chip also.
PIC16F84A LED blink circuit:
Circuit schematic for the LED flasher is shown below.
pic16f84a led blink ccs pic c
PIC16F84A LED blink C code:
Code is written with CCS compiler.
// PIC16F84A LED blink example
// http://ccspicc.blogspot.com/

#include <16F84A.h>
#use delay(crystal=8000000)

void main()
{
   while(TRUE)    // Endless loop
   {
      output_low(PIN_A0);    // LED OFF
      delay_ms(500);         // Delay 500 ms
      output_high(PIN_A0);   // LED ON
      delay_ms(500);         // Delay 500 ms
   }
}

PIC16F84A LED blink simulation video:
The following video shows the simulation using Proteus.