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: , , ,

52 Responses to “Up-Down Counter menggunakan uC AT89”

  1. oke banget !

  2. Mantab mas Agfi..
    flowcode-nya mantab..

  3. terima kasih, next ttg pewaktu/pencacah… Insya Alloh…

  4. Setuju! Dissection macam bgini memang bikin yang baca cepet ngerti dan cepet pinter.

  5. kalau menggunakan bahasa assembly di dt-51 minsys versi 3.3 itu gimana, tolong kasih penjelasan dan perancangan software’nya?
    terimakasih.

  6. @Tri:
    sama saja konsepnya, programnya juga sama gak ada bedanya, cuman program di DT-51 harus dimulai alamat tertentu bukan 0h…

  7. Pak agfi klo mau counter up/down sampai ribuan bagaimana caranya?
    bisa kasih saran…
    terima kasih

  8. @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…

  9. Wah bagus banget mas programnya tapi kalau seumpama outputnya LCD 16×2 bagaimana, infonya donk…….

  10. bagus pak programnya, gampang dicerna!! coba dosen saya kaya bapak!! hahaha…

  11. gimana kalo uC at89c55nya saya ganti sama at89c51, yg at89c51 lbh kecil memorynya, bisa ga ya??
    thx b4..

  12. 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

  13. 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

  14. Bagus pak inline expanationnya :) yang baca jadi cepet ngerti

  15. thanks for sharing pak

  16. thank you for sharing it’s so helpful

  17. its good thing to share, thank you.

  18. thanks for the post man

  19. thanks for the post mands

  20. 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.

  21. get all the details fo mpcs payment online

  22. highly expertise and professionalism in any kind of translation services.

  23. thanks for the post mans

  24. 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

  25. Get all kinds of assistance from the experts of Student Life Saviour in doing assignments of any nature.

  26. Get the experts of Australian Assignment Help for all kinds of assignment services to students.

  27. Complete the guide on metropcs online from our site

  28. 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.

  29. 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

  30. 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.

  31. Family owned business located in Surrey, A1 Sports is your best choice for a customized solution for everything sports. Call Today

  32. MetroPCS Login-Clients needing to make a MetroPCS login [+] should finish th

  33. to make a MetroPCS login [+] should finish the

  34. get all the sruff of att bill pay

  35. need some old stuff then u must look up here

  36. 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.

  37. Thanks for sharing your experience, really great. Waiting for more like this.

  38. AT&T Inc. is an American worldwide conglomerate holding organization

  39. 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

  40. 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!

  41. 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!

  42. can competently tackle any topic and return a top grade worthy paper!

  43. 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,

  44. 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

  45. افراد زیادی هستند که به ترجمه تخصصی فارسی به انگلیسی نیاز دارند و دنبال مترجمی می گردند که کار آن ها را به بهترین شکل و در سریع ترین زمان ممکن انجام دهد. اگر شما هم به دنبال ترجمه فوری می گردید ما به شما سایت ترجمه آنلاین را پیشنهاد می کنیم

  46. 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.

  47. 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

  48. Thanks for sharing the information with us. Keep on updating us regularly.

  49. 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.

  50. 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.

  51. Thank you for sharing this article. I really love it. please keep sharing the good articles.

Trackbacks/Pingbacks

  1. Memulai Belajar Mikrokontroler - Quick, Easy and Harmless!

Leave a Reply

You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>