SMK Binawiyata Sragen

  • This is default featured slide 1 title

    Go to Blogger edit html and find these sentences.Now replace these sentences with your own descriptions.This theme is Bloggerized by Lasantha Bandara - Premiumbloggertemplates.com.

  • This is default featured slide 2 title

    Go to Blogger edit html and find these sentences.Now replace these sentences with your own descriptions.This theme is Bloggerized by Lasantha Bandara - Premiumbloggertemplates.com.

  • This is default featured slide 3 title

    Go to Blogger edit html and find these sentences.Now replace these sentences with your own descriptions.This theme is Bloggerized by Lasantha Bandara - Premiumbloggertemplates.com.

  • This is default featured slide 4 title

    Go to Blogger edit html and find these sentences.Now replace these sentences with your own descriptions.This theme is Bloggerized by Lasantha Bandara - Premiumbloggertemplates.com.

  • This is default featured slide 5 title

    Go to Blogger edit html and find these sentences.Now replace these sentences with your own descriptions.This theme is Bloggerized by Lasantha Bandara - Premiumbloggertemplates.com.

Stop Watch dengan Atmega32

Rangkaian :
Code List :
'Program Stopwatch
$regfile = "m32def.dat"
$crystal = 12000000

'deklarasi LCD
Config Lcdpin = Pin , Db4 = Portc.5 , Db5 = Portc.4 , Db6 = Portc.3 , Db7 = Portc.2 , E = Portc.6 , Rs = Portc.7
Config Lcd = 16 * 2
Cursor Off
Cls

'Deklarasi variabel
Dim Pengali As Word
Dim Detik_1 As Byte
Dim Detik As Byte
Dim Menit As Byte
Dim Jam As Word
Dim Status As Byte
Dim Status2 As Byte
Dim Status3 As Byte

'konfigurasi timer
Config Timer0 = Timer , Prescale = 256
Config Debounce = 30
'setting porta
Ddra = 0
Porta = 255

'pengaktifan interupsi timer
On Ovf0 Int_timer0

'penggantian nama variabel
Pin_reset Alias Pina.2
Pin_on_off Alias Pina.1
Pin_capture Alias Pina.0

'setting nilai awal variabel
'Pin_reset = 1
'Pin_on_off = 1
'Pin_capture = 1
Status = 0
Status2 = 1


'pengaktifan timer0
Enable Timer0

Do
 If Pin_capture = 0 Then
   Bitwait Pin_capture , Set
   Incr Status2
   Cls
   Locate 1 , 1
   Lcd "BINA ELEKTRONIK"
   Locate 2 , 1
   Lcd Jam ;
   Locate 2 , 3
   Lcd ":" ;
   Locate 2 , 4
   Lcd Menit ;
   Locate 2 , 6
   Lcd ":" ;
   Locate 2 , 7
   Lcd Detik ;
   Locate 2 , 9
   Lcd ":" ;
   Locate 2 , 10
   Lcd Detik_1 ;
   Locate 2 , 12
   Lcd Capture1
 End If
 If Status2 = 2 Then
   Locate 2 , 13
   Lcd "SLIP"
   End If
If Status2 = 2 Then
   Locate 2 , 11
   Lcd "       "
   End If
 If Pin_on_off = 0 Then
   Bitwait Pin_on_off , Set
   Incr Status

 End If

 If Pin_reset = 0 Then
      Pengali = 0
      Detik_1 = 00
      Locate 2 , 1
      Lcd "00"
      Locate 2 , 4
      Lcd "00"
      Locate 2 , 7
      Lcd "00"
      Locate 2 , 10
      Lcd "00"
      Detik = 00
      Menit = 00
      Jam = 00
 End If


 If Status > 2 Then
   Status = 1
 End If

 If Status2 > 2 Then
   Status2 = 1
   Cls
 End If

 If Status = 1 Then Enable Interrupts
 If Status = 2 Then Disable Interrupts

 If Status2 < 2 Then
   Locate 1 , 1
   Lcd "STOPWATCH"
   Locate 2 , 1
   Lcd Jam ;
   Locate 2 , 3
   Lcd ":" ;
   Locate 2 , 4
   Lcd Menit ;
   Locate 2 , 6
   Lcd ":" ;
   Locate 2 , 7
   Lcd Detik ;
   Locate 2 , 9
   Lcd ":" ;
   Locate 2 , 10
   Lcd Detik_1 ;
   End If
 If Status = 2 Then                                         ' tambahan
   Locate 2 , 13                                            ' tambahan
   Lcd "STOP"                                               ' tambahan
   End If                                                   ' tambahan
 If Status = 1 Then                                         ' tambahan
   Locate 2 , 13                                            ' tambahan
   Lcd ">>>>"                                               ' tambahan
 End If



Loop

Int_timer0:
   Incr Pengali
   If Pengali > 0 Then
      Pengali = 0
      Incr Detik_1
   End If
   If Detik_1 > 99 Then
      Detik_1 = 0
      Incr Detik
   End If
   If Detik > 59 Then
      Detik = 0
      Incr Menit
   End If
   If Menit > 59 Then
      Menit = 0
      Incr Jam
   End If
   Return
Share:

Pengendali motor stepper dengan keypad

Rangkaian ;

Code List :

$regfile = "m16def.dat"
$crystal = 1000000

Config Kbd = Portb
Config Lcd = 16 * 2
Config Lcdpin = Pin , Db4 = Portc.4 , Db5 = Portc.5 , Db6 = Portc.6 , Db7 = Portc.7 ,Rs = Portc.0 , E = Portc.1
Config Portd = Output
Config Porta = Input

Dim A As Byte , B As Byte , Key As Byte , C As Byte , D As Byte , E As Byte

Cls
Cursor Off

B = 0
D = 1

Q:
Locate 1 , 1
Lcd "Putaran :"
Locate 2 , 1
Lcd "Kecept  :"
Do
'************Read Keyboard
A = Getkbd()
If A > 15 Then
   Goto Q
Else
   Key = Lookup(a , Dta)
     If Key <= 9 Then
           B = B * 10
           B = B + Key
'*************Direction
          If D = 0 Then Lcd B
                   Waitms 270
               Elseif Key = 10 Then
                   Locate 1 , 11
                   Lcd "Kiri"
                   C = 1
                   D = 0
                   B = 0

               Elseif Key = 11 Then
                  Locate 1 , 11
                  Lcd "Kanan"
                  C = 2
                  D = 0
                  B = 0
'****************reset
               Elseif Key = 13 Then
                  Cls
                  D = 1
                  B = 0
                  Portd.0 = 0
                  Portd.1 = 0
                  Waitms 50
                  Goto Q
'****************Enter key
               Elseif Key = 14 Then
                   If D = 0 Then
                       Select Case C
                          Case 1 : Gosub R
                          Case 2 : Gosub T
                       End Select

                   End If
         End If

End If

Wait 1

Loop

End

Dta:
Data 7 , 8 , 9 , 10 , 4 , 5 , 6 , 11 , 1 , 2 , 3 , 12 , 13 , 0 , 14 , 15

R:
Do
Portd = &B00000001 : Waitms B
Portd = &B00000011 : Waitms B
Portd = &B00000010 : Waitms B
Portd = &B00000110 : Waitms B
Portd = &B00000100 : Waitms B
Portd = &B00001100 : Waitms B
Portd = &B00001000 : Waitms B
Portd = &B00001001 : Waitms B
  If Pina.0 = 1 Then
      Locate 2 , 1
      Lcd "Kecept:"
      B = 0
      Lcd B ; "          "
      Return
  End If

Loop

T:
Do
Portd = &B00001001 : Waitms B
Portd = &B00001000 : Waitms B
Portd = &B00001100 : Waitms B
Portd = &B00000100 : Waitms B
Portd = &B00000110 : Waitms B
Portd = &B00000010 : Waitms B
Portd = &B00000011 : Waitms B
Portd = &B00000001 : Waitms B
   If Pina.0 = 1 Then
       Locate 2 , 1
       Lcd "Kecept:"
       B = 0
       Lcd B ; "          "
       Return
   End If

Loop
Share:

Program menampilkan penekanan tombol dengan display led

Rangkaian :



Code List :
'===================================================
'Program Saklar_1.bas
'Program untuk menampilkan kondisi saklar pada LED
'===================================================
Saklar Alias P2
Led Alias P0
Do
If Saklar = &HFF Then
Led = &HFF
Elseif Saklar = &HFE Then
Led = &HAA
Else
Led = 0
End If
Loop
End
Share:

Counter Up 00 - 99

Skemantik Counter Up 00-99



Souce Codenya :
'****************************************************************
'*  Name    : 59sec_Counter.BAS                                 *
'*  Author  : Likno                                             *
'*  Date    : 25.03.2012                                        *
'*  Version : 1.0.1                                             *
'*  Notes   :                                                   *
'*          :                                                   *
'****************************************************************
@ Device Xt_osc , Wdt_off , Pwrt_on , Protect_off

Display Var Word
Counter Var Byte
Doonce Var Bit
Pbup Var Porta.0
Pbdn Var Porta.1

Trisa = 011
Trisb = 000000
Porta = 0
Portb = 0

Doonce = 0
Counter = 0

Hours Var Byte                                             
Minutes Var Byte                                           
Seconds Var Byte                                          
Ticks Var Byte                                             
U_flag Var Byte                                           
T0ie Var Intcon.5                                         
T0if Var Intcon.2                                        
Gie Var Intcon.7                                           
Ps0 Var Option_reg.0                                      
Ps1 Var Option_reg.1                                     
Ps2 Var Option_reg.2                                      
Psa Var Option_reg.3                                     
        ' (0= assigned to oscillator)
T0cs Var Option_reg.5                                     
        ' (1=External PORTA.4)
 Hours = 0                                                 
 Minutes = 0
 Seconds = 0
 Ticks = 0
 U_flag = 1                                               


Gie = 0                                                    
While Gie = 1 : Gie = 0 : Wend                             
Psa = 0                                                 
Ps0 = 1                                                   
Ps1 = 0                                                   
Ps2 = 1                                                    
T0cs = 0                                                   
Tmr0 = 0                                                   
T0ie = 1                                                   
Gie = 1                                                    

On Interrupt Goto Clock_int                                

Main:

    If U_flag = 1 Then                                     
        U_flag = 0                                      
        Counter = Seconds
        Display.byte0 =(counter Dig 1) << 4
        Display.byte1 =(counter Dig 0)
        Display = Display >> 4
        Portb = Display.byte0
    End If

Goto Main



Disable                                                    
Clock_int:
 Ticks = Ticks + 1                                         
 If Ticks <= 61 Then Clock_exit                            

' One second has elasped so update the time variables
 Ticks = 0                                                 
 Seconds = Seconds + 1                                     
 If Seconds >= 60 Then                                     
 Seconds = 0                                               
 Minutes = Minutes + 1                                     
 If Minutes >= 60 Then                                     
 Minutes = 0                                               
 Hours = Hours + 1                                         
 If Hours >= 23 Then                                       
 Hours = 0                                                 
 End If
 End If
 End If
 U_flag = 1                                                

Clock_exit:
 T0if = 0                                                  
Resume                                                     
Enable                                                     

End
Share:

Pengaturan Kecepatan Motor DC Dengan Mikrokontroler dengan BASCOM AVR

Penggunaan motor DC dewasa ini sudah sangatlah umum, salah satu kelebihan motor DC adalah relatif gampang didapat dan mudah diatur kecepatan putarnya. Secara umum pengaturan kecepatan motor DC adalah dengan menggunakan cara analog. Pada artikel kali ini akan dibahas contoh cara mengatur kecepatan motor DC dengan menggunakan mikrokontroller.
Mikrokontroler yang digunakan adalah Tipe AVR dari Atmel seperti mikrokontroler Atmega 8535, 16, 32. Informasi kecepatan motor akan ditampilkan pada modul LCD HD4480. Sedangkan sebagai driver motor menggunakan modul driver motor IC L298.
Cara pengaturan kecepatan yang digunakan adalah dengan menggunakan teknik PWM (Pulse Width Modulation), salah satu teknik untuk mengatur kecepatan motor DC yang umum digunakan. Dengan menggunakan PWM kita dapat mengatur kecepatan yang diinginkan dengan mudah. Teknik PWM untuk pengaturan kecepatan motor adalah, pengaturan kecepatan motor dengan cara merubah-rubah besarnya duty cycle pulsa. Pulsa yang yang berubah ubah duty cycle-nya inilah yang menentukan kecepatan motor. Besarnya amplitudo dan frekuensi pulsa adalah tetap, sedangkan besarnya duty cycle berubah-ubah sesuai dengan kecepatan yang diinginkan, semakin besar duty cylce maka semakin cepat pula kecepatan motor, dan sebaliknya semakin kecil duty cycle maka semakin pelan pula kecepatan motor. Sebagai contoh bentuk pulsa yang dikirimkan adalah seperti pada gambar 1, pulsa kotak dengan duty cycle pulsa 50%. Sedangkan sebagai contoh bentuk pulsa PWM adalah seperti pada gambar 2.
Seperti pada gambar 1, semakin besar duty cycle pulsa kotak, maka semakin lama pula posisi logika high. Jika motor diatur agar berjalan ketika diberi logika high, maka jika memberi pulsa seperti pada gambar 1 diatas, maka motor akan berada pada kondisi “nyala-mati-nyala-mati” sesuai dengan bentuk pulsa tersesebut. Semakin lama motor berada pada kondisi “nyala” maka semakin cepat pula kecepatan motor tersebut. Motor akan berputar dengan kecepatan maksimum jika mendapat pulsa dengan duty cycle 100%. Dengan kata lain motor mendapat logika high terus menerus.
Dengan mengatur besarnya duty cycle pulsa kotak yang dikirimkan, kita dapat mengatur banyaknya logika high yang diberikan pada motor, dengan kata lain mengatur lamanya waktu motor untuk berputar dalam satu periode pulsa. Jika lamanya waktu motor untuk berputar dalam satu periode pulsa ini berubah maka kecepatan purtaran motor juga akan berubah, sesuai dengan duty cycle atau waktu motor untuk berputar dalam satu periode pulsa.
===============================================================
PENGATURAN KECEPATAN MOTOR DC Berbasis Atmega8535
Skema dengan proteus:

Hasil simulasi dengan proteus:

Program Pengaturan Kecepatan Motor DC dengan Bascom AVR

