RSS

Jam Digital menggunakan Mikro ATMega8 dan Bahasa BASCOM-AVR

24 Mar
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
About these ads
 
6 Komentar

Posted by pada Kamis, Maret 24, 2011 in Bascom AVR, Mikrokontroler

 

6 responses to “Jam Digital menggunakan Mikro ATMega8 dan Bahasa BASCOM-AVR

  1. elazmy

    Jumat, April 1, 2011 at 1:17 am

    Bisa bikin sytem buat alarm mescit yg trsambung ke loadspeaker?
    Dan lagi, kalau pas sholat brjamaah, alarm g’bunyi.

     
  2. Faudzee

    Senin, April 4, 2011 at 6:38 pm

    Salam, kenapa bila compile Bascom AVR menulis:

    “Usage: errdump /v”

    gak ada hex filenya….

     
  3. khoiru

    Sabtu, April 30, 2011 at 7:03 pm

    pak, rumah anda dimana?
    boleh dong saya maen dan belajar mikrokontrol

     
  4. Anda Suganda

    Senin, Juni 13, 2011 at 12:58 pm

    pak, saat dicompile kenapa error di ds1307.lib

     
  5. masparno

    Selasa, Agustus 23, 2011 at 11:30 pm

    Silahkan mengetest hasil programnya pakai ISIS Proteus Bang

     
  6. masparno

    Selasa, Agustus 23, 2011 at 11:32 pm

    Pakai ISIS Proteus silahkan cari di internet banyak

     

Jangan Lupa Tinggalkan Komentar Anda !

Isikan data di bawah atau klik salah satu ikon untuk log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Logout / Ubah )

Twitter picture

You are commenting using your Twitter account. Logout / Ubah )

Facebook photo

You are commenting using your Facebook account. Logout / Ubah )

Google+ photo

You are commenting using your Google+ account. Logout / Ubah )

Connecting to %s

 
Ikuti

Get every new post delivered to your Inbox.

%d bloggers like this: