ArtsAutosBooksBusinessEducationEntertainmentFamilyFashionFoodGamesGenderHealthHolidaysHomeHubPagesPersonal FinancePetsPoliticsReligionSportsTechnologyTravel
  • »
  • Technology»
  • Computers & Software»
  • Computer Science & Programming

PIC16f887 Source code to operate relay, LED (anything) no. of times with interrupt

Updated on September 11, 2012

PIC16f887 micro controller is a 8 Bit CMOS micro controller with nano Technology from the company Microchip having High-Performance RISC CPU and several other special features . In this project , we shall interface LED , relay , buzzer or anything which can act as output with the Micro Controller PIC16f887 .

The main motive is that for every interrupt we give to micro Controller , it will give that much particular no. of times the total output at our desired configured pin . According to the source code of the program , you need to interface switch "push button" on portb as input while on portc , connect anything which can act as output .

Just copy the following source code int the software "PIC C compiler" named as PCWHD and compile it . After the compilation , you will get the converted "hex" file of your written code . Just flash or burn the hex file onto your micro controller using usb 2.0 Programmer or by any other way you want .

Now for each time you press the switch , it will count the total no. of times the switch has been pressed , and it will give output for that much no. of times . For example , I pressed the switch 5 times , The LED will then Glow 5 times .

#include<16f887.h>
#fuses intrc_io,nowdt
#byte portb= 0x06
#byte trisb= 0x86
#byte portc= 0x07
#byte trisc= 0x87
#byte intcon=0x8b
unsigned int32 i=0,j=0,m=0,k=0;
#int_ext
external()
{
m=m+1;
k=1;
for(i=0;i<10000;i++);
intcon&=0xfd;
}
void main ()
{
trisc = 0x00;
portc = 0x00;  //off
trisb = 0x01;
intcon= 0xd0;
while(1)
{
if(k==1)
{
for(j=0;j<m;j++)
{
portc=0x01;
for(i=0;i<95000;i++);
portc=0x00;
for(i=0;i<95000;i++);
}
k=0;
}
}

Comments

    0 of 8192 characters used
    Post Comment

    No comments yet.