1 $regfile = “m8535.dat”   ’menggunakan Atmega8535 sebagai preprosesor
  2 $crystal = 12000000      ’menggunakan crystal clock 12 MHz
  3 $eeprom                  'menggunakan fasilitas eeprom Atmega8535
  4
  5 ‘—————————inisialisasi lcd————————————
  6
  7 Config Lcdpin = Pin , Db4 = Portc.4 , Db5 = Portc.5 , Db6 = Portc.6 , Db7 = Portc.7 , E = Portc.2 , Rs = Portc.0
  8 Config Lcd = 16 * 2 : Cursor Off
  9
 10 ‘—————————inisialisasi pwm———————————–
 11
 12 Config Timer1 = Pwm , Pwm = 10 , Prescale = 64 , Compare A Pwm = Clear Up , Compare B Pwm = Clear Up       ‘pwm dengan settingan fast pwm 10 bit
 13
 14 ‘—————————inisialisasi port——————————–
 15
 16 ‘inisialisasi tombol
 17 Config Portb = Input
 18
 19 ‘—————————pull up internal——————————–
 20
 21 Portb.0 = 1
 22 Portb.1 = 1
 23 Portb.2 = 1
 24 Portb.3 = 1
 25 Config Portd = Output
 26alias logika motor
 27 M1a Alias Portd.0
 28 M1b Alias Portd.1
 29 M2a Alias Portd.2
 30 M2b Alias Portd.3
 31
 32 ‘——————————alias——————————————–
 33
 34alias tombol
 35 Sw_ok Alias Pinb.3
 36 Sw_cancel Alias Pinb.2
 37 Sw_down Alias Pinb.1
 38 Sw_up Alias Pinb.0
 39
 40 ‘——————————————————————————-
 41
 42 Dim Pwm As Integer
 43 Dim Pwm_eprom As Eram Integer
 44 Home
 45 Lcd “Fahmizal_dte2006″
 46 Lowerline
 47 Lcd “Cek fungsi PWM”
 48 Wait 1
 49
 50 Do
 51 Pwm = Pwm_eprom
 52 If Sw_up = 0 Then : Incr Pwm : Waitms 10
 53 End If
 54 If Sw_down = 0 Then : Decr Pwm : Waitms 10
 55 End If
 56 If Pwm > 1023 Then : Pwm = 0 : Waitms 10
 57 End If
 58 If Pwm < 0 Then : Pwm = 1023 : Waitms 10
 59 End If
 60 Pwm_eprom = Pwm
 61 Cls
 62
 63 Home
 64 Lcd “tes uji pwm”
 65 Lowerline
 66 Reset M1a
 67 Reset M2a
 68 Set M1b
 69 Set M2b
 70 Pwm1a = Pwm
 71 Pwm1b = Pwm
 72 Lcd “nilai pwm:” ; Pwm1a : Waitms 100
 73 Loop
 74 End
Share:

Jam Digital dengan Mode 12/24

Rangkaian :

Source Code : Bascom AVR
$regfile = "m8def.dat"
$crystal = 1000000
'------------------------  lcd -----------------------------------------------
Config Lcd = 16 * 2
Config Lcdpin = Pin , Rs = Pind.0 , E = Pind.1 , Db4 = Pind.2 , Db5 = Pind.3 , Db6 = Pind.4 , Db7 = Pind.5
Cls

'---------------------------  ds 1307 -----------------------------------------
$lib "ds1307clock.lib"
'configure the scl and sda pins
Config Sda = Portd.7
Config Scl = Portd.6
'address of ds1307
Const Ds1307w = &HD0                                        ' Addresses of Ds1307 clock
Const Ds1307r = &HD1
'------------------------------ key --------------------------------------------
Config Pinc.1 = Input
Config Pinc.2 = Input
Config Pinc.3 = Input
Config Pinc.4 = Input
'------------------------------------------------------------------------------
Config Debounce = 30

Dim A As Byte , B As Byte , Data1 As Byte , C As Byte

Dim Seco As Byte , Mine As Byte , Hour As Byte

'----------------------------------------------------------------------------
Cursor Off
'-----------------------------
Cls
Locate 1 , 6
Lcd "Hello"
Locate 2 , 1
Lcd "WWW.elec4u.ir"
Wait 2

For A = 1 To 15
 Shiftlcd Left
Waitms 300
Next

Cls
'-------------------------------------------------------------------------------
Main:
Do
         Gosub Ds1307
         Gosub 24_12
         Gosub Chekkey

Loop
'-------------------------------------------------------------------------------
Ds1307:
        I2cstart                                            ' Generate start code
        I2cwbyte Ds1307w                                    ' send address
        I2cwbyte 0                                          ' start address in 1307
        I2cstart                                            ' Generate start code
        I2cwbyte Ds1307r                                    ' send address
        I2crbyte Seco , Ack                                 'sec
        I2crbyte Mine , Ack                                 ' MINUTES
        I2crbyte Hour , Nack                                ' Hours
        I2cstop

        Seco = Makedec(seco) : Mine = Makedec(mine) : Hour = Makedec(hour)

        If Seco > 59 Then Seco = 0
        If Mine > 59 Then Mine = 0
        If Hour > 23 Then
        Hour = 0
        Gosub Seco
        End If

Return
'-------------------------------------------------------------------------------
 24_12:
 If Pinc.4 = 1 Then Gosub Disply_24
 If Pinc.4 = 0 Then Gosub Disply_12
 Return
'-------------------------------------------------------------------------------
Disply_24:

         Locate 1 , 1
         Lcd "Time = " ; Hour ; ":" ; Mine ; ":" ; Seco ; "      "
         Locate 2 , 6
         Lcd "(24)"
Return

'-------------------------------------------------------------------------------
Disply_12:

         If Hour = 0 Then Hour = 12
         If Hour > 12 Then Hour = Hour - 12

         Locate 1 , 1
         Lcd "Time = " ; Hour ; ":" ; Mine ; ":" ; Seco ; "      "
         Locate 2 , 6
         Lcd "(12)"
Return
'-------------------------------------------------------------------------------
Chekkey:

         Debounce Pinc.1 , 0 , Seco , Sub
         Debounce Pinc.2 , 0 , Mine , Sub
         Debounce Pinc.3 , 0 , Hour , Sub

Return
'---------------------------------------------
Seco:
         Incr Seco
         If Seco > 59 Then Seco = 0
         Seco = Makebcd(seco)
         I2cstart                                           ' Generate start code
         I2cwbyte Ds1307w                                   ' send address
         I2cwbyte 0                                         ' starting address in 1307
         I2cwbyte Seco
         I2cstop
Return

'-------------------------------------
Mine:
         Incr Mine
         If Mine > 59 Then Mine = 0
         Mine = Makebcd(mine)
         I2cstart                                           ' Generate start code
         I2cwbyte Ds1307w                                   ' send address
         I2cwbyte 1                                         ' starting address in 1307
         I2cwbyte Mine
         I2cstop
Return
'-------------------------------------

Hour:
         Incr Hour
         If Hour > 23 Then Hour = 0
         Hour = Makebcd(hour)
         I2cstart                                           ' Generate start code
         I2cwbyte Ds1307w                                   ' send address
         I2cwbyte 2                                         ' starting address in 1307
         I2cwbyte Hour
         I2cstop

Return
'-------------------------------------

End
Share:

Jam Digital menggunakan Mikro ATMega8 dan Bahasa BASCOM-AVR

Belajar menggunakan LCD dengan ATMega8535 tidaklah sulit, dengan menggunakan bahasa Bascom AVR hal ini menjadi mudah dilakukan terutama bagi pemula. Berikut adalah rangkaian konfigurasi pin pada mikro ATMega8535 dan contoh program yang dapat dicoba. Selamat Mencoba.

Gambar Rangkaian :

Rangkaian Tampilan LCD.
Kode Bascom AVR


