RSS

Digital Clock v1.00 using Bascom and ATMEGA16

20 Jun

‘——————————————————————————–
‘Designer                 : Abhishek kumar
‘name                     : clock.bas
‘copyright                : (c) 1995-2005, MCS Electronics
‘purpose                  : Digital Clock with internal Clock Generator
‘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                                       ‘Setting
Config Pind.6 = Input                                       ‘UP (+)
Config Pind.5 = Input                                       ‘DOWN (-)
‘*******************************declaring subroutines***************************
Declare Sub Settin
‘************************Declaring variables************************************
Dim Count As Byte
Dim H As Byte , M As Byte , S As Byte
Dim Day As Byte , Month As Byte , Year As Integer , Hg As Byte
Dim X As Byte
Dim Z As Byte
Count = 0
H = 0
M = 0
S = 0
Day = 1
Month = 1
Year = 2000
X = 0
‘*******************Special Character definations*******************************
Deflcdchar 2 , 32 , 27 , 32 , 4 , 4 , 17 , 14 , 32          ‘ replace ? with number (0-7)
Deflcdchar 3 , 32 , 27 , 32 , 4 , 4 , 32 , 14 , 17          ‘ replace ? with number (0-7)
Deflcdchar 4 , 32 , 27 , 32 , 4 , 4 , 32 , 31 , 32          ‘ replace ? with number (0-7)
Deflcdchar 5 , 32 , 27 , 32 , 4 , 4 , 1 , 14 , 16           ‘ replace ? with number (0-7)
Deflcdchar 6 , 17 , 10 , 32 , 4 , 4 , 17 , 14 , 32          ‘ replace ? with number (0-7)
Deflcdchar 7 , 32 , 10 , 17 , 4 , 4 , 17 , 14 , 32          ‘ replace ? with number (0-7)
Deflcdchar 1 , 14 , 14 , 21 , 14 , 4 , 4 , 10 , 17          ‘ replace ? with number (0-7)
Deflcdchar 0 , 14 , 14 , 4 , 31 , 21 , 4 , 10 , 17          ‘ replace ? with number (0-7)
‘**************************Timer Config and initialisations*********************
Config Timer1 = Timer , Prescale = 1

Enable Interrupts
Enable Ovf1

On Ovf1 Abhishek
‘***********************Program Main Loop***************************************
Do

Set Portd.7
Set Portd.6
Set Portd.5
‘———————–Press Settin button (PIND.7)
If Pind.7 = 0 Then
Call Settin
End If
‘———————–Press UP button (PIND.6)
If Pind.6 = 0 Then
Cls
Lcd “AbHiShEk”
For Z = 1 To 10 Step 1
Shiftlcd Right
Waitms 200
Next Z
For Z = 1 To 10 Step 1
Shiftlcd Left
Waitms 200
Next Z

Cls
Lowerline
Lcd “ThE EViL GeNiUs”
For Z = 1 To 10 Step 1
Shiftlcd Right
Waitms 200
Next Z
For Z = 1 To 10 Step 1
Shiftlcd Left
Waitms 200
Next Z

Cls
Lcd “>>> ABHISHEK <<<”
Lowerline
Lcd ” The Evil Genius”
Wait 1

End If
‘———————–Press Down button (PIND.5)
If Pind.5 = 0 Then
Cls
Lcd “Digital Clock”
Lowerline
Lcd ”    By AbHiShEk”
Wait 2
End If
‘—————————–Normal Display Routine—————————-
If H >= 0 And H < 12 Then
    Cls
    Lcd ” ” ; Day ; “-” ; Month ; “-” ; Year ; ”   ” ; Chr(x)
    Lowerline
    Lcd ”  ” ; H ; “:” ; M ; “:” ; S ; ”  ” ; “AM” ; ”  ” ; Chr(x)
    Waitms 100
Else
    Hg = H – 12
    If Hg = 0 Then
    Hg = 12
    End If

    Cls
    Lcd ”  ” ; Day ; “-” ; Month ; “-” ; Year ; ”   ” ; Chr(x)
    Lowerline
    Lcd ”  ” ; Hg ; “:” ; M ; “:” ; S ; ”  ” ; “PM” ; ”  ” ; Chr(x)
    Waitms 100
