Just in case: At 11:59 a.m. 10/10/2003, you wrote: >Good day to all: > >I'm planing to work with multitasking on a PIC 16F877A, I found a lot of >useful help in PICLIST site, I'm a attaching a code I found there, it works >really well for two task, does anybody know how to expand it to more >tasks??? I was trying, but I can't figure it out how... any help will be >apreciate!!! > >Thanks in advance, > >Gonzalo ; RAM to bookmark current location in each task. context equ 0x20 temp equ 0x77 ; ``switch'' overwrites the W register. switch macro continuation_lable retlw ((continuation_lable)-task_table_start) ; return pointer to where to continue task endm power_on_setup: ; ... movlw (t1_1 - task_table_start) ; note task1_offset1 will run first movwf context movlw (t2_1 - task_table_start) ; task switcher call $+2 ; make a place for 'switch' to return to goto $-1 ; (i.e. here!) ;context_switcher: ; Swapping code optimized for 2 tasks. ; Code to handle 3 or more tasks ; would probably be much easier to understand. xorwf context,w xorwf context,f xorwf context,w addwf PCL,f task_table_start: t1_1 goto task1_offset1 t1_2 goto task1_offset2 t1_3 goto task1_offset3 t2_1 goto task2_offset1 t2_2 goto task2_offset2 t2_3 goto task2_offset3 task1 NOP NOP switch task1_offset1 task1_offset1 NOP NOP NOP switch task1_offset2 task1_offset2 ; fcall input_stuff NOP movwf temp ; fcall get_mask NOP andwf temp ; fcall output_stuff NOP switch task1_offset3 task1_offset3 NOP NOP ; select the address at which the task ; will next begin executing. ; this is very tricky. ; btfss condition,condition_bit ; switch(task1_offset2) ; switch(task1_offset3) ;task1_offset3 goto task1 task2 NOP NOP switch task2_offset1 task2_offset1 NOP NOP NOP switch task2_offset2 task2_offset2 NOP NOP NOP NOP switch task2_offset3 task2_offset3 NOP NOP goto task2 -- http://www.piclist.com hint: The PICList is archived three different ways. See http://www.piclist.com/#archives for details.