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.

Delay function using Timer0

Status
Not open for further replies.

Ma3ix

Member level 2
Joined
Dec 17, 2015
Messages
43
Helped
0
Reputation
0
Reaction score
0
Trophy points
6
Activity points
375
I need help for this code. It is coded in Bascom program language.

I wanted to create function for delay using timer0. The problem is that this code executes
only "second delay" (5ms).

Where is problem in code:idea:

Code:
Led1 Alias P1.0   						' Led1 alias connected to pin P1.0                                            
Led2 Alias P1.6							  Led2 alias connected to pin P1.0 

Config Timer0 = Timer , Gate = Internal , Mode = 1            'Config timer 0 as 16bit timer

Enable Timer0                                                                                              

---varijables---------------------
Dim Flag As Byte                                             
Dim X As Integer					' parameter of function "delayy"    
Declare Sub Delayy(x As Integer)			' delay function with parameter x
Dim Miliseconds As Integer				
---------------------------
Enable Timer0

'------------------------------------------------------------------------------
'main  program
------------------------------------------------------------------------------

Do                                                            

--' first delay of 10ms (one call of fuction is 1000uS = 1ms)---'

Call Delayy(10)					
If Flag = 1 Then
Led1 = Not Led1					 'blink P1.0
Miliseconds = 0
Flag = 0
End If


--' second delay of 5ms (one call of fuction is 1000uS = 1ms)---'

Call Delayy(5)
If Flag = 1 Then
Led2 = Not Led2					    ' blink P1.6
Miliseconds = 0
Flag = 0
End If

Loop


End                                                           



------------------------------------------------------------------------------
subroutine Delayy
------------------------------------------------------------------------------


Sub Delayy(x As Integer)



Th0 = &HFC                                                'initialization registers for overflow:  65536 - Hex. FC17 (64535)= 1000 microseconds										  
Tl0 = &H17                                                    

Start Timer0						 'start timer

Incr Miliseconds					          'increment miliseconds


If Miliseconds = X Then                                 ' forwarded parameter x ( 10 or 5) 
Flag = 1

Stop Timer0						' timer stoped
End If

Return
End Sub							' ends subroutine
 
Last edited by a moderator:

Bump, nobody?

How can I know when registers TH0 and TL0 overflows?
There is in C language statement TF (TF=1,overflow occurred) but I can not find it in Bascom.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top