⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 pict16c.c

📁 to light a ledfdssssssssffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff
💻 C
字号:
//<pre>
// PICT16c.C
//
// A timer/counter demonstration that uses internal 
// interrupts
//
// Generally, TMR0 will click over at 256 and start again at
// 0. TMR0 always runs (can't shut it off).  It is counting
// microseconds unless you set a divisor in the option
// register.  That's what the 'setup_counters' command
// does (below). The divisor can be any of those on page
// 57 of the CCS manual (or the location of setup_counters
// definition).  For this one, we divided by 128 and then
// waited for the counter to overflow 256 times so
//  (128 * 256 * 256 microseconds). This is about 8 seconds
//
// 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 four switches
//	(pullups still are on them - makes it all work!)
//
#case
#include <16f84.h>
#include <defs_f84.h>  // defines registers and bits
#fuses xt,nowdt,put,noprotect

int high_count=256;

// following is mandatory to set up interrupt vector
// function that immediately follows is always the 
// interrupt service routine

#int_rtcc
timer_isr()
{	if(--high_count==0)
	{
		rb0=0;  // turn off led and then go into
			// infinite loop
		while(1);
	}
}

void main(void)
{
    TRISB=0x00;  // make Port B all outputs
    PORTB=0;	 // clear the port
    set_rtcc(0); // clear clock
    setup_counters(RTCC_INTERNAL, RTCC_DIV_128); // setup clock divisor to 256
    rb0=1;       // turn on LED
    enable_interrupts(RTCC_ZERO);
    enable_interrupts(GLOBAL);
    while(1);    // wait for interrupt
}


⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -