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

📄 pict7c.c

📁 to light a ledfdssssssssffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff
💻 C
字号:
//<pre>
// PICT7.C
//
// A timer/counter demonstration (no interrupts on this one)
// The output is an 8 ms square wave.
//
// Generally, TMR0 will click over at 256 and start again at
// 0. Once started (by writing to it), 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 256 and then
// waited 32 ticks (32 * 256 microseconds).
//
// 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!)
// 	You aren't going to see much with this one unless
//	you use a scope. The freq is too fast.
//
#case
#include <16f84.h>
#include <defs_f84.h>  // defines registers and bits
#fuses xt,nowdt,put,noprotect

// delay routines
void pause(void);

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_256); // setup clock divisor to 256

    while (1)
	{	rb0=1; // turn on port b0
		pause(); // pause for 8 ms (view with scope)
		rb0=0; // turn off port b0
		pause(); // pause for 8 ms (view with scope)
	}
}

// delay routines

void pause(void)	// clock increments 1 every 256
			// beats (1 us per beat)
			// tests timer bit 5 until is
			// set - which means it waits for 
			// about 8 ms (256 us * 32)
			// note that this is for a 4 mhz
			// clock. Bit 5 is equiv to 32
{
	set_rtcc(0);	// clear the counter
	while(	! bit_test(TMR0,5));
}

⌨️ 快捷键说明

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