Paralel Porttan 0-9 Yukarı Aşağı Sayici Yapımı
Bu uygulamamızda bir adet 7-segment displayden oluşan bir yukarı aşağı sayıcı yapmaya çalışacağız.Aslında bu uygulamanın amacı bilgisayarımızın paralel portunun (D25 tipi konnektör) data pinlerine bağlanacak bir 7-segment displayin yakılabilmesi için data pinlerine gönderilecek olan bilgileri göstermektir. Burada belirtmek isterim ki bilgisayarımızın portlarına displayi mümkünse doğrudan bağlamıyoruz bir adet Latch (d tipi filip floplardan oluşan ve kendisine verilen tetikleme sinyali ile girişlerindeki bilgileri çıkışa aktaran ve bir sonraki tetiklemeye kadar da çıkışlarını koruyan entegre) entegresi üzerinden bağlıyoruz ki port ile devre arasında bir katman oluşturmuş oluyoruz. Aslında bunlar tamamen elektronik konusu olup meraklıları nette konu ile ilgili gerekli bilgileri elde edebilirler. Ben burada kısaca belirtmek isterim VB.NET te bile doğrudan paralelport data pinlerine giriş-çıkış yapamıyoruz bu amaçla C++ da hazırlanmış bir takım .dll' lerden yararlanıyoruz. Her neyse, biz işimize bakalım. Uygulamamızı çalıştırabilmek için:
1) Her zaman olduğu gibi öncelikle bir Excel dokümanı oluşturup kaydedin. Aşağıda verilen hücre biçimlendirmelerini yapın, sonrasında Araçlar>Makro>Güvenlik komutları ile ekrana gelen pencerede Makro güvenliği sekmesinde Düşük seçemeğini işaretleyerek Tamam düğmesi ile onaylayın.Kaydet düğmesine basıp dokümanı kapatıp yeniden açın. Şekil-1 de verildiği üzere varsayılan olarak Sayfa1, üzerinde gerekli hücre birleştirme işlemlerini yapın.
Şekil-1
2.Sonrasında Görünüm > Araç çubukları ile ekrana gelen listeden Visual Basic araç çubuğunu işaretleyin. Bu araç çubuğunda tasarım modu (Şekil-2 / 3 numara) düğmesine basın.
Şekil-2
3) Yine Visual Basic araç çubuğunda yer alan Denetim Araç Kutusu düğmesine (Şekil-2 / 2 numara) basın ve kullanabileceğiz ocx nesnelerini görüntüleyin. Bunların arasından Komut düğmesi nesnesini tıklayın ve sonrasında farenin sol tuşunu basılı tutarak çalışma sayfası üzerinde sürükle bırak yönetimi ile Şekil-1 de verilen name özelliklerine (kırmızı ile yazılanlar) sahip 5 adet düğme çizin. Sonrasında bu düğmelerin üzerinde farenin sağ tuşuna basın ekrana gelen pop-up mönüden Özellikler/Properties tıklayın ve sırasıyla bu düğmelerin Caption özelliklerini (düğme üzerindeki yazıları) yine Şekil-1 de verildiği gibi yapın.
4) Veri giriş işlemlerini tamamladıktan sonra Klavyeden ALT+F11 tuşlarına basarak VBA kod editörünü açıyoruz. Burada (şayet ekrana gözükmüyorsa) Project Explorer penceresini ekrana getirmek için CTRL+L tuşlarına basıyoruz. Sonrasında Sayfa1 i çift tıklıyoruz ekrana gelen kod penceresine aşağıda verilen kodları yazıyoruz
'calisma sayfasinin General Declerations kısmına sayfa düzeyinde global değişkenlerimizi tanımlıyoruz.
Dim sayac As Integer, renkIndeksi As Byte
Dim bekle As Variant
Dim sayac As Integer, renkIndeksi As Byte
Dim bekle As Variant
Private Sub dijitleriGoruntule(deger As Integer, colorNumber As Byte, defColor As Byte)
'************************************************************************************************
'Coded By : Bilal SERT
'Creation Time / Date :
'Aim :
'Modified By :
'Modified Time /Date :
'Modification Aim :
'Possible I/O :
'Calls :
'Called By :
'************************************************************************************************
With Sayfa1
Select Case deger
Case 0:
.Cells(9, 4).Interior.ColorIndex = colorNumber 'd0-A
.Cells(10, 7).Interior.ColorIndex = colorNumber 'd1-B
.Cells(15, 7).Interior.ColorIndex = colorNumber 'd2-C
.Cells(19, 4).Interior.ColorIndex = colorNumber 'd3-D
.Cells(15, 4).Interior.ColorIndex = colorNumber 'd4-E
.Cells(10, 4).Interior.ColorIndex = colorNumber 'd5-F
.Cells(14, 4).Interior.ColorIndex = defColor 'd6-G
Case 1:
.Cells(9, 4).Interior.ColorIndex = defColor 'd0-A
.Cells(10, 7).Interior.ColorIndex = colorNumber 'd1-B
.Cells(15, 7).Interior.ColorIndex = colorNumber 'd2-C
.Cells(19, 4).Interior.ColorIndex = defColor 'd3-D
.Cells(15, 4).Interior.ColorIndex = defColor 'd4-E
.Cells(10, 4).Interior.ColorIndex = defColor 'd5-F
.Cells(14, 4).Interior.ColorIndex = defColor 'd6-G
Case 2:
.Cells(9, 4).Interior.ColorIndex = colorNumber 'd0-A
.Cells(10, 7).Interior.ColorIndex = colorNumber 'd1-B
.Cells(15, 7).Interior.ColorIndex = defColor 'd2-C
.Cells(19, 4).Interior.ColorIndex = colorNumber 'd3-D
.Cells(15, 4).Interior.ColorIndex = colorNumber 'd4-E
.Cells(10, 4).Interior.ColorIndex = defColor 'd5-F
.Cells(14, 4).Interior.ColorIndex = colorNumber 'd6-G
Case 3:
.Cells(9, 4).Interior.ColorIndex = colorNumber 'd0-A
.Cells(10, 7).Interior.ColorIndex = colorNumber 'd1-B
.Cells(15, 7).Interior.ColorIndex = colorNumber 'd2-C
.Cells(19, 4).Interior.ColorIndex = colorNumber 'd3-D
.Cells(15, 4).Interior.ColorIndex = defColor 'd4-E
.Cells(10, 4).Interior.ColorIndex = defColor 'd5-F
.Cells(14, 4).Interior.ColorIndex = colorNumber 'd6-G
Case 4:
.Cells(9, 4).Interior.ColorIndex = defColor 'd0-A
.Cells(10, 7).Interior.ColorIndex = colorNumber 'd1-B
.Cells(15, 7).Interior.ColorIndex = colorNumber 'd2-C
.Cells(19, 4).Interior.ColorIndex = defColor 'd3-D
.Cells(15, 4).Interior.ColorIndex = defColor 'd4-E
.Cells(10, 4).Interior.ColorIndex = colorNumber 'd5-F
.Cells(14, 4).Interior.ColorIndex = colorNumber 'd6-G
Case 5:
.Cells(9, 4).Interior.ColorIndex = colorNumber 'd0-A
.Cells(10, 7).Interior.ColorIndex = defColor 'd1-B
.Cells(15, 7).Interior.ColorIndex = colorNumber 'd2-C
.Cells(19, 4).Interior.ColorIndex = colorNumber 'd3-D
.Cells(15, 4).Interior.ColorIndex = defColor 'd4-E
.Cells(10, 4).Interior.ColorIndex = colorNumber 'd5-F
.Cells(14, 4).Interior.ColorIndex = colorNumber 'd6-G
Case 6:
.Cells(9, 4).Interior.ColorIndex = colorNumber 'd0-A
.Cells(10, 7).Interior.ColorIndex = defColor 'd1-B
.Cells(15, 7).Interior.ColorIndex = colorNumber 'd2-C
.Cells(19, 4).Interior.ColorIndex = colorNumber 'd3-D
.Cells(15, 4).Interior.ColorIndex = colorNumber 'd4-E
.Cells(10, 4).Interior.ColorIndex = colorNumber 'd5-F
.Cells(14, 4).Interior.ColorIndex = colorNumber 'd6-G
Case 7:
.Cells(9, 4).Interior.ColorIndex = colorNumber 'd0-A
.Cells(10, 7).Interior.ColorIndex = colorNumber 'd1-B
.Cells(15, 7).Interior.ColorIndex = colorNumber 'd2-C
.Cells(19, 4).Interior.ColorIndex = defColor 'd3-D
.Cells(15, 4).Interior.ColorIndex = defColor 'd4-E
.Cells(10, 4).Interior.ColorIndex = defColor 'd5-F
.Cells(14, 4).Interior.ColorIndex = defColor 'd6-G
Case 8:
.Cells(9, 4).Interior.ColorIndex = colorNumber 'd0-A
.Cells(10, 7).Interior.ColorIndex = colorNumber 'd1-B
.Cells(15, 7).Interior.ColorIndex = colorNumber 'd2-C
.Cells(19, 4).Interior.ColorIndex = colorNumber 'd3-D
.Cells(15, 4).Interior.ColorIndex = colorNumber 'd4-E
.Cells(10, 4).Interior.ColorIndex = colorNumber 'd5-F
.Cells(14, 4).Interior.ColorIndex = colorNumber 'd6-G
Case 9:
.Cells(9, 4).Interior.ColorIndex = colorNumber 'd0-A
.Cells(10, 7).Interior.ColorIndex = colorNumber 'd1-B
.Cells(15, 7).Interior.ColorIndex = colorNumber 'd2-C
.Cells(19, 4).Interior.ColorIndex = colorNumber 'd3-D
.Cells(15, 4).Interior.ColorIndex = defColor 'd4-E
.Cells(10, 4).Interior.ColorIndex = colorNumber 'd5-F
.Cells(14, 4).Interior.ColorIndex = colorNumber 'd6-G
End Select
End With
End Sub
Private Sub pinleriRenklendir(deger As Integer, colorNumber As Byte, defColor As Byte)
'************************************************************************************************
'Coded By : Bilal SERT
'Creation Time / Date :
'Aim :
'Modified By :
'Modified Time /Date :
'Modification Aim :
'Possible I/O :
'Calls :
'Called By :
'************************************************************************************************
With Sayfa1
Select Case deger
Case 0:
.Cells(4, 4) = 1 'd0-A
.Cells(4, 5) = 1 'd1-B
.Cells(4, 6) = 1 'd2-C
.Cells(4, 7) = 1 'd3-D
.Cells(4, 8) = 1 'd4-E
.Cells(4, 9) = 1 'd5-F
.Cells(4, 10) = 0 'd6-G
'Pinler renklendiriliyor
.Cells(4, 4).Interior.ColorIndex = colorNumber 'd0-A
.Cells(4, 5).Interior.ColorIndex = colorNumber 'd1-B
.Cells(4, 6).Interior.ColorIndex = colorNumber 'd2-C
.Cells(4, 7).Interior.ColorIndex = colorNumber 'd3-D
.Cells(4, 8).Interior.ColorIndex = colorNumber 'd4-E
.Cells(4, 9).Interior.ColorIndex = colorNumber 'd5-F
.Cells(4, 10).Interior.ColorIndex = defColor 'd6-G
Case 1:
.Cells(4, 4) = 0 'd0-A
.Cells(4, 5) = 1 'd1-B
.Cells(4, 6) = 1 'd2-C
.Cells(4, 7) = 0 'd3-D
.Cells(4, 8) = 0 'd4-E
.Cells(4, 9) = 0 'd5-F
.Cells(4, 10) = 0 'd6-G
'Pinler renklendiriliyor
.Cells(4, 4).Interior.ColorIndex = defColor 'd0-A
.Cells(4, 5).Interior.ColorIndex = colorNumber 'd1-B
.Cells(4, 6).Interior.ColorIndex = colorNumber 'd2-C
.Cells(4, 7).Interior.ColorIndex = defColor 'd3-D
.Cells(4, 8).Interior.ColorIndex = defColor 'd4-E
.Cells(4, 9).Interior.ColorIndex = defColor 'd5-F
.Cells(4, 10).Interior.ColorIndex = defColor 'd6-G
Case 2:
.Cells(4, 4) = 1 'd0-A
.Cells(4, 5) = 1 'd1-B
.Cells(4, 6) = 0 'd2-C
.Cells(4, 7) = 1 'd3-D
.Cells(4, 8) = 1 'd4-E
.Cells(4, 9) = 0 'd5-F
.Cells(4, 10) = 1 'd6-G
'Pinler renklendiriliyor
.Cells(4, 4).Interior.ColorIndex = colorNumber 'd0-A
.Cells(4, 5).Interior.ColorIndex = colorNumber 'd1-B
.Cells(4, 6).Interior.ColorIndex = defColor 'd2-C
.Cells(4, 7).Interior.ColorIndex = colorNumber 'd3-D
.Cells(4, 8).Interior.ColorIndex = colorNumber 'd4-E
.Cells(4, 9).Interior.ColorIndex = defColor 'd5-F
.Cells(4, 10).Interior.ColorIndex = colorNumber 'd6-G
Case 3:
.Cells(4, 4) = 1 'd0-A
.Cells(4, 5) = 1 'd1-B
.Cells(4, 6) = 1 'd2-C
.Cells(4, 7) = 1 'd3-D
.Cells(4, 8) = 0 'd4-E
.Cells(4, 9) = 0 'd5-F
.Cells(4, 10) = 1 'd6-G
'Pinler renklendiriliyor
.Cells(4, 4).Interior.ColorIndex = colorNumber 'd0-A
.Cells(4, 5).Interior.ColorIndex = colorNumber 'd1-B
.Cells(4, 6).Interior.ColorIndex = colorNumber 'd2-C
.Cells(4, 7).Interior.ColorIndex = colorNumber 'd3-D
.Cells(4, 8).Interior.ColorIndex = defColor 'd4-E
.Cells(4, 9).Interior.ColorIndex = defColor 'd5-F
.Cells(4, 10).Interior.ColorIndex = colorNumber 'd6-G
Case 4:
.Cells(4, 4) = 0 'd0-A
.Cells(4, 5) = 1 'd1-B
.Cells(4, 6) = 1 'd2-C
.Cells(4, 7) = 0 'd3-D
.Cells(4, 8) = 0 'd4-E
.Cells(4, 9) = 1 'd5-F
.Cells(4, 10) = 1 'd6-G
'Pinler renklendiriliyor
.Cells(4, 4).Interior.ColorIndex = defColor 'd0-A
.Cells(4, 5).Interior.ColorIndex = colorNumber 'd1-B
.Cells(4, 6).Interior.ColorIndex = colorNumber 'd2-C
.Cells(4, 7).Interior.ColorIndex = defColor 'd3-D
.Cells(4, 8).Interior.ColorIndex = defColor 'd4-E
.Cells(4, 9).Interior.ColorIndex = colorNumber 'd5-F
.Cells(4, 10).Interior.ColorIndex = colorNumber 'd6-G
Case 5:
.Cells(4, 4) = 1 'd0-A
.Cells(4, 5) = 0 'd1-B
.Cells(4, 6) = 1 'd2-C
.Cells(4, 7) = 1 'd3-D
.Cells(4, 8) = 0 'd4-E
.Cells(4, 9) = 1 'd5-F
.Cells(4, 10) = 1 'd6-G
'Pinler renklendiriliyor
.Cells(4, 4).Interior.ColorIndex = colorNumber 'd0-A
.Cells(4, 5).Interior.ColorIndex = defColor 'd1-B
.Cells(4, 6).Interior.ColorIndex = colorNumber 'd2-C
.Cells(4, 7).Interior.ColorIndex = colorNumber 'd3-D
.Cells(4, 8).Interior.ColorIndex = defColor 'd4-E
.Cells(4, 9).Interior.ColorIndex = colorNumber 'd5-F
.Cells(4, 10).Interior.ColorIndex = colorNumber 'd6-G
Case 6:
.Cells(4, 4) = 1 'd0-A
.Cells(4, 5) = 0 'd1-B
.Cells(4, 6) = 1 'd2-C
.Cells(4, 7) = 1 'd3-D
.Cells(4, 8) = 1 'd4-E
.Cells(4, 9) = 1 'd5-F
.Cells(4, 10) = 1 'd6-G
'Pinler renklendiriliyor
.Cells(4, 4).Interior.ColorIndex = colorNumber 'd0-A
.Cells(4, 5).Interior.ColorIndex = defColor 'd1-B
.Cells(4, 6).Interior.ColorIndex = colorNumber 'd2-C
.Cells(4, 7).Interior.ColorIndex = colorNumber 'd3-D
.Cells(4, 8).Interior.ColorIndex = colorNumber 'd4-E
.Cells(4, 9).Interior.ColorIndex = colorNumber 'd5-F
.Cells(4, 10).Interior.ColorIndex = colorNumber 'd6-G
Case 7:
.Cells(4, 4) = 1 'd0-A
.Cells(4, 5) = 1 'd1-B
.Cells(4, 6) = 1 'd2-C
.Cells(4, 7) = 0 'd3-D
.Cells(4, 8) = 0 'd4-E
.Cells(4, 9) = 0 'd5-F
.Cells(4, 10) = 0 'd6-G
'Pinler renklendiriliyor
.Cells(4, 4).Interior.ColorIndex = colorNumber 'd0-A
.Cells(4, 5).Interior.ColorIndex = colorNumber 'd1-B
.Cells(4, 6).Interior.ColorIndex = colorNumber 'd2-C
.Cells(4, 7).Interior.ColorIndex = defColor 'd3-D
.Cells(4, 8).Interior.ColorIndex = defColor 'd4-E
.Cells(4, 9).Interior.ColorIndex = defColor 'd5-F
.Cells(4, 10).Interior.ColorIndex = defColor 'd6-G
Case 8:
.Cells(4, 4) = 1 'd0-A
.Cells(4, 5) = 1 'd1-B
.Cells(4, 6) = 1 'd2-C
.Cells(4, 7) = 1 'd3-D
.Cells(4, 8) = 1 'd4-E
.Cells(4, 9) = 1 'd5-F
.Cells(4, 10) = 1 'd6-G
'Pinler renklendiriliyor
.Cells(4, 4).Interior.ColorIndex = colorNumber 'd0-A
.Cells(4, 5).Interior.ColorIndex = colorNumber 'd1-B
.Cells(4, 6).Interior.ColorIndex = colorNumber 'd2-C
.Cells(4, 7).Interior.ColorIndex = colorNumber 'd3-D
.Cells(4, 8).Interior.ColorIndex = colorNumber 'd4-E
.Cells(4, 9).Interior.ColorIndex = colorNumber 'd5-F
.Cells(4, 10).Interior.ColorIndex = colorNumber 'd6-G
Case 9:
.Cells(4, 4) = 1 'd0-A
.Cells(4, 5) = 1 'd1-B
.Cells(4, 6) = 1 'd2-C
.Cells(4, 7) = 1 'd3-D
.Cells(4, 8) = 0 'd4-E
.Cells(4, 9) = 1 'd5-F
.Cells(4, 10) = 1 'd6-G
'Pinler renklendiriliyor
.Cells(4, 4).Interior.ColorIndex = colorNumber 'd0-A
.Cells(4, 5).Interior.ColorIndex = colorNumber 'd1-B
.Cells(4, 6).Interior.ColorIndex = colorNumber 'd2-C
.Cells(4, 7).Interior.ColorIndex = colorNumber 'd3-D
.Cells(4, 8).Interior.ColorIndex = defColor 'd4-E
.Cells(4, 9).Interior.ColorIndex = colorNumber 'd5-F
.Cells(4, 10).Interior.ColorIndex = colorNumber 'd6-G
End Select
End With
End Sub
Private Sub btnAsagiSay_Click()
If btnAsagiSay.Caption = "AŞAĞI SAY" Then
btnAsagiSay.Caption = "DUR"
btnYukariSay.Enabled = False
Else
btnAsagiSay.Caption = "AŞAĞI SAY"
btnYukariSay.Enabled = True
End If
Do
If IsEmpty(sayac) Then
sayac = 9
Else
If sayac > 0 Then
sayac = sayac - 1
Else
sayac = 9
End If
End If
Sayfa1.Cells(9, 9) = sayac
If IsNumeric(Sayfa1.Cells(4, 13)) Then
renkIndeksi = Sayfa1.Cells(4, 13)
Else
renkIndeksi = 3
End If
pinleriRenklendir sayac, renkIndeksi, 0
dijitleriGoruntule sayac, renkIndeksi, 0
bekle = Timer
Do
DoEvents
Loop Until Timer > bekle + 0.5
Loop Until btnAsagiSay.Caption = "AŞAĞI SAY"
End Sub
Private Sub btnExit_Click()
ThisWorkbook.Application.DisplayAlerts = False
Application.Quit
End Sub
Private Sub btnRenkIndeksi_Click()
Dim i As Integer
For i = 1 To 50
Sayfa1.Cells(i, 1) = i
Sayfa1.Cells(i, 1).Interior.ColorIndex = i
Next
End Sub
Private Sub btnSaveAndExit_Click()
ThisWorkbook.Save
ThisWorkbook.Application.Quit
End Sub
Private Sub btnYukariSay_Click()
If btnYukariSay.Caption = "YUKARI SAY" Then
btnYukariSay.Caption = "DUR"
btnAsagiSay.Enabled = False
Else
btnYukariSay.Caption = "YUKARI SAY"
btnAsagiSay.Enabled = True
End If
Do
If IsEmpty(sayac) Then
sayac = 0
Else
If sayac < 9 Then
sayac = sayac + 1
Else
sayac = 0
End If
End If
Sayfa1.Cells(9, 9) = sayac
If IsNumeric(Sayfa1.Cells(4, 13)) Then
renkIndeksi = Sayfa1.Cells(4, 13)
Else
renkIndeksi = 3
End If
pinleriRenklendir sayac, renkIndeksi, 0
dijitleriGoruntule sayac, renkIndeksi, 0
bekle = Timer
Do
DoEvents
Loop Until Timer > bekle + 0.5
Loop Until btnYukariSay.Caption = "YUKARI SAY"
End Sub
Yukarıda verilenler aslında oldukça basit bir algoritmaya dayanıyor sayac değişkeni ile kontrol edilen bir 0-9 ya da 9-0 arasındaki değer alınıyor dijitleriGoruntule() alt programı ile 7-segment bir display görüntüsü oluşturacak şekilde ilgili hücrelerin arka planları boyanıyor. Aynı şekilde paralel portun data pinlerini simgeleyen hücrelerde lojik 1 gelirse yeşil, lojik 0 gelirse dolgu rengi olmayacak biçimde boyanıyorlar. Bu olaylar siz durdurana kadar tekrarlanıyor. Bir diğer önemli hususta VBA da Timer() adında yani belirli zaman aralıklarında belirli bir kodu işletecek ocx nesnesinin olmamasıdır. Bu problemi do-loop döngüsü ile sistemi boşa döndürerek çözdük ancak burada dikkat etmeniz gereken nokta DoEvents satırıdır. Bunu yazmazsanız sisteminiz (kısa aralıklarla) kilitlenecektir. DoEvents satırı işletildiği anda VBA klavye vb. kontrollerin denetimini yeniden size verecektir. Güç sizinle olsun...
Yardımcı olması dileğiyle