A friend asked me for help to create a program to perform calculations that can go up or down. The data displayed on a three-digit seven segment. Meanwhile, the buttons mounted on the port 3 used to raise or lower the count.
Actually, he asked me to place the digits control using P0, and P2 for segment data. However, because previously I had made the program with P0 as the control of digits and P1 for segment data, so that I don’t need to reconfigure when I tried on the simulator, I keep using P0 as the control of digits and P1 for segment data. Therefore if you have already used P0 as the control of digits and P1 for segment data, then you need to change the PortDigit and PortData constants at the top of the program.
To realize the friend request, I use the way I usually do if I want to display data on the seven segment, i.e. put seven segment manager procedure on the timer interrupt. This ensures our programs to be able to display data on the seven segment with good brightness. There are several examples of programs that put the seven segment scanning process in the main program. But we know that the seven segment which installed in a multiplex must continuously scanned to be able to display the data. If the program are less keen in doing the scanning, then the display will be disturbed. Probably will not light up, and this is the worst, or at least the light intensity of the seven segment will be dimmed. And it is very unpleasant. By using a timer interrupt to do the scanning, we can relieve our attention from the scanning process, because it has been fully handled the interrupt handler. So this way is the best way (at least I think so, you may leave a comment if you do not agree).
Then, because the program is indeed a very simple program, then we can use all facilities owned by the microcontroller without much consideration. For easier handling in counter addition or subtraction, we can use the external interrupts, i.e. ext0 and ext1. So we just attach the button at P3.2 (ext0) and P3.3 (ext1). Of course we must use the button that really bounce-free (bounceless), so that if we press the button once, then we also get only one count. To raise the count, we use ext0. As for lowering the count, we use ext1. In the main program, we do not even do anything.
Using interrupts to handle button is very simple in terms of response. But the drawback is that the button used should be a bounceless type. In addition, only P3.2 and P3.3 can be used. Therefore, using debouncing technique as I have discussed in the Easy and Fun Learning Microcontroller book will probably be a better solution in handling button. For that, I also will feature a program that handles the button not on the external interrupt, but placed on the timer interrupt. Thus, in addition to the timer interrupt is used to perform seven segment scanning is also used for button scanning.
In scanning through the timer interrupt, we can use any button, does not have to use the bounceless. We just need to adjust how quickly button bounce will be addressed. To try it, you can change the value MaxWait to 255 to slow down the response of the button bounce. If you use a simulator, and a computer that used is quite a fast computer, it may be the key response is still too fast. You simply change the TimeOutDown and TimeOutUp type to be unsigned int, and change the MaxWait value to higher rates. After that, try to press the button on Tombol.exe with high frequency. You will find that if the button is pressed too quickly, then presses the button too fast will be considered as a bounce. Thus, we can use the buttons that are not really bounce free. All you need to do is adjusting how sensitive your buttons, i.e. by setting the MaxWait value. And generally, you will not use numbers higher than 255. Therefore, the data type I use is unsigned char.
Remember, if you use Tombol.exe as simulated buttons, then you must set the used port (in this case is P3) on the simulator to be linked in Link Message. This is necessary because Tombol.exe send the keystrokes signals to the simulator through Window Message. As for the program that handles button via the external interrupts, then you can not use Tombol.exe, because Tombol.exe could not provide an interrupt signal to the simulator. You must use the existing buttons on the simulator. To display this button port window is from the View-Port menu. Then from the window, double-click on the desired port, which is the name of the port, not on its value, because if you double-click on the value, then it will appear the dialog to change the value of the port or the relevant registers.
Another friend asked me, “How do I create a program that constantly monitor keystrokes, but other operations continue to run without being interrupted by the oversight of the key”. Well, two examples of the above program, whether using an external interrupt and those that use the button scanning on the timer interrupt, has conducted monitoring of key presses continuously, while at the main program does not even do anything. Thus, the above example is also an answer to this question. You simply put the other operations in the main program, while the supervision of the button has been continuously monitored.
I wrote the program in c and M51 language only. So if you just have a Micro v5.4, which is the IDE that I include in the Easy and Fun Learning Microcontroller book, then you should first download the latest version of the IDE that supports the C language.
Happy trying, hopefully useful.

