📄 pict15c.c
字号:
//<pre>
// pict15c.c
//
// Implementation of the PICT15.ASM program in Easy Pic 'N
// Interrupt demo.
//
// In this example, portB,0 is the interrupt source - the
// interrupt is done with a 'pulser' which is basically a
// debounced switch with a half monostable multivibrator.
// You can use a debounced switch alone to make it work.
// I have used an ordinary Radio Shack switch and let it
// bounce. It still works ok - just have to punch it a
// couple of times to get the light to stay on.
//
// Using '84 on a board (simple solderless breadboard with
// 16F84 on it) and Peter Anderson's include file with
// port/bit definitions (defs_f84.h available at www.phanderson.com)
// Settings:
// 4Mhz resonator (not important)
// All Port A inputs use external pullups (resistor
// SIP used)
// Port B outputs tied to a LED array (Radio Shack
// has 'em)
// Port A inputs tied to ground through five switches
// (pullups still are on them - makes it all work!)
// Port A0 use for switch monitoring (for kicks - not
// part of interrupt scheme).
// PortB0 is the Int source so it is
// an input. A one shot is tied to portB0. (see the book
// for more information, but you should be able to make
// something that will work from this)
#case
#include <16f84.h>
#include <defs_f84.h> // defines registers and bits
#fuses xt,nowdt,put,noprotect
#int_ext // see page 41 of the CCS manual - this is
// the interrupt declaration. the function that
// follows is the interrupt service routine
void iserv(void)
{
rb2=!rb2; // flop the bit on rb2
}
void main(void)
{
TRISA=0x1f; // make porta inputs
trisb0=1; // make portb, bit 0 input (interrupt)
trisb1=0; // make portb, bit 1, 2 output
trisb2=0;
rb1=0;
rb2=0;
enable_interrupts(INT_EXT); // mandatory if you want externals
enable_interrupts(GLOBAL); // mandatory to start it all
// get this going and then toggle the portA0 switch
// to see the normal switch monitoring, and then
// pulse rb0 to see the interrupt work.
//
while(1)
{
if (ra0==1) // monitor porta for switch (just
// for something to do while
// toggling interrupts)
rb1=1;
if (ra0==0)
rb1=0;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -