RSS

Programmable Countdown Timer

20 Jun

‘copyright                : (c) 1995-2005, MCS Electronics
‘purpose                  : Programmable Timer
‘micro                    : ATMEGA16
‘suited for demo          : yes
‘commercial addon needed  : no
‘use in simulator         : possible
‘eeprom memory usage      : no
‘——————————————————————————–
‘*******************************************************************************
$regfile = “m16def.dat”
$crystal = 8000000
‘ $sim
‘********************* LCD Configuration ***************************************
Config Lcd = 16 * 2
Config Lcdbus = 4
Config Lcdmode = Port
Config Lcdpin = Pin , Db4 = Portb.0 , Db5 = Portb.1 , Db6 = Portb.2 , Db7 = Portb.3 , E = Portc.5 , Rs = Portc.4
‘**************************Port Configuration **********************************
Config Pind.7 = Input                                       ‘SET/RESET
Config Pind.6 = Input                                       ‘UP (+)
Config Pind.5 = Input                                       ‘DOWN (-)
Config Pinc.0 = Output
‘****************************Variables******************************************
Dim H As Byte , M As Byte , S As Byte
Dim Ho As Byte , Mo As Byte , So As Byte
Dim Count As Byte
Dim Day As Integer , Dayo As Integer
‘————Original time look up variables
Ho = 0
Mo = 0
So = 0
Dayo = 0
‘————Set time  Variables
H = 0
M = 0
S = 50
Day = 0
‘**************************Timer Config and initialisations*********************
Config Timer1 = Timer , Prescale = 1
Stop Timer1

Enable Interrupts
Enable Ovf1

On Ovf1 Abhishek
‘*******************************************************************************
Cls
Lcd “Programmable ”
Lowerline
Lcd ”         Timer”
Wait 2

Startseret:
Stop Timer1
Ho = 0
Mo = 0
So = 0
Dayo = 0
Cls
Lcd “Please Set the”
Lowerline
Lcd “Alarming time >>”
Wait 1
‘—————————Set Days
Do
Set Portd.7
Set Portd.6
Set Portd.5

Cls
Lcd “Set Days====>”
Lowerline
Lcd Day
Waitms 120

If Pind.6 = 0 Then
Day = Day + 1
End If
If Pind.5 = 0 Then
Day = Day – 1
End If
If Day < 0 Or Day > 365 Then
Day = 0
End If
If Pind.7 = 0 Then
Exit Do
End If
Loop
‘—————————Set Hours
Do
Set Portd.7
Set Portd.6
Set Portd.5

Cls
Lcd “Set Hours====>”
Lowerline
Lcd H
Waitms 120

If Pind.6 = 0 Then
H = H + 1
End If
If Pind.5 = 0 Then
H = H – 1
End If
If H < 0 Or H > 24 Then
H = 0
End If
If Pind.7 = 0 Then
Exit Do
End If
Loop
‘—————————Set Minutes
Do
Set Portd.7
Set Portd.6
Set Portd.5

Cls
Lcd “Set Minutes====>”
Lowerline
Lcd M
Waitms 120

If Pind.6 = 0 Then
M = M + 1
End If
If Pind.5 = 0 Then
M = M – 1
End If
If M < 0 Or M > 59 Then
M = 0
End If
If Pind.7 = 0 Then
Exit Do
End If
Loop
‘—————————Set Seconds
Do
Set Portd.7
Set Portd.6
Set Portd.5

Cls
Lcd “Set Seconds====>”
Lowerline
Lcd S
Waitms 120

If Pind.6 = 0 Then
S = S + 1
End If
If Pind.5 = 0 Then
S = S – 1
End If
If S < 0 Or S > 59 Then
S = 0
End If
If Pind.7 = 0 Then
Exit Do
End If
Loop
‘—————————Startin Timer1 after takin all Values—————
Start Timer1
‘****************************Main Loop******************************************
Do
Set Portd.7
Set Portd.6
If Pind.7 = 0 And Pind.6 = 0 Then
Goto Startseret
End If

If Day = Dayo And H = Ho And M = Mo And S = So Then

Do

Set Portd.7
Set Portd.6
If Pind.7 = 0 And Pind.6 = 0 Then
Goto Startseret
Exit Do
End If

Lcd “Time Reached”
Lowerline
Lcd ”  Wake Up !!!”
Set Portc.0
Waitms 300
Cls
Reset Portc.0
Waitms 300
Loop

Else

Cls
Lcd “Set ” ; Day ; “-” ; H ; “:” ; M ; “:” ; S
Lowerline
Lcd “Or  ” ; Dayo ; “-” ; Ho ; “:” ; Mo ; “:” ; So
Waitms 100
End If

Loop

End
‘**************************ISR timer1*******************************************

Abhishek:

Count = Count + 1
If Count = 122 Then
        Count = 0
        So = So + 1

        If So = 60 Then
                  Mo = Mo + 1
                  So = 0
        End If

        If Mo = 60 Then
                  Ho = Ho + 1
                  Mo = 0
        End If

        If Ho = 24 Then
        Dayo = Dayo + 1
        Ho = 0
        So = 0
        Mo = 0
        End If
        If Dayo = 366 Then
        Dayo = 0
        Ho = 0
        Mo = 0
        So = 0
        End If
End If
Return

Advertisements
 
Leave a comment

Posted by on June 20, 2010 in AVR

 

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
%d bloggers like this: