Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

How to control the led like this?

Status
Not open for further replies.

egg_land

New Member
:shock:

My PIC is PIC16F873.
This is the initial C program. I have to modify this thing like this;

Input push button on RB4, LED is initially ON. A press AND release of the button starts the LED flashing, and a subsequent press AND release freezes the LED ON .

I already hooked up the RB4, but I can't modify this code. Especially, how can I control the LED at the fist press and second press?

Please help me.

egg_land@msn.com

#include <pic.h>

#define DATA_EEMEM_PROTECT_DISABLE 0x0100
#define XT_OSC 0x0001
#define DISABLE_DEBUG 0x0800


#define CP0 0x1010
#define CP1 0x2020

/* CP0,CP1 code protect off*/
/* other bits zero which means WDT disabled
Low Voltage prm disabled, brownout disabled
power up timer enabled */

__CONFIG((CP1 | CP0) | DATA_EEMEM_PROTECT_DISABLE | XT_OSC | DISABLE_DEBUG);


#define bitset(var,bitno) ((var) |= (1 << (bitno)))
#define bitclr(var,bitno) ((var) &= ~(1 << (bitno)))
#define bittst(var,bitno) (var & (1 << (bitno)))

/* a subroutine that implements a delay via loops
Note that the compile option used will alter this delay!
Always use -O compile option
*/
a_delay()
{
unsigned int i,k;

/* change count values to alter delay */
for (k=1800; --k;) {
for(i = 200 ; --i ;);
}

}

/* just flash LED on port PB1 */
/* use this to test if PIC board is alive */
main(void)
{

TRISB = 0; /* all bits output */
PORTB = 0x00; /* turn all off */
/* use PB1 for output */

for(;;) { /* note infinite loop, all PIC programs should
be an infinite loop of some kind. Why? If the
loop exited, what would the PIC do? */

a_delay(); /* a subroutine that implements a delay via loops */
bitset(PORTB,1); /* turn on PB1 */
a_delay();
bitclr(PORTB,1); /* turn off PB1 */
}
}
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top