mas yoko saya adalah pemula dan saya ingin tahu cara memultifleks 7 segmen, oleh karena itu saya berharap mau memberikan pencerahan kepada saya.dan saya mohon kepada mas yoko memberi penjelasasan mengenai perintah dalam program counter 3 digit ini. mohon jika tidak keberatan jawaban nya dikirim ke email saya saja.
atas kebaikan nya saya ucapkan terima kasih.
Coba deh, Mas Iman baca buku “Mudah dan Menyenangkan Belajar Mikrokontroler”. Di situ ada pembahasan yang cukup jelas dan mudah dipahami untuk mengendalikan seven segment secara multipleks. Kalau sulit untuk mendapatkan buku tersebut di toko buku, Mas Iman bisa juga pesan melalui toko buku online. Dalam listing program Counter 3 digit yang bisa didownload tersebut, saya juga menyisipkan beberapa komentar untuk menjelaskan bagaimana cara kerja dari program tersebut.
Terima Kasih Atas Jawaban mas Sulhan. Saya Akan kumpul2 uang untuk membeli bukunya mas Sulhan, Maklum lah kalo doku nya Pelajar SMA di daerah tertinggal Kab Bandung seperti saya ini
kempis melulu. tapi saya udah niat nabung nich Mas.
saya mau berterima kasih sama mas Sulhan karena Program Counter 3 digit dari mas Sulhan Sangat bermanfaat, karena saya
Aplikasikan di puskesmas Di daerah saya sebagai display Antrian.
Mas saya mau bertanya lagi nih? saya sudah mendownload Program counter 3 Digit dan membuat Hardwarenya. di listing program tersebut saya rubah Max count nya menjadi 999999 dan menambah digit nya menjadi 6 digit tapi, mengapa ngak jalan Ya? Bagaimana Solusinya?
Satu lagi mas saya pernah melihat rangkaian AT89C51 dimana rangkaian tersebut Hanya bertugas menyalakan lampu led secara berurutan dari LED1 Sampai Led100.Namun yang saya Ketahui Pin Yang dapat Berfungsi Sebagai input/output hanya berjumlah 32. jadi jika dipasang lampuled pun Maksimal Hanya32. Jadi Bagaimana Cara Menyalakan led hingga 100 itu?
terima kasih sebelumnya.
Contoh tersebut hanya bisa digunakan untuk maksimal 4 digit (yang *.M51) karena kita hanya menggunakan variabel Counter bertipe Word. Jika kita ingin meningkatkan hingga 6 digit, maka kita harus menggunakan array 3 byte. Dan proses perhitungannya juga harus dikaskade.
Saya menyarankan untuk menggunakan bahasa C saja biar lebih mudah. Caranya adalah mengganti tipe Counter menjadi unsigned long, karena unsigned int hanya bisa sampai 65565. Kita harus mengubah beberapa baris menjadi seperti berikut (saya kumpulkan menjadi satu, tidak seperti pada contoh program)
Dengan cara diatas, kita bisa menambah maksimal hitungan hingga 999999. Bahkan dengan menambah KodeDigit menjadi {0x1,0x2,0x4,0x8,0x10,0x20,0x40,0x80} dan MaskDigit menjadi selalu 0 baik untuk simulator maupun bukan, maka kita bisa membuah hitungan hingga 8 digit,yaitu 99999999. Karena sesungguhnya unsigned long itu batasnya adalah 4294967295.
Untuk led hingga 100 buah, caranya adalah dengan multiplex. Lihat pada led matiks dan susunlah led tersebut tidak sebagai matriks, tetapi sebagai led yang berjarar. Jadi jumlahnya kan bisa sebanyak yang kita mau. Akan tetapi tentu saja mengatur variasi nyala lampu hingga 100 buah juga bukan hal yang sederhana lho.
Akan lebih mudah jika kita memparalel beberapa led. Jadi nyala led ke 8, ke 16, ke 24, dst, akan sama dengan led pertama. Suatu saat akan saya tampilkan artikel untuk contoh tersebut. Tunggu saja ya.
OK, semoga berhasil.
BTW, Mas Iman itu hebat, baru SMA sudah main-main mikrokontroler. Keep learning!
mas, saya sudah beli bukunya.
terimakasih banyak, buku tersebut sangat bermanfaat.
tapi karena saya belajar sendiri, maklum waktu kuliah alat dan informasi masih terbatas. saya kesulitan tuk memahami
untuk mengirim data ke led matrix. sudikah mas menolong saya tuk membuat tutorial mengirim data ke led matrix dengan ppi
ic dipakai 74hc595 dan uln 2003.. oh iya mas saya hanya paham pakai bahasa assembly, karena lebih gampang..
pertanyaan yang sulit untuk dijawab jika informasinya tidak lengkap. pertama saya harus tahu bagaimana rangkaian led matriksnya dan bagaimana hubungannya dengan ppi (tidak harus skema yang lengkap, tp minimal blok diagramnya). kedua, pengiriman data ke led matriks disini maksudnya pengiriman data bagaimana? saya tunggu informasinya yang lebih lengkap. (tolong kirim langsung ke email saja).
assalamulaikum.
saya mau nanya ni,
gimana cara untuk membuat tanggal lahir 3 digit dari seven segment ?
atas jawabannya saya ucapkan terima kasih.
@novfalah: masih bingung dengan pertanyaannya. maksudnya gimana tuh, membuat tanggal lahir 3 digit? bisa lebih detil?
asslmualikum…..
mas gmn carA membuat counterup dan down…..3digit…
1. data lagi naik disimpan dimemori menggunakan interup up
2. data yg disimpan ditampilkan turun menggunakan interup down
trimakasih sebelumnya saya lagi belajar microcntroller….
ga paham dg interupt up dan interupt down, apaan tuh?
tp contoh di sini jg salah satunya menggunakan interupt, yg satu untuk menaikkan hitungan, dan yg lainnya untuk menurunkannya. jd kalo maksdumu adalah begitu, ya tinggal donlot aja kan?
mas sulhan saya sudah coba counter 3 digit mas sulhan dan berhasil yang jadi pertanyaannya saya kalau mas sulhan g keberatan kalau dalam hitungan mundur di bawah angka 10 untuk 0 digit kedua di non aktif kan gmana caranya yah mas sulhan sebagai contoh angka 8 saja yang muncul tetapi tidak muncul angka 08 semoga mas sulhan bisa memberi saya pencerahaannya.
owh, itu gampang aja, hanya perlu mengubah prosedur IsiBuffer menjadi seperti:
gampang kan? 😀
sudah saya coba mas sulhan ok tks y.
mas sulhan untuk program 3 digit saya belum coba menggunakan c dan baru mau coba menggunkana bahasa C , pertanyaan saya kalau mas sulhan g keberatan kalau dalam hitungan mundur di bawah angka 10 untuk 0 digit kedua di non aktif kan gmana caranya yah mas sulhan sebagai contoh angka 8 saja yang muncul tetapi tidak muncul angka 08 semoga mas sulhan bisa memberi saya pencerahaannya.
Caranya tidak ada bedanya dengan yang menggunakan assembly. Tinggal menganti bagian IsiBuffer agar memadamkan display paling kanan jika isinya menunjukkan bilangan nol.
Lumayan nih ada versi SDCC-nya, bisa buat studi banding.
Thanks…