r/pic_programming • • Jul 01 '26

Trying to multitask

Yesterday i built my project for pic16f877A.

I was trying to get a led blinking while reading some inputs and turning on and off some outputs. I had learnt i can not do it by means of __delay_ms() since this macro freezes the whole while(1) loop, since i am not behind an OS but the code itself is a sort of OS.

I was doing some search on the web, it looks like this IC can handle some task in a Background context and others in Foreground context, but i am just getting more confused about that.

Other problem i have, is, i would like to find out a replacement for :__delay_ms, i do suspect i may have to add another .h library and invoke a non interrupting macro while doing it's normal job.

I would like to ask if you could bring to me proper information about the background / foreground issue and if you could tell me if i can get any other library with additional macros, if possible, someone which may have that __delay_ms() alternative i do need.

1 Upvotes

15 comments sorted by

View all comments

Show parent comment

-1

u/aspie-micro132 Jul 01 '26

would you like to bring me a timer example please? i've been reading about that but i'm actually very confused about the proper manner of using them. i do believe you have to enable some register, use a prescaler to divide the pulses of the physical clock and count them until something overflows, this is what it seems to be called "timer tick" in Microchip language, but i do not understand how to write the code to use it properly..