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.

Tampilkan postingan dengan label Bascom AVR. Tampilkan semua postingan
Tampilkan postingan dengan label Bascom AVR. Tampilkan semua postingan

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:

Aplikasi ADC pada ATMega8 dengan Bahasa Bascom AVR

Untuk aplikasi ADC menggunakan bahasa Bascom AVR sangatlah sederhana, kita tidak perlu memahami lebih dalam tentang proses yang terjadi pada LCD dan ADC. Kita cukup tau perintah yang digunakan untuk mengakses perangakat tersebut melalui bahasa pemrograman. Pada aplikasi ini saya mencoba menggunakan ATMega8 yang tidak jauh berbeda dengan ATMega8535, yang berbeda hanyalah beberapa fitur dan jumlah Port. Gambar rangkaiannya cukup sederhana seperti gambar dibawah ini.


Gambar Rangkaian Aplikasi ADC menggunakan ATMega8
Berikut ini adalah contoh program sederhana yang dapat di pahami dan dikembangkan dengan mudah dalam aplikasi yang kompleks. Mudah-mudahan bermanfaat. Terima kasih.

 Contoh Program :

  1 $regfile = "m8def.dat"
  2 $crystal = 4000000
  3 Config Portb = Output
  4 Config Lcd = 16 * 2
  5 Config Lcdpin = Pin, Rs = Portd.4, E = Portd.5, Db4 = Portd.0
  6 Config Lcdpin = Pin, Db5 = Portd.1 , Db6 = Portd.2 , Db7 = Portd.3
  7 Config Adc = Single , Prescaler = Auto
  8 
  9 Start Adc
 10 'With STOP ADC, you can remove the power from the chip
 11 'Stop Adc
 12 
 13 Dim W As Word , Channel As Byte
 14 Channel = 0
 15 'Baca Nilai ADC dari channel 0
 16 
 17 Do
 18 Locate 1 , 1
 19 Lcd "Nilai ="
 20 W = Getadc(channel)
 21 Locate 1 , 9
 22 Lcd " "
 23 Locate 1 , 9
 24 Lcd W
 25 Waitms 100
 26 Loop
 27 End 
Share:

Jadwal Waktu Sholat

TIME WIB

TV EDUKASI LIVE

Popular Posts

Recent Posts

Pages