1 $regfile = "m8def.dat"
2 $crystal = 1000000
3 '------------------------  lcd -----------------------------------------------
4 Config Lcd = 16 * 2
5 Config Lcdpin = Pin , Rs = Pind.0 , E = Pind.1 , Db4 = Pind.2 , Db5 = Pind.3 , Db6 = Pind.4 , Db7 = Pind.5
6 Cls
7 
8 '---------------------------  ds 1307 -----------------------------------------
9 $lib "ds1307clock.lib"
10 'configure the scl and sda pins
11 Config Sda = Portd.7
12 Config Scl = Portd.6
13 'address of ds1307
14 Const Ds1307w = &HD0                                        ' Addresses of Ds1307 clock
15 Const Ds1307r = &HD1
16 '------------------------------ key --------------------------------------------
17 Config Pinc.1 = Input
18 Config Pinc.2 = Input
19 Config Pinc.3 = Input
20 Config Pinc.4 = Input
21 '------------------------------------------------------------------------------
22 Config Debounce = 30
23 
24 Dim A As Byte , B As Byte , Data1 As Byte , C As Byte
25 
26 Dim Seco As Byte , Mine As Byte , Hour As Byte
27 
28 '----------------------------------------------------------------------------
29 Cursor Off
30 '-----------------------------
31 Cls
32 Locate 1 , 1
33 Lcd "Jam Digital LCD"
34 Locate 2 , 1
35 Lcd "Bina Project"
36 Wait 2 

37 
38 For A = 1 To 15
39  Shiftlcd Left
40 Waitms 30
41 Next
42 
43 Cls
44 '-------------------------------------------------------------------------------
45 Main:
46 Do
47          Gosub Ds1307
48          Gosub 24_12
49          Gosub Chekkey
50 
51 Loop
52 '-------------------------------------------------------------------------------
53 Ds1307:
54         I2cstart                                            ' Generate start code
55         I2cwbyte Ds1307w                                    ' send address
56         I2cwbyte 0                                          ' start address in 1307
57         I2cstart                                            ' Generate start code
58         I2cwbyte Ds1307r                                    ' send address
59         I2crbyte Seco , Ack                                 'sec
60         I2crbyte Mine , Ack                                 ' MINUTES
61         I2crbyte Hour , Nack                                ' Hours
62         I2cstop
63 
64         Seco = Makedec(seco) : Mine = Makedec(mine) : Hour = Makedec(hour)
65 
66         If Seco > 59 Then Seco = 0
67         If Mine > 59 Then Mine = 0
68         If Hour > 23 Then
69         Hour = 0
70         Gosub Seco
71         End If 

72 
73 Return
74 '-------------------------------------------------------------------------------
75  24_12:
76  If Pinc.4 = 1 Then Gosub Disply_24
77  If Pinc.4 = 0 Then Gosub Disply_12
78  Return
79 '-------------------------------------------------------------------------------
80 Disply_24:
81 
82          Locate 1 , 1
83          Lcd "Jam = " ; Hour ; ":" ;
84          If Mine < 10 Then
85             Lcd "0" ; Mine ; ":" ;
86          Else
87             Lcd Mine ; ":" ;
88          End If
89 
90          If Seco < 10 Then
91             Lcd "0" ; Seco
92          Else 

93             Lcd Seco
94          End If
95 
96          Locate 2 , 6
97          Lcd "(24 Jam)"
98 
99 Return
100 
101 '-------------------------------------------------------------------------------
102 Disply_12:
103 
104          If Hour = 0 Then Hour = 12
105          If Hour > 12 Then Hour = Hour - 12
106
107          Locate 1 , 1
108          Lcd "Jam = " ; Hour ; ":" ;
109          If Mine < 10 Then
110             Lcd "0" ; Mine ; ":" ;

111          Else
112             Lcd Mine ; ":" ;
113          End If
114
115          If Seco < 10 Then
116             Lcd "0" ; Seco
117          Else
118             Lcd Seco
119          End If
120
121          Locate 2 , 6
122          Lcd "(12 Jam)"
123 Return
124 '-------------------------------------------------------------------------------
125 Chekkey:
126
127          Debounce Pinc.1 , 0 , Seco , Sub
128          Debounce Pinc.2 , 0 , Mine , Sub
129          Debounce Pinc.3 , 0 , Hour , Sub
130 
131 

132 Return
133 '---------------------------------------------
134 Seco:
135          Incr Seco
136          If Seco > 59 Then Seco = 0

137          Seco = Makebcd(seco)
138          I2cstart                                           ' Generate start code
139          I2cwbyte Ds1307w                                   ' send address
140          I2cwbyte 0                                         ' starting address in 1307
141          I2cwbyte Seco
142          I2cstop
143 Return
144
145 '-------------------------------------
146 Mine:

147          Incr Mine
148          If Mine > 59 Then Mine = 0
149          Mine = Makebcd(mine)
150          I2cstart                                           ' Generate start code
151          I2cwbyte Ds1307w                                   ' send address
152          I2cwbyte 1                                         ' starting address in 1307
153          I2cwbyte Mine
154          I2cstop
155 Return
Share:

Jam Digital dengan Alarm

Gamabar Rangkaian dengan simulator Proteus :


Source Code *asm
; *** File Name: CLOCK.ASM
; *** Project: Programmable Digital Clock with Alarm
; *** Author: Suparno, M.Pd
; *** Date: 26/03/2011
; *** Processor: Atmel AT89C51 Microcontroller (Compatible With MCS-51)
; *** Timekeeper: DS1307 I2C Serial Timekeeper IC
; *** Display: 16 characters x 2 lines LCD
;**************************************************************
; LCD Connections
LCD     DATA     P2         ; define LCD data port on port 1
Busy    BIT      LCD.7      ; define LCD busy flag
EN      BIT      P3.5       ; define LCD enable pin on port 2.2
RW      BIT      P3.6       ; define LCD register select pin on port 2.0
RS      BIT      P3.7       ; define LCD read/write pin on port 2.1
;**************************************************************
; KEYS
UP      BIT      P1.3
DN      BIT      P1.2
Rel_Set BIT      P3.4
T_Set   BIT      P3.2
A_Set   BIT      P3.3
;**************************************************************
Rel_Out BIT      P1.4
;**************************************************************
; I2C Connections
SCL     BIT      P1.0       ; I2C serial clock line
SDA     BIT      P1.1       ; I2C serial data line
;**************************************************************
; Slave Address
SAW     EQU      0D0H       ; Slave address for write (DS1307)
SAR     EQU      0D1H       ; Slave address for read (DS1307)
;**************************************************************
BitCnt  DATA     20H        ; BIT COUNTER FOR I2C ROUTINES
Sec     DATA     21H        ; SECONDS STORAGE RAM
Min     DATA     22H        ; MINUTES STORAGE RAM
Hour    DATA     23H        ; HOURS STORAGE RAM
Day     DATA     24H        ; DAY STORAGE RAM
Date    DATA     25H        ; DATE STORAGE RAM
Month   DATA     26H        ; MONTH STORAGE RAM
Year    DATA     27H        ; YEAR STORAGE RAM
SQW     DATA     28H        ; SQUARE-WAVE CONTROL
AL_Hour DATA     29H        ; ALARM HOURS STORAGE RAM SPACE
AL_Min  DATA     2AH        ; ALARM MINUTES STORAGE RAM SPACE
Rel_H   DATA     2BH        ; RELAY HOURS STORAGE RAM SPACE (FOR ON)
Rel_M   DATA     2CH        ; RELAY MINUTES STORAGE RAM SPACE (FOR ON)
RH_Off  DATA     2DH        ; RELAY HOURS STORAGE RAM SPACE (FOR OFF)
RM_Off  DATA     2EH        ; RELAY MINUTES STORAGE RAM SPACE (FOR OFF)
Flags   DATA     2FH        ; FLAGS
AL_Flag BIT      Flags.0    ; ALARM FLAG
RL_Flag BIT      Flags.1    ; RELAY TIMER FLAG
RL_On   BIT      FlagS.2
;**************************************************************
;                       ***MACRO'S***
I2C_Delay  MACRO
        NOP
           ENDM
;--------------------------------------------------------------
SCLHigh    MACRO
        SETB    SCL
        JNB     SCL,$
           ENDM
;--------------------------------------------------------------
D_Str      MACRO
        ACALL    Command
        LCALL    Disp_Char
           ENDM
;--------------------------------------------------------------
CLR_LCD    MACRO
        MOV      A,#01H
        ACALL    Command
           ENDM
;**************************************************************
ORG     0000H
;--------------------------------------------------------------
        CLR      AL_Flag
        CLR      RL_Flag
        CLR      RL_On
        MOV      SP,#2FH
        MOV      SQW,#80H
        ACALL    SQW_W
        ACALL    I2C_Start
        MOV      A,#SAW
        ACALL    I2C_Write
        MOV      A,#3FH
        ACALL    I2C_Write
        ACALL    I2C_Start
        MOV      A,#SAR
        ACALL    I2C_Write
        ACALL    I2C_Read_Last
        ACALL    I2C_Stop
        CJNE     A,#'~',INIT
        LJMP     LCD_I
;--------------------------------------------------------------
INIT:   ACALL    I2C_Start
        MOV      A,#SAW
        ACALL    I2C_Write
        MOV      A,#3FH
        ACALL    I2C_Write
        MOV      A,#'~'
        ACALL    I2C_Write
        MOV      A,#00H
        ACALL    I2C_Write
        ACALL    I2C_Stop
        SJMP     LCD_I
;--------------------------------------------------------------
RTC_Reset:
        MOV      R0,#21H
        MOV      R6,#07H
        ACALL    I2C_Start
 MOV      A,#SAW
 ACALL    I2C_Write
 MOV      A,#00H
 ACALL    I2C_Write
Loop1: MOV      A,@R0
 ACALL    I2C_Write
 INC      R0
 DJNZ     R6,Loop1
 ACALL    I2C_Stop
        RET
;--------------------------------------------------------------
AL_Off: CLR      AL_Flag
        MOV      SQW,#80H
        ACALL    SQW_W
        CLR_LCD
        MOV      A,#84H
        D_Str
        DB       'Alarm Off!',0
        MOV      A,#82H
        ACALL    Command
        MOV      A,#01H
        ACALL    Data_Disp
        ACALL    Delay
        ACALL    RL_Logo
        SJMP     Main
;--------------------------------------------------------------
Alarm_Set:
        JB       AL_Flag,AL_Off
        CLR_LCD
        MOV      A,#84H
        D_Str
        DB       'Set Alarm',0
        MOV      A,#82H
        ACALL    Command
        MOV      A,#01H
        ACALL    Data_Disp
        ACALL    Delay
        AJMP     AH
;--------------------------------------------------------------
LCD_I:  ACALL    LCD_Initial
        ACALL    CGR
;--------------------------------------------------------------
Main:   ACALL    Disp_C
Start:  ACALL    Key_Scan
Back1:  MOV      R0,#21H
        MOV      R1,#0DH
        ACALL    I2C_Start
        MOV      A,#SAW
        ACALL    I2C_Write
        MOV      A,#00H
        ACALL    I2C_Write
        ACALL    I2C_Start
        MOV      A,#SAR
        ACALL    I2C_Write
Loop:   ACALL    I2C_Read
        DJNZ     R1,Loop
        ACALL    I2C_Read_Last
        ACALL    I2C_Stop
        ACALL    Display
        ACALL    Alarm_Check
        ACALL    Relay_Check
        SJMP     Start
;--------------------------------------------------------------
Key_Scan:
        JNB      T_Set,Jump1
        JNB      A_Set,Alarm_Set
        JNB      Rel_Set,Jump2
        RET
;--------------------------------------------------------------
Jump1:  LJMP     Time_Set
Jump2:  SJMP     Relay_Set
;--------------------------------------------------------------
Alarm_Check:
        JNB      AL_Flag,CH
        MOV      A,AL_Min
        CJNE     A,Min,Alarm_Off
        MOV      A,AL_Hour
        CJNE     A,Hour,Alarm_Off
        ACALL    Alarm_On
CH:     RET
;--------------------------------------------------------------
Alarm_Off:
        MOV      SQW,#80H
        ACALL    SQW_W
        RET
;--------------------------------------------------------------
RL_Off: CLR      RL_Flag
        SETB     Rel_Out
        CLR      RL_On
        CLR_LCD
        MOV      A,#84H
        D_Str
        DB       'Relay Off!',0
        MOV      A,#82H
        ACALL    Command
        MOV      A,#00H
        ACALL    Data_Disp
        ACALL    Delay
        ACALL    AL_Logo
        SJMP     Main
;--------------------------------------------------------------
SQW_W:  ACALL    I2C_Start
        MOV      A,#SAW
        ACALL    I2C_Write
        MOV      A,#07H
        ACALL    I2C_Write
        MOV      A,SQW
        ACALL    I2C_Write
        ACALL    I2C_Stop
        RET
;--------------------------------------------------------------
Alarm_On:
        MOV      SQW,#10H
        ACALL    SQW_W
        RET
;--------------------------------------------------------------
Relay_Check:
        JNB      RL_Flag,CH1
        JB       RL_On,Rel_Off
        MOV      A,Rel_M
        CJNE     A,Min,Relay_Off
        MOV      A,Rel_H
        CJNE     A,Hour,Relay_Off
        SETB     RL_On
        ACALL    Relay_On
CH1:    RET
;--------------------------------------------------------------
Relay_Off:
        SETB     Rel_Out
        RET
;--------------------------------------------------------------
Relay_On:
        CLR      Rel_Out
        RET
;--------------------------------------------------------------
Relay_Set:
        JB       RL_Flag,RL_Off
        LJMP     R_Set
;--------------------------------------------------------------
Rel_Off:MOV      A,RM_Off
        CJNE     A,Min,Relay_On
        MOV      A,RH_Off
        CJNE     A,Hour,Relay_On
        CLR      RL_On
        ACALL    Relay_Off
CH2:    RET
;--------------------------------------------------------------
Time_Set:
        CLR_LCD
        MOV      A,#83H
        D_Str
        DB       'Set Hours:',0
        MOV      A,#0C7H
        ACALL    Command
        MOV      A,Hour
        MOV      R7,A
        ACALL    Disp_BCD
        JNB      T_Set,$
I24:    PUSH     ACC
        MOV      A,#0C7H
        ACALL    Command
        POP      ACC
KS24:   JNB      UP,Inc_Hour
        JNB      DN,Dec_Hour
        JNB      T_Set,Done_H
        SJMP     KS24
Inc_Hour:
        NOP
        ACALL    BCD_2_Hex
        INC      A
 CJNE     A,#18H,SH
 MOV      A,#00H
SH:     ACALL    Hex_2_BCD
 ACALL    Disp_BCD
 JNB      UP,$
 JNB      DN,$
 SJMP     I24
Dec_Hour:
        NOP
        ACALL    BCD_2_Hex
        DEC      A
 CJNE     A,#00H-1,SH
 MOV      A,#17H
 SJMP     SH
Done_H: JNB      T_Set,$
        MOV      Hour,R7
;--------------------------------------------------------------
Mint:   CLR_LCD
        MOV      A,#82H
        D_Str
        DB       'Set Minutes:',0
        MOV      A,#0C7H
        ACALL    Command
        MOV      A,Min
        MOV      R7,A
        ACALL    Disp_BCD
        JNB      T_Set,$
M1:     PUSH     ACC
        MOV      A,#0C7H
        ACALL    Command
        POP      ACC
KSMIN:  JNB      UP,Inc_Min
        JNB      DN,Dec_Min
        JNB      T_Set,DoneMin
        SJMP     KSMIN
Inc_Min:NOP
        ACALL    BCD_2_Hex
        INC      A
 CJNE     A,#3CH,SMin
 MOV      A,#00H
SMin:   ACALL    Hex_2_BCD
 ACALL    Disp_BCD
 JNB      UP,$
 JNB      DN,$
 SJMP     M1
Dec_Min:NOP
        ACALL    BCD_2_Hex
        DEC      A
 CJNE     A,#00H-1,SMin
 MOV      A,#3BH
 SJMP     SMin
DoneMin:JNB      T_Set,$
        MOV      Min,R7
;--------------------------------------------------------------
        CLR_LCD
        MOV      A,#83H
        D_Str
        DB       'Set Days:',0
        MOV      A,#0C5H
        D_Str
        DB       '*   *',0
        MOV      A,#0C6H
        ACALL    Command
        MOV      A,Day
        PUSH     ACC
        LCALL    W_Day
        POP      ACC
        JNB      T_Set,$
D1:     PUSH     ACC
        MOV      A,#0C6H
        ACALL    Command
        POP      ACC
KSDAY:  JNB      UP,Inc_Day
        JNB      DN,Dec_Day
        JNB      T_Set,DoneDay
        SJMP     KSDAY
Inc_Day:NOP
        INC      A
 CJNE     A,#08H,SDay
 MOV      A,#01H
SDay:   PUSH     ACC
        LCALL    W_Day
        POP      ACC
 JNB      UP,$
 JNB      DN,$
 SJMP     D1
Dec_Day:NOP
        DEC      A
 CJNE     A,#00H,SDay
 MOV      A,#07H
 SJMP     SDay
DoneDay:JNB      T_Set,$
        MOV      Day,A
;--------------------------------------------------------------
        CLR_LCD
        MOV      A,#83H
        D_Str
        DB       'Set Date:',0
        MOV      A,#0C7H
        ACALL    Command
        MOV      A,Date
        MOV      R7,A
        ACALL    Disp_BCD
        JNB      T_Set,$
DA1:    PUSH     ACC
        MOV      A,#0C7H
        ACALL    Command
        POP      ACC
KSDAT:  JNB      UP,Inc_DAT
        JNB      DN,Dec_DAT
        JNB      T_Set,DoneDAT
        SJMP     KSDAT
Inc_DAT:NOP
        ACALL    BCD_2_Hex
        INC      A
 CJNE     A,#20H,SDAT
 MOV      A,#01H
SDAT:   ACALL    Hex_2_BCD
 ACALL    Disp_BCD
 JNB      UP,$
 JNB      DN,$
 SJMP     DA1
Dec_DAT:NOP
        ACALL    BCD_2_Hex
        DEC      A
 CJNE     A,#00H,SDAT
 MOV      A,#1FH
 SJMP     SDAT
DoneDAT:JNB      T_Set,$
        MOV      Date,R7
;--------------------------------------------------------------
        CLR_LCD
        MOV      A,#83H
        D_Str
        DB       'Set Month:',0
        MOV      A,#0C7H
        ACALL    Command
        MOV      A,Month
        MOV      R7,A
        ACALL    Disp_BCD
        JNB      T_Set,$
MM1:    PUSH     ACC
        MOV      A,#0C7H
        ACALL    Command
        POP      ACC
KSMON:  JNB      UP,Inc_MON
        JNB      DN,Dec_MON
        JNB      T_Set,DoneMON
        SJMP     KSMON
Inc_MON:NOP
        ACALL    BCD_2_Hex
        INC      A
 CJNE     A,#0DH,SMON
 MOV      A,#01H
SMON:   ACALL    Hex_2_BCD
 ACALL    Disp_BCD
 JNB      UP,$
 JNB      DN,$
 SJMP     MM1
Dec_MON:NOP
        ACALL    BCD_2_Hex
        DEC      A
 CJNE     A,#00H,SMON
 MOV      A,#0CH
 SJMP     SMON
DoneMON:JNB      T_Set,$
        MOV      Month,R7
;--------------------------------------------------------------
        CLR_LCD
        MOV      A,#83H
        D_Str
        DB       'Set Year:',0
        MOV      A,#0C6H
        D_Str
        DB       '20',0
        MOV      A,#0C8H
        ACALL    Command
        MOV      A,Year
        MOV      R7,A
        ACALL    Disp_BCD
        JNB      T_Set,$
YY1:    PUSH     ACC
        MOV      A,#0C8H
        ACALL    Command
        POP      ACC
KSYY:   JNB      UP,Inc_YY
        JNB      DN,Dec_YY
        JNB      T_Set,DoneYY
        SJMP     KSYY
Inc_YY: NOP
        ACALL    BCD_2_Hex
        INC      A
 CJNE     A,#64H,SYY
 MOV      A,#00H
SYY:    ACALL    Hex_2_BCD
 ACALL    Disp_BCD
 JNB      UP,$
 JNB      DN,$
 SJMP     YY1
Dec_YY: NOP
        ACALL    BCD_2_Hex
        DEC      A
 CJNE     A,#00H-1,SYY
 MOV      A,#63H
 SJMP     SYY
DoneYY: JNB      T_Set,$
        MOV      Year,R7
        MOV      Sec,#00H
        ACALL    RTC_Reset
        ACALL    Done
        ACALL    Disp_C
        ACALL    RL_Logo
        ACALL    AL_Logo
        LJMP     Main
;--------------------------------------------------------------
Done:
        CLR_LCD
        MOV      A,#86H
        D_Str
        DB       'Done!',0
        ACALL    Delay
        RET
;--------------------------------------------------------------
Delay:  MOV      R2,#0FFH
        MOV      R3,#14H
LP3:    MOV      R2,#0FFH
LP2:    MOV      R5,#0FFH
LP1:    DJNZ     R5,LP1
        DJNZ     R2,LP2
        DJNZ     R3,LP3
        RET
;--------------------------------------------------------------
AH:     CLR_LCD
        MOV      A,#83H
        D_Str
        DB       'Set Hours:',0
        MOV      A,#0C7H
        ACALL    Command
        MOV      A,AL_Hour
        MOV      R7,A
        ACALL    Disp_BCD
ALH1:   PUSH     ACC
        MOV      A,#0C7H
        ACALL    Command
        POP      ACC
ALH2:   JNB      UP,Inc_AL_Hour
        JNB      DN,Dec_AL_Hour
        JNB      A_Set,DoneALH
        SJMP     ALH2
Inc_AL_Hour:
        NOP
        ACALL    BCD_2_Hex
        INC      A
 CJNE     A,#18H,Z_AL_H
 MOV      A,#00H
Z_AL_H: ACALL    Hex_2_BCD
 ACALL    Disp_BCD
 JNB      UP,$
 JNB      DN,$
 SJMP     ALH1
Dec_AL_Hour:
        NOP
        ACALL    BCD_2_Hex
        DEC      A
 CJNE     A,#00H-1,Z_AL_H
 MOV      A,#17H
 SJMP     Z_AL_H
DoneALH:JNB      A_Set,$
        MOV      AL_Hour,R7
        CLR_LCD
        MOV      A,#82H
        D_Str
        DB       'Set Minutes:',0
        MOV      A,#0C7H
        ACALL    Command
        MOV      A,AL_Min
        MOV      R7,A
        ACALL    Disp_BCD
        JNB      A_Set,$
ALM1:   PUSH     ACC
        MOV      A,#0C7H
        ACALL    Command
        POP      ACC
ALM2:   JNB      UP,Inc_AL_Min
        JNB      DN,Dec_AL_Min
        JNB      A_Set,DoneAL_Min
        SJMP     ALM2
Inc_AL_Min:
        NOP
        ACALL    BCD_2_Hex
        INC      A
 CJNE     A,#3CH,SAL_Min
 MOV      A,#00H
SAL_Min:ACALL    Hex_2_BCD
 ACALL    Disp_BCD
 JNB      UP,$
 JNB      DN,$
 SJMP     ALM1
Dec_AL_Min:
        NOP
        ACALL    BCD_2_Hex
        DEC      A
 CJNE     A,#00H-1,SAL_Min
 MOV      A,#3BH
 SJMP     SAL_Min
DoneAL_Min:
        JNB      A_Set,$
        MOV      AL_Min,R7
        SETB     AL_Flag
        ACALL    ALT_Done
        ACALL    Done
        ACALL    RL_Logo
        ACALL    AL_Logo
        LJMP     Main
;--------------------------------------------------------------
R_Set:  CLR_LCD
        MOV      A,#81H
        D_Str
        DB       ' Set Timer(ON)',0
        MOV      A,#80H
        ACALL    Command
        MOV      A,#00H
        ACALL    Data_Disp
        ACALL    Delay
        CLR_LCD
        MOV      A,#83H
        D_Str
        DB       'Set Hours:',0
        MOV      A,#0C7H
        ACALL    Command
        MOV      A,Rel_H
        MOV      R7,A
        ACALL    Disp_BCD
        JNB      Rel_Set,$
RTH1:   PUSH     ACC
        MOV      A,#0C7H
        ACALL    Command
        POP      ACC
KHREL:  JNB      UP,Inc_Rel_H
        JNB      DN,Dec_Rel_H
        JNB      Rel_Set,DoneRel_H
        SJMP     KHREL
Inc_Rel_H:
        NOP
        ACALL    BCD_2_Hex
        INC      A
 CJNE     A,#18H,HRel
 MOV      A,#00H
HRel:   ACALL    Hex_2_BCD
 ACALL    Disp_BCD
 JNB      UP,$
 JNB      DN,$
 SJMP     RTH1
Dec_Rel_H:
        NOP
        ACALL    BCD_2_Hex
        DEC      A
 CJNE     A,#00H-1,HRel
 MOV      A,#17H
 SJMP     HRel
DoneRel_H:
        JNB      Rel_Set,$
        MOV      Rel_H,R7
        CLR_LCD
        MOV      A,#82H
        D_Str
        DB       'Set Minutes:',0
        MOV      A,#0C7H
        ACALL    Command
        MOV      A,Rel_M
        MOV      R7,A
        ACALL    Disp_BCD
        JNB      Rel_Set,$
RTM1:   PUSH     ACC
        MOV      A,#0C7H
        ACALL    Command
        POP      ACC
KMREL:  JNB      UP,Inc_Rel_M
        JNB      DN,Dec_Rel_M
        JNB      Rel_Set,DoneRel_M
        SJMP     KMREL
Inc_Rel_M:
        NOP
        ACALL    BCD_2_Hex
        INC      A
 CJNE     A,#3CH,MRel
 MOV      A,#00H
MRel:   ACALL    Hex_2_BCD
 ACALL    Disp_BCD
 JNB      UP,$
 JNB      DN,$
 SJMP     RTM1
Dec_Rel_M:
        NOP
        ACALL    BCD_2_Hex
        DEC      A
 CJNE     A,#00H-1,MRel
 MOV      A,#3BH
 SJMP     MRel
DoneRel_M:
        JNB      Rel_Set,$
        MOV      Rel_M,R7
Off:    CLR_LCD
        MOV      A,#81H
        D_Str
        DB       ' Set Timer(OFF)',0
        MOV      A,#80H
        ACALL    Command
        MOV      A,#00H
        ACALL    Data_Disp
        ACALL    Delay
        CLR_LCD
        MOV      A,#83H
        D_Str
        DB       'Set Hours:',0
        MOV      A,#0C7H
        ACALL    Command
        MOV      A,RH_Off
        MOV      R7,A
        ACALL    Disp_BCD
        JNB      Rel_Set,$
RTHF1:  PUSH     ACC
        MOV      A,#0C7H
        ACALL    Command
        POP      ACC
KHFREL: JNB      UP,Inc_Rel_HF
        JNB      DN,Dec_Rel_HF
        JNB      Rel_Set,DoneRel_HF
        SJMP     KHFREL
Inc_Rel_HF:
        NOP
        ACALL    BCD_2_Hex
        INC      A
 CJNE     A,#18H,HFRel
 MOV      A,#00H
HFRel:  ACALL    Hex_2_BCD
 ACALL    Disp_BCD
 JNB      UP,$
 JNB      DN,$
 SJMP     RTHF1
Dec_Rel_HF:
        NOP
        ACALL    BCD_2_Hex
        DEC      A
 CJNE     A,#00H-1,HFRel
 MOV      A,#17H
 SJMP     HFRel
DoneRel_HF:
        JNB      Rel_Set,$
        MOV      RH_Off,R7
        CLR_LCD
        MOV      A,#82H
        D_Str
        DB       'Set Minutes:',0
        MOV      A,#0C7H
        ACALL    Command
        MOV      A,RM_Off
        MOV      R7,A
        ACALL    Disp_BCD
        JNB      Rel_Set,$
RFTM1:  PUSH     ACC
        MOV      A,#0C7H
        ACALL    Command
        POP      ACC
KFMREL: JNB      UP,Inc_Rel_MF
        JNB      DN,Dec_Rel_MF
        JNB      Rel_Set,DoneRel_MF
        SJMP     KFMREL
Inc_Rel_MF:
        NOP
        ACALL    BCD_2_Hex
        INC      A
 CJNE     A,#3CH,MFRel
 MOV      A,#00H
MFRel:  ACALL    Hex_2_BCD
 ACALL    Disp_BCD
 JNB      UP,$
 JNB      DN,$
 SJMP     RFTM1
Dec_Rel_MF:
        NOP
        ACALL    BCD_2_Hex
        DEC      A
 CJNE     A,#00H-1,MFRel
 MOV      A,#3BH
 SJMP     MFRel
DoneRel_MF:
        JNB      Rel_Set,$
        MOV      RM_Off,R7
        SETB     RL_Flag
        ACALL    ALT_Done
        ACALL    Done
        ACALL    RL_Logo
        ACALL    AL_Logo
        LJMP     Main
;--------------------------------------------------------------
RL_Logo:JNB      RL_Flag,WE1
        MOV      A,#0CDH
        ACALL    Command
        MOV      A,#00H
        ACALL    Data_Disp
WE1:    RET
;--------------------------------------------------------------
AL_Logo:JNB      AL_Flag,WE2
        MOV      A,#0C2H
        ACALL    Command
        MOV      A,#01H
        ACALL    Data_Disp
WE2:    RET
;--------------------------------------------------------------
ALT_Done:
        MOV      R1,#29H
        MOV      R3,#07H
        ACALL    I2C_Start
        MOV      A,#SAW
        ACALL    I2C_Write
        MOV      A,#08H
        ACALL    I2C_Write
LOOP4:  MOV      A,@R1
        ACALL    I2C_Write
        INC      R1
        DJNZ     R3,LOOP4
        ACALL    I2C_Stop
        RET
;--------------------------------------------------------------
LCD_Initial:
        MOV      A,#38H
 ACALL    Command
 MOV      A,#0CH
 ACALL    Command
 CLR_LCD
 MOV      A,#06H
 ACALL    Command
 RET
;--------------------------------------------------------------
Display:MOV      R1,#21H
 MOV      A,#0CAH
 ACALL    Command
 MOV      A,@R1
 ACALL    Disp_BCD