End If

Loop
End
‘**********************Settings Subroutine**************************************
Sub Settin

Set Portd.7
Set Portd.6
Set Portd.5

‘——————-Set DAY
Do
Set Portd.7
Set Portd.6
Set Portd.5
Cls
Lcd “Set Day ====>”
Lowerline
Lcd Day
Waitms 100
If Pind.6 = 0 Then
Day = Day + 1
End If
If Pind.5 = 0 Then
Day = Day – 1
End If
If Pind.7 = 0 Then
Exit Do
End If
If Day > 31 Or Day < 1 Then
Day = 1
End If
Loop

‘——————-Set Month
Do
Set Portd.7
Set Portd.6
Set Portd.5
Cls
Lcd “Set Month ====>”
Lowerline
Lcd Month
Waitms 100
If Pind.6 = 0 Then
Month = Month + 1
End If
If Pind.5 = 0 Then
Month = Month – 1
End If
If Pind.7 = 0 Then
Exit Do
End If
If Month > 12 Or Month < 1 Then
Month = 1
End If
Loop

‘——————-Set Year
Do
Set Portd.7
Set Portd.6
Set Portd.5
Cls
Lcd “Set Year ====>”
Lowerline
Lcd Year
Waitms 100
If Pind.6 = 0 Then
Year = Year + 1
End If
If Pind.5 = 0 Then
Year = Year – 1
End If
If Pind.7 = 0 Then
Exit Do
End If
If Year > 3999 Or Year < 1700 Then
Year = 2010
End If
Loop

‘——————-Set Second
Do
Set Portd.7
Set Portd.6
Set Portd.5
Cls
Lcd “Set Second ====>”
Lowerline
Lcd S
Waitms 100
If Pind.6 = 0 Then
S = S + 1
End If
If Pind.5 = 0 Then
S = S – 1
End If
If Pind.7 = 0 Then
Exit Do
End If
If S > 59 Or S < 0 Then
S = 0
End If
Loop

‘——————-Set Minute
Do
Set Portd.7
Set Portd.6
Set Portd.5
Cls
Lcd “Set Minute ====>”
Lowerline
Lcd M
Waitms 100
If Pind.6 = 0 Then
M = M + 1
End If
If Pind.5 = 0 Then
M = M – 1
End If
If Pind.7 = 0 Then
Exit Do
End If
If M > 59 Or M < 0 Then
M = 0
End If
Loop

‘——————-Set Hour
Do
Set Portd.7
Set Portd.6
Set Portd.5
Cls
Lcd “Set Hour ====>”
Lowerline
Lcd H
Waitms 100
If Pind.6 = 0 Then
H = H + 1
End If
If Pind.5 = 0 Then
H = H – 1
End If
If Pind.7 = 0 Then
Exit Do
End If
If H > 24 Or H < 0 Then
H = 0
End If
Loop

End Sub

‘**********************Timer ISR (one second pulse)*****************************
Abhishek:

Count = Count + 1
If Count = 122 Then
        Count = 0
        S = S + 1
        X = X + 1

        If X = 8 Then
        X = 0
        End If

        If S = 60 Then
                  M = M + 1
                  S = 0
        End If

        If M = 60 Then
                  H = H + 1
                  M = 0
        End If
        If H = 24 Then
                  H = 0
                  M = 0
                  S = 0
                  Day = Day + 1
        End If

        If Day = 30 Then
                  Month = Month + 1
                  Day = 1
        End If

        If Month = 12 Then
                  Year = Year + 1
                  Month = 1
        End If

End If
Return

Advertisements
 
1 Comment

Posted by on June 20, 2010 in AVR

 

One response to “Digital Clock v1.00 using Bascom and ATMEGA16

  1. http://dbvehicleelectrics.wordpress.com/

    April 2, 2014 at 6:46 am

    When someone writes an piece of writing he/she keeps the
    thought of a user in his/her mind that how a user can be aware of
    it. So that’s why this paragraph is outstdanding. Thanks!

     

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: