View previous topic :: View next topic |
Author |
Message |
naseerak
Joined: 08 Nov 2008 Posts: 138
|
Posted: Tue Nov 10, 2015 8:18 am Post subject: Timer2 not working in real hardware.. |
|
|
Hi
I am using the following code having attached a 32.768khz crystal to pins 28,29 of atmega16, the code runs fine in Proteus but not working in real hardware as for incrementing of second minute and hour variable, this is a simple code where i want the time in minutes and not a real clock rather i want to get seconds and minutes to be displayed in 40X4 lcd..
'Procesor Identification ==============================
$regfile = "m16adef.dat"
$crystal = 8000000
$baud = 19200
$hwstack = 128
$swstack = 128
$framesize = 128
'Hardware Configuration ===============================
Config Aci = Off
Config Adc = Single , Prescaler = Auto , Reference = Avcc
Start Adc
Disable Jtag
'Disable 12c
Disable Twi
'Config Clock = Soft
Enable Interrupts
'RTC_Init
Config Timer2 = Timer , Prescale = 128
On Ovf2 Tim2_isr
Enable Ovf2
Assr.as2 = 1 'Timer2 in asynchronous mode
$lib "Lcd4e2.lib"
Config Lcd = 40 * 4
Mcusr = &H80
Ddrd = &B10110010
Ddrb = &B11111111
Ddrc = &B00111111
Ddra = &B00000000
Dim ___lcde As Byte
Dim Second As Byte
Dim Minut As Byte
Dim Hour As Byte
Dim Sec_flag As Byte
Dim Min_flag As Byte
Do
___lcde = 0
'Cls
Cursor Off
___lcde = 1
'Cls
Cursor Off
___lcde = 0
Locate 1 , 1
Lcd " CLOCK SYSTEM "
Locate 2 , 1
Lcd "HOUR " ; Hour
___lcde = 1
Locate 1 , 1
Lcd "MINUTS " ; Minut
Locate 2 , 1
Lcd "SECOND " ; Second
Loop
End
Tim2_isr:
Incr Second
If Second > 59 Then
Second = 0
Incr Minut
End If
If Minut > 59 Then
Minut = 0
Incr Hour
End If
If Hour > 23 Then
Hour = 0
End If
Sec_flag = 1
Return
(BASCOM-AVR version : 2.0.7.5 , Latest : 2.0.7.8 ) |
|
Back to top |
|
|
naseerak
Joined: 08 Nov 2008 Posts: 138
|
Posted: Tue Nov 10, 2015 8:32 am Post subject: |
|
|
the fuse settings are:
24 D9 |
|
Back to top |
|
|
MWS
Joined: 22 Aug 2009 Posts: 2262
|
Posted: Tue Nov 10, 2015 8:54 am Post subject: Re: Timer2 not working in real hardware.. |
|
|
MOD BY ADMIN
Would you mind to leave your religious stuff out of the forum? I'm a infidel and I feel insulted.
#ADMIN : This forum is not for sharing and discussing religion, politics and the weather. It also means that references to gods, prophets and other religious matters may not be posted. There are zillions forum where you can do that, but not here. Of course the exception is when you make something electronic with BASCOM like an electronic vote system or compass that shows you the east. |
|
Back to top |
|
|
naseerak
Joined: 08 Nov 2008 Posts: 138
|
Posted: Tue Nov 10, 2015 6:24 pm Post subject: |
|
|
as it has been MOD now lets come to the business.. |
|
Back to top |
|
|
naseerak
Joined: 08 Nov 2008 Posts: 138
|
Posted: Wed Nov 11, 2015 6:34 am Post subject: |
|
|
Ok it GOT it now lets come to my real problem |
|
Back to top |
|
|
Evert :-)
Joined: 18 Feb 2005 Posts: 2156
|
Posted: Wed Nov 11, 2015 8:30 pm Post subject: |
|
|
Try this.
If it's not working then most likely you have a problem with the hardware.
Are you using something like a breadboard? won't work on that (low freq crystal).
Code: |
$regfile = "m16adef.dat"
$crystal = 8000000
$baud = 19200
$hwstack = 40
$swstack = 40
$framesize = 40
Enable Interrupts
'[now init the clock]
Config Date = Mdy , Separator = / ' ANSI-Format
Config Clock = Soft 'this is how simple it is
'The above statement will bind in an ISR so you can not use the TIMER anymore!
'assign the date to the reserved date$
'The format is MM/DD/YY
Date$ = "11/11/05"
'assign the time, format in hh:mm:ss military format(24 hours)
'You may not use 1:2:3 !! adding support for this would mean overhead
'But of course you can alter the library routines used
Time$ = "23:59:50"
Do
Waitms 500
Print Date$ ; Spc(3) ; Time$
Loop
end
|
_________________ www.evertdekker.com Bascom code vault |
|
Back to top |
|
|
naseerak
Joined: 08 Nov 2008 Posts: 138
|
Posted: Thu Nov 12, 2015 5:34 pm Post subject: |
|
|
As I said earlier I dont want the time/date to be displayed I just want the counts of minuts.. |
|
Back to top |
|
|
EDC
Joined: 26 Mar 2014 Posts: 971
|
Posted: Sat Nov 14, 2015 10:36 am Post subject: |
|
|
Code: | $regfile = "m16adef.dat"
$crystal = 8000000
$baud = 19200
$hwstack = 40
$swstack = 40
$framesize = 40
Config Clock = Soft
'this create Int for Timer2 and hidden variables
'variables _sec, _min, _hour
' *** You can access them directly so where is the problem? ***
Dim Old_sec As Byte
Dim Old_min As Byte
Enable Interrupts
Do
'if mark for running time is needed
If Old_sec <> _sec Then
Old_sec = _sec
'this code is fired every second (if needed)
End If
If Old_min <> _min Then
Old_min = _min
'this code is fired every minute (if needed)
End If
' *** AT ANY MOMENT YOU CAN SET VARIABLES TO ZERO ***
' _sec = 0
' _min = 0
' _hour = 0
Loop
End |
|
|
Back to top |
|
|
|