;
        INC      R1
 MOV      A,#0C7H
 ACALL    Command
 MOV      A,@R1
 ACALL    Disp_BCD
;
        INC      R1
 MOV      A,#0C4H
 ACALL    Command
 MOV      A,@R1
 ACALL    Disp_BCD
;
        INC      R1
 MOV      A,#80H
 ACALL    Command
 MOV      A,@R1
 LCALL    W_Day
;
        INC      R1
 MOV      A,#86H
 ACALL    Command
 MOV      A,@R1
 ACALL    Disp_BCD
;
        INC      R1
 MOV      A,#89H
 ACALL    Command
 MOV      A,@R1
 ACALL    Disp_BCD
;
        INC      R1
 MOV      A,#8EH
 ACALL    Command
 MOV      A,@R1
 ACALL    Disp_BCD
        RET
;--------------------------------------------------------------
Hex_2_BCD:
        MOV      B,#00001010B
 DIV      AB
 MOV      R3,B
 MOV      B,#00010000B
 MUL      AB
 ADD      A,R3
 MOV      R7,A
 RET
;--------------------------------------------------------------
BCD_2_Hex:
        MOV      B,#00010000B
 DIV      AB
 MOV      R3,B
 MOV      B,#00001010B
 MUL      AB
 ADD      A,R3
 RET
;--------------------------------------------------------------
Disp_BCD:
 PUSH     ACC
 MOV      R5,A
 ANL      A,#11110000B
 SWAP     A
 MOV      DPTR,#Ascii_Code
 MOVC     A,@A+DPTR
 ACALL    Data_Disp
 MOV      A,R5
 ANL      A,#00001111B
 MOVC     A,@A+DPTR
 ACALL    Data_Disp
 POP      ACC
 RET
;--------------------------------------------------------------
Disp_C: MOV      A,#80H
        D_Str
        DB       '        /  /20  ',0
        MOV      A,#0C0H
        ACALL    Command
        MOV      A,#'*'
        ACALL    Data_Disp
        MOV      A,#0C6H
        ACALL    Command
        MOV      A,#':'
        ACALL    Data_Disp
        MOV      A,#0C9H
        ACALL    Command
        MOV      A,#':'
        ACALL    Data_Disp
        MOV      A,#0CFH
        ACALL    Command
        MOV      A,#'*'
        ACALL    Data_Disp
        RET
;--------------------------------------------------------------
CGR: MOV      R4,#08H
        MOV      R5,#40H
        MOV      DPTR,#Clock
        ACALL    WRI
        MOV      R4,#08H
        MOV      R5,#48H
        MOV      DPTR,#Bell
        ACALL    WRI
        RET
;--------------------------------------------------------------
WRI:    CLR      A
        ACALL    Get_Ready
        MOV      LCD,R5
        CLR      RS
        CLR      RW
        SETB     EN
        CLR      EN
        INC      R5
        MOVC     A,@A+DPTR
        ACALL    Data_Disp
        INC      DPTR
        DJNZ     R4,WRI
        RET
;---------------------------------------;
; ************I2C Commands************* ;
;---------------------------------------;
I2C_Start:
 SETB     SCL
 SETB     SDA
 I2C_Delay
 CLR      SDA
 I2C_Delay
 CLR      SCL
 RET
;--------------------------------------------------------------
I2C_Stop:
 CLR      SDA
 SETB     SCL
 I2C_Delay
 SETB     SDA
 RET
;--------------------------------------------------------------
I2C_Write:
 MOV      BitCnt,#08H
I2C_Write_Loop:
 RLC      A
 MOV      SDA,C
 NOP
 SCLHigh
 CLR      SCL
 DJNZ     BitCnt,I2C_Write_Loop
 NOP
 SETB     SDA
 NOP
 SETB     SCL
 I2C_Delay
 MOV      C,SDA
 CLR      SCL
 NOP
 JNC      Label
 ACALL    I2C_Stop
 ACALL    I2C_Start
 SJMP     I2C_Write
Label: RET
;--------------------------------------------------------------
I2C_Read_Dummy:
 SETB     SDA
 CLR      A
 MOV      BitCnt,#08H
I2C_Read_Loop:
 CLR      SCL
 I2C_Delay
 SCLHigh
 MOV      C,SDA
 RLC      A
 DJNZ     BitCnt,I2C_Read_Loop
 CLR      SCL
 MOV      @R0,A
 INC      R0
 RET
;--------------------------------------------------------------
I2C_Ack_Write:
 CLR      SDA
 NOP
 SETB     SCL
 I2C_Delay
 CLR      SCL
 SETB     SDA
 I2C_Delay
 RET
;--------------------------------------------------------------
I2C_Nack_Write:
 SETB     SDA
 NOP
 SETB     SCL
 I2C_Delay
 CLR      SCL
 I2C_Delay
 RET
;--------------------------------------------------------------
I2C_Read:
 ACALL    I2C_Read_Dummy
 ACALL    I2C_Ack_Write
 RET
;--------------------------------------------------------------
I2C_Read_Last:
 ACALL    I2C_Read_Dummy
 ACALL    I2C_Nack_Write
 RET
;--------------------------------------;
; ************LCD CommandS*************;
;--------------------------------------;
Command:ACALL    Get_Ready
        MOV      LCD,A
        CLR      RS
        CLR      RW
        SETB     EN
        CLR      EN
        RET
;--------------------------------------------------------------
Data_Disp:
        ACALL    Get_Ready
        MOV      LCD,A
        SETB     RS
        CLR      RW
        SETB     EN
        CLR      EN
        RET
;--------------------------------------------------------------
Get_Ready:
        SETB     Busy
        CLR      RS
        SETB     RW
Back:   CLR      EN
        SETB     EN
        JB       Busy,BACK
        RET
;--------------------------------------------------------------
Disp_Char:
        POP      DPH
        POP      DPL
Print_Text:
        CLR      A
        MOVC     A,@A+DPTR
        CJNE     A,#00H,Loop2
        SJMP     Return
Loop2:  MOV      R4, A
        LCALL    Data_Disp
        INC      DPTR
        LJMP     Print_Text
Return: MOV      A,#01H
        JMP      @A+DPTR
;--------------------------------------------------------------
W_Day:  CJNE     A,#01H,MON
        LCALL    Disp_Char
        DB       'Sun',0
        RET
MON:    CJNE     A,#02H,TUE
        LCALL    Disp_Char
        DB       'Mon',0
        RET
TUE:    CJNE     A,#03H,WED
        LCALL    Disp_Char
        DB       'Tue',0
        RET
WED:    CJNE     A,#04H,THU
        LCALL    Disp_Char
        DB       'Wed',0
        RET
THU:    CJNE     A,#05H,FRI
        LCALL    Disp_Char
        DB       'Thu',0
        RET
FRI:    CJNE     A,#06H,SAT
        LCALL    Disp_Char
        DB       'Fri',0
        RET
SAT:    CJNE     A,#07H,WHAT
        LCALL    Disp_Char
        DB       'Sat',0
        RET
WHAT:   RET
;--------------------------------------------------------------
Ascii_Code:
        DB       30H,31H,32H,33H,34H,35H,36H,37H,38H,39H
;--------------------------------------------------------------
;Icons
Clock:  DB       00H,0EH,15H,17H,11H,0EH,00H,00H
Bell:   DB       04H,0EH,0EH,0EH,1FH,00H,04H,00H
;--------------------------------------------------------------
 END
Share:

Jadwal Waktu Sholat

TIME WIB

TV EDUKASI LIVE

Popular Posts

Recent Posts

Pages