Sebenarnya membuat aplikasi pencacah naik-turun (up-down counter) menggunakan AT89 adalah hal yang aneh dalam dunia elektronika digital. Lho kok? La ya… lha wong tinggal pake rangkaian dengan IC TTL (seri 74LS) saja sudah bisa, kok ini pake programming mikrokontroler segala… Lha kalo untuk belajar pemrograman mikrokontroler gimana? O ya silahkan saja… itu jadi gak aneh lagi… he he he…
Oke gak apa-apa, yang penting kali ini kita belajar bagaimana membuat pencacah naik turun menggunakan mikrokontroler seri AT89C atau AT89S. Perhatikan rangkaiannya terlebih dahulu…
Mmmm gak ada yang aneh khan? Biasa-biasa saja, tombol pushbutton digunakan untuk memberi picuan atau detak (clock) untuk melakukan pencacahan naik (P3.2 atau ~INT0) atau pencacahan turun (P3.3 atau ~INT1). Dengan demikian kita juga sekaligus belajar memanfaatkan fasilitas interupsi di AT89.
Baik, program kita awali dengan menentukan alamat seperti biasa di lokasi 0h, dilanjutkan dengan lompatan ke label “utama” (ljmp utama):
org 0h
ljmp utama
Kemudian dilanjutkan dengan mendefinisikan vektor atau lokasi interupsi INT0 dan INT1. Untuk interupsi-0 (INT0) kita isikan lompatan ke label “cacah_naik”. Lho kok gak pake ORG? ya karena instruksi sebelumnya (ljmp utama) berukuran 3 byte (menempati lokasi 0, 1, dan 2), sedangkan vektor interupsi INT0 harus dituliskan mulai lokasi 3 dan itu pas dengan instruksi pertama, jadi gak perlu pake ORG. Sedangkan untuk INT1 tetap harus menggunakan ORG 13h (instruksi ljmp cacah_turun):
ljmp cacah_naik org 13h ljmp cacah_turun
Instruksi-instruksi berikutnya adalah melakukan inisialisasi data angka yang akan ditampilkan di 7-segmen (pada lokasi yang ditandai dengan label “numerik“), sedangkan lokasi program utama mulai alamat 30h:
org 30h
utama:
mov dptr, #numerik
Kemudian persiapan akumulator A, data pertama juga ditempatkan ke A, tampilkan ke 7-segmen yang terhubung dengan P0, dan jangan lupa ada sebuah register, R0, yang digunakan untuk menyimpan indeks data (mengapa? Karena untuk cacah turun tidak ada perintah DEC atau penurunan pada DPTR, dalam hal ini data menggunakan register DPTR):
clr a
movc a, @a+dptr
mov p0, a
mov r0, #0
Nah, sekarang inisialisasi interupsi, eksternal-0 (INT0), eksternal-1 (INT1), aktivasi interupsi global (EA), aktifkan interupsi aktif low pada IT0 dan IT1:
setb ex0
setb ex1
setb ea
setb it0
setb it1
Dan seperti biasa, lompat ditempat:
sjmp $
Baiklah, sekarang apa yang terjadi jika terjadi penekanan tombol pada INT0? Ya betul! Terjadilah interupsi eksternal-0, label apa yang dijalankan? Ya tepat! Label “cacah_naik” yang dijalankan. Pertama nilai R0 dinaikkan (untuk indeks data berikutnya), kemudian bandingkan dengan nilai #10 (apakah R0 = 10, artinya data sudah semuanya), jika belum maka lompat ke label “tampil”, namun jika R0=10, maka R0 dibuat sama dengan 9, selesai interupsi:
cacah_naik:
inc r0
cjne r0, #10, tampil
mov r0, #9
reti
Begitu juga saat interupsi eksternal-1 (INT1) yang terjadi, maka mikrokontroler akan mengerjakan label “cacah_turun”. Pertama nilai R0 dikurangi satu, kemudian dibandingkan datanya apakah sama dengan 255, lho kok? Setelah R0=0 kemudian ada instruksi untuk mengurangi satu, maka akan kembali ke nilai terbesar yaitu 255, hal ini diistilahkan dengan warping. Jika sama, maka nilai R0 dipertahankan agar sama dengan 0. Kalo belum sama ya data ditampilkan saja:
cacah_turun:
dec r0
cjne r0, #255, tampil
mov r0, #0
reti
Untuk masalah tampilan ke 7-segmen adalah masalah gampang! Simpan lokasi data yang sudah siap ke akumulator A, kemudian lakukan penyalinan data ke A menggunakan MOVC dan tampilkan ke 7-segmen yang terhubungkan melalui port-0, selesai:
tampil:
mov a, r0
movc a, @a+dptr
mov p0, a
reti
Program selengkapnya sebagai berikut:
——————————————————————————-
org 0h
ljmp utama
ljmp cacah_naik
org 13h
ljmp cacah_turun
org 30h
utama:
mov dptr, #numerik
clr a
movc a, @a+dptr
mov p0, a
mov r0, #0
;
;mov ie, #85h ; <- bisa juga aktivasi INT pake yang singkat begini
setb ex0
setb ex1
setb ea
setb it0
setb it1
sjmp $
;
cacah_naik:
inc r0
cjne r0, #10, tampil
mov r0, #9
reti
;
cacah_turun:
dec r0
cjne r0, #255, tampil
mov r0, #0
reti
;
tampil:
mov a, r0
movc a, @a+dptr
mov p0, a
reti
;
numerik:
DB 0C0h,0F9h,0A4h,0B0h,99h,92h,82h,0F8h,80h,90h
end
——————————————————————————-
Semoga bermanfaat!
Tags: at89, counter, Mikrokontroler, pencacah
February 7th, 2009 at 10:04 pm
oke banget !
February 8th, 2009 at 6:46 pm
Mantab mas Agfi..
flowcode-nya mantab..
February 9th, 2009 at 9:04 am
terima kasih, next ttg pewaktu/pencacah… Insya Alloh…
February 9th, 2009 at 10:02 am
Setuju! Dissection macam bgini memang bikin yang baca cepet ngerti dan cepet pinter.
April 1st, 2009 at 8:51 pm
kalau menggunakan bahasa assembly di dt-51 minsys versi 3.3 itu gimana, tolong kasih penjelasan dan perancangan software’nya?
terimakasih.
April 2nd, 2009 at 7:27 am
@Tri:
sama saja konsepnya, programnya juga sama gak ada bedanya, cuman program di DT-51 harus dimulai alamat tertentu bukan 0h…
April 30th, 2009 at 11:39 am
Pak agfi klo mau counter up/down sampai ribuan bagaimana caranya?
bisa kasih saran…
terima kasih
April 30th, 2009 at 2:34 pm
@agus:
untuk count-up/down hingga ribuan masih bsa menggunakan register (cuman 8 bit atau 1 byte) dan bantuan register lainnya… kemudian nilai dari register2 tsb dibaca dan diterjemahkan ke 4×7segment..
kira-kira begitu cara kerjanya…
May 31st, 2009 at 11:37 pm
Wah bagus banget mas programnya tapi kalau seumpama outputnya LCD 16×2 bagaimana, infonya donk…….
June 1st, 2009 at 10:16 pm
bagus pak programnya, gampang dicerna!! coba dosen saya kaya bapak!! hahaha…
January 18th, 2010 at 10:59 am
gimana kalo uC at89c55nya saya ganti sama at89c51, yg at89c51 lbh kecil memorynya, bisa ga ya??
thx b4..
May 14th, 2010 at 11:38 am
aslm mf pk bisa ng dibahas rangkain down counter menggunakan IC TTL 74LS,ini untuk display waktu lampu lalu lintas yg berbasis PLC,output PLCny sdh hbis unt lampu jdi diparalelkn output PLC ny ke rangk digital unt display,mhn bntuannya pak.mks
September 11th, 2010 at 3:35 pm
assalamualaikum pak
saya berencaana membuat 4 digit multiplexed up/down counter dg uC atmega8 dalam bahasa bascom,kra programya bbagai mana pak?
terima kasih
wassalam
October 15th, 2011 at 1:29 am
Bagus pak inline expanationnya
yang baca jadi cepet ngerti
April 11th, 2018 at 2:16 pm
thanks for sharing pak
May 16th, 2018 at 2:51 pm
thank you for sharing it’s so helpful
December 13th, 2018 at 1:39 pm
its good thing to share, thank you.
March 8th, 2019 at 7:25 pm
thanks for the post man
May 9th, 2019 at 5:10 pm
thanks for the post mands
June 19th, 2019 at 4:36 pm
Take BUSINESS TRANSLATION SERVICES SINGAPORE at Singaporetranslators.com, we have a pool of transaltors who have proved them the Best translators by providing uncountable service to the Singapore’s Clients. They are highly expertise and professionalism in any kind of translation services.
July 4th, 2019 at 12:37 pm
get all the details fo mpcs payment online
July 5th, 2019 at 4:36 pm
highly expertise and professionalism in any kind of translation services.
August 17th, 2019 at 4:39 pm
thanks for the post mans
August 20th, 2019 at 8:37 pm
Preceding now, people expected to hold on for some couple of days before they could watch their most adored TV shows and all that a
August 24th, 2019 at 4:57 pm
Get all kinds of assistance from the experts of Student Life Saviour in doing assignments of any nature.
August 24th, 2019 at 4:59 pm
Get the experts of Australian Assignment Help for all kinds of assignment services to students.
August 26th, 2019 at 11:37 am
Complete the guide on metropcs online from our site
September 2nd, 2019 at 3:12 pm
Nice Blog, I have get enough information from your blog and I appreciate your way of writing.
Hope you are sharing the same in future.
Great share! Nice work. Keep it up.
September 3rd, 2019 at 1:23 pm
Ireland assignment help provides the best quality assignment help services to the students. Our professional writers can write any assignment as they are well-versed with every assignment topic. S
September 6th, 2019 at 4:16 pm
We strive to improve your overall lifestyle and appearance by providing you with the best services to achieve your goals. At Breeze, we specialise in laser hair removal, skin care, and weight loss treatments using the most modern and effective tools on the market. In our clean, safe, and supportive environment, we are dedicated to providing the tools to help you make well-informed decisions to look and feel your best.
September 7th, 2019 at 6:24 pm
Family owned business located in Surrey, A1 Sports is your best choice for a customized solution for everything sports. Call Today
September 10th, 2019 at 1:33 pm
MetroPCS Login-Clients needing to make a MetroPCS login [+] should finish th
September 10th, 2019 at 1:33 pm
to make a MetroPCS login [+] should finish the
September 10th, 2019 at 5:58 pm
get all the sruff of att bill pay
September 10th, 2019 at 5:58 pm
need some old stuff then u must look up here
September 12th, 2019 at 6:37 pm
As we all know that, we can access Roadrunner Webmail on any smart device that has strong internet connection. However setup of Roadrunner email requires us to follow some necessary steps. Though these steps are simple but if not followed properly may lead to trouble and may result in Roadrunner email not working issue. Therefore, we have listed here some effective steps that will help you to perform the setup of Roadrunner email application very easily.
September 18th, 2019 at 1:20 pm
Thanks for sharing your experience, really great. Waiting for more like this.
September 20th, 2019 at 10:42 am
AT&T Inc. is an American worldwide conglomerate holding organization
September 20th, 2019 at 10:42 am
AT&T Inc. is an American worldwide conglomerate holding organization headquartered at Whitacre Tower in Downtown Dallas, Texas. It is the world’s biggest media communications organization, the biggest
September 25th, 2019 at 2:41 pm
Looking for a UK essay writing service? Need assistance with your projects? Place an order at British Essay Writing. We are a team of experts with active and field experience in every practice of law. Our experts can competently tackle any topic and return a top grade worthy paper!
September 26th, 2019 at 1:00 pm
We are a team of experts with active and field experience in every practice of law. Our experts can competently tackle any topic and return a top grade worthy paper!
September 26th, 2019 at 1:18 pm
can competently tackle any topic and return a top grade worthy paper!
October 16th, 2019 at 2:01 pm
NTTA bill pay How to pay toll? You can pay utilizing labels, for example, TxTag, NTTA TollTag, HCTRA EZ Tag, EZ TAG. You can likewise utilize video tolling framework,
October 16th, 2019 at 2:02 pm
ramework, for example, Pay via mail on TxDOT streets or ZipCash on NTTA streets. You can buy TxTag and it will be useful for the entire
November 2nd, 2019 at 12:54 pm
افراد زیادی هستند که به ترجمه تخصصی فارسی به انگلیسی نیاز دارند و دنبال مترجمی می گردند که کار آن ها را به بهترین شکل و در سریع ترین زمان ممکن انجام دهد. اگر شما هم به دنبال ترجمه فوری می گردید ما به شما سایت ترجمه آنلاین را پیشنهاد می کنیم
November 26th, 2019 at 12:58 pm
We are the best composing company giving assignment writing service UK and our Affordable Writing Services are 100% valid as we don’t offer pre-composed articles paying little heed to the resemblance of theme or research project.
March 14th, 2020 at 12:47 pm
Thanks for sharing the information with us. Keep on updating us regularly.
https://www.24×7direct.com.au/offshore-staffing/“>Offshore Staffing Companies
|https://www.24×7direct.com.au/offshore-outsourcing/“>Offshore Outsourcing
April 6th, 2020 at 2:16 pm
Thanks for sharing the information with us. Keep on updating us regularly.
April 7th, 2020 at 12:13 pm
thank you for sharing this article. I really love it. in case, If you are facing any kind of problem with your Lenovo laptop. visit askprob blogs to troubleshoot the problem.
April 9th, 2020 at 11:58 am
This is an interesting write-up, and shine its formatting through using office 365 applications. In case something gets wrong, then you can use office 365 download link to obtain the suitable result.
April 20th, 2020 at 2:39 am
Thank you for sharing this article. I really love it. please keep sharing the good articles.