View previous topic :: View next topic |
Author |
Message |
kimmi
Joined: 24 Feb 2006 Posts: 1922 Location: Denmark
|
Posted: Wed Mar 08, 2006 12:14 pm Post subject: M8 help !!!! Me Pls |
|
|
Hello Again all ...
Iīm working on a mega8 making a timer to run as interval but i canīt
find my way around this timer instru.(Grrrr)
It must worke like this :
While portd.6=1 'FROM MAIN to start the interval timer
interval 0,0 to 20.0 sec (potrd.4=1)
interval 0 to 240 sec (portd.4=0)
wend
hoto make this so i can use the data from lcd-menu
in the timer this must be done in background so the main program stil runs
' Snegl = the time portd.4=1
' inte = time portd.4=0
I have 4 buttons to controle this program
portd.1 to 4
'program snip ::::
$regfile = "m8def.dat"
$crystal = 4000000 '4 Mhz
'to setup the (snegl)time for interval in lcd-menu
Readeeprom Snegl , 01
If Portd.1 = 1 Then
Snegl = Snegl + 0.1
If Snegl > 240 Then Snegl = 240
Locate 2 , 8
Lcd " "
Waitms 100
Locate 2 , 8
Lcd Fusing(snegl , "###.#") ; " SEC"
Writeeeprom Snegl , 01
End If
If Portd.2 = 1 Then
While Portd.2 = 1
Snegl = Snegl - 0.1
If Snegl < 0.1 Then Snegl = 0.0
Locate 2 , 8
Lcd " "
Waitms 100
Locate 2 , 8
Lcd Fusing(snegl , "###.#") ; " SEC"
Writeeeprom Snegl , 01
Waitms 100
Wend
End If
If Snegl < 0.1 Then Snegl = 0.1
If Portd.4 = 1 Then
Goto main
End If
'********
'to setup the (inte)time for interval in lcd-menu time pord.4 = 0
Readeeprom inte , 05
If Portd.1 = 1 Then
inte = inte + 0.1
If inte > 240 Then inte = 240
Locate 2 , 8
Lcd " "
Waitms 100
Locate 2 , 8
Lcd Fusing(intel , "###.#") ; " SEC"
Writeeeprom inte , 05
End If
If Portd.2 = 1 Then
While Portd.2 = 1
inte = inte - 1
If inte < 1 Then inte = 1
Locate 2 , 8
Lcd " "
Waitms 100
Locate 2 , 8
Lcd Fusing(inte , "###.#") ; " SEC"
Writeeeprom inte , 05
Waitms 100
Wend
End If
If inte < 1 Then inte =1
If Portd.4 = 1 Then
Goto main
End If _________________ / Kim |
|
Back to top |
|
|
Luciano
Joined: 29 Nov 2004 Posts: 3149 Location: Italy
|
Posted: Wed Mar 08, 2006 3:07 pm Post subject: |
|
|
Hi,
You will need two LEDs.
Best regards,
Luciano
Code: |
$regfile = "m8def.dat"
$crystal = 4000000
$hwstack = 32
$swstack = 16
$framesize = 32
Config Pind.2 = Output ' I/O----470 ohm----LED----GND
Config Pind.3 = Output ' I/O----470 ohm----LED----GND
Config Timer1 = Timer , Prescale = 1
Timer1 = 61535
' Our 16-bit Timer/counter will count up to 65535 before overflowing to zero.
' At every overflow, a Timer interrupt occurs.
'
' If we preload the timer with a value, then we can define how long it takes to get
' from this value up to 65535. That way we can get the exact time we need.
' I our case this value will be 61535 because we need an interrupt every 1000 microseconds.
'
' By preloading the timer with the value 61535, an interrupt will occur after
' the timer has incremented 4000 times. At 4Mhz and with Prescale = 1, the timer
' will increment every 0.25 microsecond.
' So in our case, 0.25 microsecond * 4000 = 1000 microseconds (1 ms)
Dim Flash_led_after_ms As Long
On Timer1 My_timer1_int
Enable Interrupts
Enable Timer1
Flash_led_after_ms = 5000
Do
Toggle Portd.2 'LED
Waitms 300
If Flash_led_after_ms = 0 Then
Toggle Portd.3 'LED
Waitms 100
Toggle Portd.3 'LED
Waitms 100
Toggle Portd.3 'LED
Waitms 100
Toggle Portd.3 'LED
Flash_led_after_ms = 5000
End If
Loop
End
My_timer1_int: 'This interrupt routine is executed every 1000 microseconds.
Timer1 = 61535 ' reload the timer value
If Flash_led_after_ms > 0 Then
Decr Flash_led_after_ms
End If
Return
|
Last edited by Luciano on Thu Mar 09, 2006 3:30 pm; edited 2 times in total |
|
Back to top |
|
|
kimmi
Joined: 24 Feb 2006 Posts: 1922 Location: Denmark
|
Posted: Thu Mar 09, 2006 2:38 pm Post subject: bas file |
|
|
hi ...
I cant find a way to inplant the time from setup it is in 0.1 sec
her is my test program : _________________ / Kim |
|
Back to top |
|
|
Luciano
Joined: 29 Nov 2004 Posts: 3149 Location: Italy
|
Posted: Thu Mar 09, 2006 3:25 pm Post subject: |
|
|
Hi Kim,
Did you try my code?
(In my sample the possible range is from 1 ms up to 2147483647 ms).
Best regards,
Luciano |
|
Back to top |
|
|
kimmi
Joined: 24 Feb 2006 Posts: 1922 Location: Denmark
|
Posted: Thu Mar 09, 2006 3:42 pm Post subject: Hmm |
|
|
maby Iīm stupid but I canīt se howto do it proberly
_________________ / Kim |
|
Back to top |
|
|
kimmi
Joined: 24 Feb 2006 Posts: 1922 Location: Denmark
|
Posted: Thu Mar 09, 2006 3:43 pm Post subject: Hmm |
|
|
maby Iīm stupid but I canīt se howto do it proberly
_________________ / Kim |
|
Back to top |
|
|
kimmi
Joined: 24 Feb 2006 Posts: 1922 Location: Denmark
|
Posted: Thu Mar 09, 2006 5:20 pm Post subject: hey hey I think i got it |
|
|
hi maby this is the way to do it (like multitask)
see bas file
if not Damm .... _________________ / Kim |
|
Back to top |
|
|
|