; ; The code starting at bigloop marks the start of the mainline ; code. The MCU performs all tasks within this loop until the ; timeout flag is set. When that happens, control falls out of ; the loop into the task section below. ; ; You can add small tasks to the loop, if you want. These will ; be run every pass through the loop. Depending on how simple ; the tasks are, you could get a few to several hundred tasks ; completed between timeouts. ; bigloop: ; ; Replace these comments with any tasks you want executed at ; every pass through the loop. ; brset PORTB,BI0,big1 ; test for clear bsf sticky,SBI0CLR ; record it goto big2 big1: bsf sticky,SBI0SET ; no, it was set big2: brset PORTB,BI1,big3 ; test for clear bsf sticky,SBI1CLR ; record it goto big4 big3: bsf sticky,SBI1SET ; no, it was set big4: brset PORTB,BI2,big5 ; test for clear bsf sticky,SBI2CLR ; record it goto big6 big5: bsf sticky,SBI2SET ; no, it was set big6: brset PORTC,BI3,big7 ; test for clear bsf sticky,SBI3CLR ; record it goto big8 big7: bsf sticky,SBI3SET ; no, it was set big8: movf timeout,f ; test timeout flag beq bigloop ; branch if not yet time ; ; This is the task section. Put whatever you want your machine ; to do at each timeout in this section. If your program might ; be disturbed by background interrupts from the 1-msec timer, ; you can disable interrupts immediately. Regardless, you should ; disable interrupts before calling SetCount to reload the timer ; values. ; movf xmtcntr,w ; get current counter bne big9 ; branch if not first time movf sticky,w ; get sticky byte movwf stickysnd ; save for SendData clrf sticky ; clear sticky byte for next loop big9: bsf LED_PORT,LED_OUTPUT call SendData ; send the data bcf LED_PORT,LED_OUTPUT incf xmtcntr,f ; count this time movfw xmtcntr ; get the counter select case 1 ; if first transmission... movlw (DLY_50MSEC&0xff) ; change delay movwf dlyl movlw (DLY_50MSEC>>8) movwf dlyh endcase case 2 ; if second transmission... movlw (DLY_50MSEC&0xff) ; change delay movwf dlyl movlw (DLY_50MSEC>>8) movwf dlyh endcase case 3 ; if third transmssion movlw (DLY_XMISSION&0xff) ; get low half of delay count movwf dlyl ; init the delay variable movlw (DLY_XMISSION>>8) ; get high half of delay count movwf dlyh ; init the delay variable clrf xmtcntr ; restart counter incf recnumber,f ; bump the record number endcase endselect bcf INTCON,GIE ; shut off interrupts call SetCount ; rearm timer bsf INTCON,GIE ; turn interrupts back on goto bigloop ; do forever