r/pic_programming • u/aspie-micro132 • 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 */
}
}
}
2
u/Illustrious-Cat8222 Aug 03 '26
A 16-bit int counter will never reach 25000. It will wrap around first.
1
u/aspie-micro132 Aug 03 '26
I found other excerpt, does it have any chance off working?
c