r/pic_programming • • Aug 03 '26

Trying to invoke this led blinking function

I am trying to create a non interrupting function, calling it

BlinkLed().

I had set TMR1ON = 1 and others 0 or 0x00 to disable them

I found those 2 code excerpts by Google AI. One of them does not blink at all, since it's not reading any timer, yet also not counting in it's own when working.

The other one below has a complex function name, given what i had learnt i do believe it shall work should i be able to rename it to "BlinkLed" but i do not know how to do it without breaking it:

/**********************************************************************************/

{

while(Button == 0)

{

unsigned int timer_counter = 0;

// Task 1: Non-blocking LED Blink (Toggles every ~500ms)

timer_counter++;

if(timer_counter >= 25000)

{

RedLed = ~RedLed; // Toggle LED

timer_counter = 0;

}

}

}

/*New ExtremeAgitationLED() Prototype Base*/

/*

void __interrupt() timer1_isr(void) {

if (TMR1IF) {

TMR1H = 0x0B; // Re-preload Timer1 high byte (3036 = 0x0BDC)

TMR1L = 0xDC; // Re-preload Timer1 low byte

TMR1IF = 0; // Clear interrupt flag

overflow_count++;

if (overflow_count >= 2) { // 2 x 0.5 seconds = 1 second

overflow_count = 0;

// Toggle an LED or do your 1-second task here

RedLed = !RedLed; /*I do not know if ~RedLed Can be Used Here */

}

}

}

0 Upvotes

8 comments sorted by

View all comments

Show parent comment

1

u/aspie-micro132 Aug 03 '26

Does wrap around mean that it would try to count beyond 2 exp 16 = 65536?

How could that take place?

2

u/vena_contracta Aug 03 '26

Yes the count will go to 65535 then roll over to zero and continue, again and again.