Professional Documents
Culture Documents
Example Program
This example program comes with the library. You can open it from the File -> Examples -
> ks0108 -> GLCDexample menu; More information can be found on the official GLCD web
page.
/*
* GLCDexample
*
* Basic test code for the Arduino KS0108 GLCD library.
* This code exercises a range of graphic functions supported
* by the library and is an example of its use.
* It also gives an indication of performance, showing the
* number of frames drawn per second.
*/
#include <ks0108.h>
#include "Arial14.h" // proportional font
#include "SystemFont5x7.h" // system font
#include "ArduinoIcon.h" // bitmap
void setup(){
delay(500); // allow time for LCD to reset
GLCD.Init(NON_INVERTED); // initialise the library, non inverted writes
pixels onto a clear screen
GLCD.ClearScreen();
GLCD.DrawBitmap(ArduinoIcon, 32,0, BLACK); //draw the bitmap at the given
x,y position
GLCD.SelectFont(System5x7); // switch to fixed width system font
countdown(5);
GLCD.ClearScreen();
introScreen(); // show some intro stuff
GLCD.ClearScreen();
}
void introScreen(){
GLCD.SelectFont(Arial_14); // you can also make your own fonts, see
playground for details
GLCD.GotoXY(20, 2);
GLCD.Puts("GLCD version ");
GLCD.PrintNumber(GLCD_VERSION);
GLCD.DrawRoundRect(16,0,99,18, 5, BLACK); // rounded rectangle around text
area
GLCD.SelectFont(System5x7); // switch to fixed width system font
showCharacters();
countdown(5);
}
void showCharacters(){
byte line = 3; // start on the fourth line
for(byte c = 32; c <=127; c++){
if( (c-32) % 20 == 0)
GLCD.CursorTo(1,line++); // CursorTo is used for fixed width system
font
GLCD.PutChar(c);
}
}
Alternate connections for Teensy 2.0: (you must edit the code to enable this connection)
The display requires a contrast adjustment potentiometer. A value of 5K or 10K works well. The
center terminal must connect to the "Contrast Adjust" pin (Vo). The two side terminals must
connect to the "Contrast Power" pin (Vee) and Ground. It does not matter which sides of the
potentiometer you connect these 2 signals, as the reverse connection will simply make the
clockwise rotation adjust in the opposite direction.
The reset pin should be connected to +5 volts. It is not necessary to drive the reset pin low before
using the LCD.
Alternately, the reset pin may be connected to any unused pin on your Teensy, if you want a
hardware connection that resets the LCD to its default state. Before initializing the LCD, output a
low to reset the LCD, then high to allow it to operate. For example:
void setup() {
pinMode(3, OUTPUT);
digitalWrite(3, LOW); // reset the LCD
delay(10);
digitalWrite(3, HIGH); // allow it to run
GLCD.Init(NON_INVERTED);
GLCD.ClearScreen();
}
More Photos
See below for the pinout of the display. The display has 8 data bits and 5 control bits. The
databits are hooked to PORTB and the control bits are hooked to PORTD of the Mega16. A
small PCB board is made for easy connection to the microcontroller. The programs are made
with the BASCOM-AVR compiler which has various functions to control the GLCD. The
program shows text and a picture on the display. A library file needs to be included in the
BASCOM program file, the library contains commands to control the display like
Setfont - Sets the current font which can be used on the graphical displays.
Lcdat - shows text on the display
$BGF - Includes a BASCOM Graphic File in the program.
Showpic - shows a graphic file on the display
Line - draws a line on the display
Circle - draws a circle on the display
Pset - Sets a single pixel on the display
Control
If you want to show text on the display you need to include a font file in the BASCOM program.
There are several fonts available like a 8x8 font and a 16x16 font, but the font file consume
memory, the larger the font file the larger the program becomes. You can also create your own
font, there are applications on the web to create your own fonts.
To show a picture on the display you need to include a picture file, they also consume a lot of
space in the microcontroller memory.
Left you see a picture with the characterset that uses the smaller font set 8x8. It has 255 different
characters. The program glcdks108_txt.txt can downloaded below.
'----------------------------------------------------------------------------
-------------
'name : glcd_chr.bas
'copyright : (c) www.avrprojects.net
'purpose : demonstrates the KS108 based graphical display
support
' ; shows the characterset on the graphical display
'microcontroller : Mega16
'----------------------------------------------------------------------------
-------------
Setfont Font16x16
Cls
Lcdat 1 , 1 , "Hello"
Lcdat 3 , 1 , "World"
Lcdat 5 , 1 , "How are"
Lcdat 7 , 1 , "you?"
End
$include "font16x16.font"
'----------------------------------------------------------------------------
-------------
'name : glcd_chr.bas
'auhtor : www.avrprojects.net
'purpose : demonstrates the KS108 based graphical display
support
' : shows the characterset on the graphical display
'target microcontroller : Mega16
'----------------------------------------------------------------------------
-------------
Setfont Font8x8
Do
Cls
Char = 31
For L = 1 To 8
For C = 0 To 127 Step 8
Char = Char + 1
Lcdat L , C , Chr(char)
Next C
Next L
Wait 2
Cls
Char = 128
For L = 1 To 8
For C = 0 To 127 Step 8
Char = Char + 1
Lcdat L , C , Chr(char)
Next C
Next L
Wait 2
Loop
End
$include "font8x8.font"
Seven segment counter up/down dengan mikrokontroler avr
Mikrokontroler, Simulasi Elektronik
Seven segment adalah penampil yang terdiri atas 7 bagian segment yang digunakan untuk menampilkan
angka atau beberapa huruf. Secara umum device ini digunakan untuk menampilkan suatu angka atau
huruf yang didapat dari proses pengaturan/pemberian masukan digital pada pin-pinnya. Kali ini saya
akan sharing mengenai salah satu aplikasi dari seven segment display yaitu counter Up/Down yang
memungkinkan untuk proses increment dan decrement dari suatu nilai.
Seven segment yang digunakan ialah berjenis CA (Common Anoda) dengan penggeraknya (driver)
menggunakan IC decoder BCD to 7segment yaitu IC 74ls47. Dengan menggunakan IC ini maka kita
hanya perlu memberikan masukan biner 4 digit yang kemudian akan dikonversi ke tampilan seven
segment.
Dim C As Integer
Dim A As Integer
Portc = 1
Porta = 1
C=0
A=0
Do
Portc = C
Porta = A
If Tambah = 0 Then
Bitwait Tambah , Set
Incr C
If C = 10 Then
C=0
Incr A
If A = 10 Then
A=0
End If
End If
End If
If Kurang = 0 Then
Bitwait Kurang , Set
If C = 0 Then
C = 10
Decr C
If A = 0 Then
A = 10
Decr A
Else
Decr A
End If
Else
Decr C
End If
End If
Waitms 200
Loop
Counter turun (down counter ) dengan tampilan seven segment pada
mikrokontroler at mega 16 dengan pemrograman basic memanfaatkan
bascom (basic compiler)
Posted by Unknown at 11:04 PM
Penghitungan turun pada mikrokontroler at mega 16 dapat dilakukan pada event (meminjam istilah
pada Delphi nih) saat tombol interupsi dalam kondisi low level maupun pada event-event yang lain…
terserah panjenengan saja sebagai pengembang aplikasi karena hal ini bersifat opsional tergantung
kebutuhan dn kreatifitas anda (butuh otak kiri dan otak kanan untuk bisa sukses di dunia
mikrokontroller)
Pemanfaatan interrupt pada pilihan enable saat kondisi low level sebagai inputan, dimaksudkan untuk
menghindari double counting (penghitungan dobel) bahkan tidak hanya dobel malah bisa lebih dari itu..
penjelasannya adalah sebagai berikut : ketika yang dipergunakan adalah logika ketikan PINA.0 , PINB.x,
PINC.x atauPIND.x maka yang terjadi ketika logika pada masing masing pin yang dimaksud berlogika nol
maka penghitungan turun akan terus dilakukan, tentunya hal ini akan menyebabkan aplikasi berjalan
tidak sebagaimana mestinya.
Selanjutnya akan saya tampilkan rangkaian pada simulai proteus yang dipergunakan pada percobaan ini,
berikut adalah gambar nya : (ingat pin interrupt interrupt pada pada mikrokontroller dapat anda cek
pada configurasi pin pada datasheet mikorokontroller ) silakan lihat gambar saja ya…
Untuk coding down counter memanfaatkan bascom (basic compiler), silakan lihat coding di
bawah ini :
$regfile = "m16def.dat"
$crystal = 8000000
Do
Gosub Tampil
If Nsat = -1 Then
Nsat = 9
Decr Npul
End If
If Npul = -1 Then
Npul = 9
Decr Nrat
End If
If Nrat = -1 Then
Nrat = 9
' Decr Nrib
End If
If Npul = 0 And Nsat = 0 Then
If Nrat = 0 Then
Goto Mundur
End If
End If
Gosub Tampil
Decr Nsat
Reset Strobe
Loop
Tampil:
Reset Strobe
Kodesat = Lookup(nsat , Kode)
Kodepul = Lookup(npul , Kode)
Koderat = Lookup(nrat , Kode)
'Koderib = Lookup(nrib , Kode)
'Shiftout Datain , Clock , Koderib , 1
Shiftout Datain , Clock , Koderat , 1
Shiftout Datain , Clock , Kodepul , 1
Shiftout Datain , Clock , Kodesat , 1
Waitms 1
Set Strobe
Waitms 100
Return
Kode:
Data &HC0 , &HF9 , &HA4 , &HB0 , &H99 , &H92 , &H82 , &HF8 , &H80 , &H90
Anda klenger ngeliatnya ? sama … saya juga tapi tenang saja dengan anda belajar sedikit saja,
saya pastikan anda akan berhasil memahaminya (semoga tidak semakin klenger ya…..)
Programnya:
$regfile = "m8def.dat"
$crystal = 8000000
Enable Interrupts
Enable Timer2
Enable Timer0
'enable Timer1
Portb = &B11111111
Portd = &B11111111
Portc = &B11111111
If Alarm2 = 1 Then
Set Portb.4
If G = Ga And M = Ma Then
Alarm = 1
End If
If Alarm = 1 Then
End If
Else
Reset Portb.4
End If
Loop
End
If S = 60 Then
S=0
Incr M
End If
If M = 60 Then
M=0
Incr G
End If
If G = 24 Then
G=0
M=0
S=0
End If
Return
Wyswietlanie:
Timer0 = 6
Incr Ktory_w
If Ktory_w = 4 Then
Ktory_w = 0
End If
If Pinc.2 = 1 Then
End If
If Pinc.2 = 0 Then
Select Case Ktory_w
Case 0:
Set Portb.3
Wysw = Ga / 10
Wysw = Lookup(wysw , Tabela)
Portd = Wysw
Reset Portb.0
Case 1:
Set Portb.0
Wysw = Ga Mod 10
Wysw = Lookup(wysw , Tabela)
Portd = Wysw
Reset Portb.1
Reset Portd.7
Case 2:
Set Portb.1
Set Portd.7
Wysw = Ma / 10
Wysw = Lookup(wysw , Tabela)
Portd = Wysw
Reset Portb.2
Case 3:
Set Portb.2
Wysw = Ma Mod 10
Wysw = Lookup(wysw , Tabela)
Portd = Wysw
Reset Portb.3
End Select
End If
Return
Tabela:
Data 192 , 249 , 164 , 176 , 153 , 146 , 130 , 248 , 128 , 144
'znak: 0 1 2 3 4 5 6 7 8 9