Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

pic 16f84 delay loop code for initial and end time

Status
Not open for further replies.

saqib

Newbie level 1
Joined
Sep 26, 2010
Messages
1
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,287
hi friends,
hope u all r f9
i'm trying to make a timer , whom i give initial time and end time and it runs between that time,also it shows option infront of user for delay of hours or mints etc i'm stuck plz help me

regards,
saqib
 

C code for a 1 second period with a 1MHz timer (4MHz xtal);

// uses 1 variable; unsigned long bres
// gets here every TMR0 int (every 256 ticks)

bres += 256; // add 256 ticks to bresenham total

if(bres >= 1000000) // if reached 1 second!
{
bres -= 1000000; // subtract 1 second, retain error
do_1sec_event(); // update clock, etc
}



C code for a 1 second period with a 5MHz timer (20MHz xtal);

// uses 1 variable; unsigned long bres
// gets here every TMR0 int (every 256 ticks)

bres += 256; // add 256 ticks to bresenham total

if(bres >= 5000000) // if reached 1 second!
{
bres -= 5000000; // subtract 1 second, retain error
do_1sec_event(); // update clock, etc
}
 

::roll:Timer Subroutine for 10MHz clock

;************* 1msec Timer Subroutine *****************
t1m movlw d'2' ;(1) Set loop cnt1
movwf cnt1m ;(1) Save loop cnt1
tm1lp1 movlw d'249' ;(1)*2 Set loop cnt2
movwf cnt500u ;(1)*2 Save loop cnt2
tm1lp2 nop ;(1)*249*2 Time adjust
nop ;(1)*249*2 Time adjust
decfsz cnt500u,f ;(1)*249*2 cnt500u-1=0 ?
goto tm1lp2 ;(2)*248*2 No, continue
decfsz cnt1m,f ;(1)*2 cnt1m-1=0 ?
goto tm1lp1 ;(2) No. Continue
return ;(2) Yes. Cnt end
;Total 2501*0.4usec=1msec

;************* 100msec Timer Subroutine ***************
t100m movlw d'100' ;Set loop counter
movwf cnt100m ;Save loop counter
tm2lp call t1m ;1msec subroutine
decfsz cnt100m,f ;cnt100m - 1 = 0 ?
goto tm2lp ;No. Continue
return ;Yes. Count end


;************* 500msec Timer Subroutine ***************
t500m movlw d'5' ;Set loop counter
movwf cnt500m ;Save loop counter
tm3lp call t100m ;100msec subroutine
decfsz cnt500m,f ;cnt500m - 1 = 0 ?
goto tm3lp ;No. Continue
return ;Yes. Count end

;************** 1sec Timer Subroutine *****************
t1s movlw d'2' ;Set loop counter
movwf cnt1s ;Save loop counter
tm4lp call t500m ;500msec subroutine
decfsz cnt1s,f ;cnt1s - 1 = 0 ?
goto tm4lp ;No. Continue
return ;Yes. Count end



I HOPE ITS SOME HELP U:idea:
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top