GLCD
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
unsigned long startMillis;
unsigned int loops = 0;
unsigned int iter = 0;
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);
}
}
void drawSpinner(byte pos, byte x, byte y) {
// this draws an object that appears to spin
switch(pos % 8) {
case 0 : GLCD.DrawLine( x, y-8, x, y+8, BLACK); break;
case 1 : GLCD.DrawLine( x+3, y-7, x-3, y+7, BLACK); break;
case 2 : GLCD.DrawLine( x+6, y-6, x-6, y+6, BLACK); break;
case 3 : GLCD.DrawLine( x+7, y-3, x-7, y+3, BLACK); break;
case 4 : GLCD.DrawLine( x+8, y, x-8, y, BLACK); break;
case 5 : GLCD.DrawLine( x+7, y+3, x-7, y-3, BLACK); break;
case 6 : GLCD.DrawLine( x+6, y+6, x-6, y-6, BLACK); break;
case 7 : GLCD.DrawLine( x+3, y+7, x-3, y-7, BLACK); break;
}
}
void countdown(int count){
while(count--){ // do countdown
GLCD.CursorTo(0,1); // first column, second row (offset is from 0)
GLCD.PutChar(count + '0');
delay(1000);
}
}
void loop(){ // run over and over again
iter = 0;
startMillis = millis();
while( millis() - startMillis < 1000){ // loop for one second
GLCD.DrawRect(0, 0, 64, 61, BLACK); // rectangle in left side of screen
GLCD.DrawRoundRect(68, 0, 58, 61, 5, BLACK); // rounded rectangle around
text area
for(int i=0; i < 62; i += 4)
GLCD.DrawLine(1,1,63,i, BLACK); // draw lines from upper left down
right side of rectangle
GLCD.DrawCircle(32,31,30,BLACK); // draw circle centered in the left
side of screen
GLCD.FillRect(92,40,16,16, WHITE); // clear previous spinner position
drawSpinner(loops++,100,48); // draw new spinner position
//GLCD.FillRect(24,txtLINE3,14,14, WHITE); // clear text area that will
be drawn below
GLCD.CursorTo(5,5); // locate curser for printing text
GLCD.PrintNumber(++iter); // print current iteration at the
current cursor position
}
// display number of iterations in one second
GLCD.ClearScreen(); // clear the screen
GLCD.CursorTo(14,2); // positon cursor
GLCD.Puts("FPS= "); // print a text string
GLCD.PrintNumber(iter); // print a number
}
Connecting the LCD to Teensy or Teensy++
Standard Connections for Teensy++ 1.0 or 2.0:
Standard Connections for Teensy 2.0:
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
Teensy 2.0 with 128x64 LCD running the example program
If you have used a Teensy with a this library, please send a photo to add to this page. Be sure to
include the model or info about the LCD, and if you'd like you name or email to appear
GLCD KS108 Interface
A Graphical LCD (GLCD) is an LCD that can show pictures and text, The come in different
sizes. The GLCD used here is a 128x64 pixels.The GLCD is controlled with the ATMega16, the
GLCD HG1286418C-VA with a S6B0107/S6B0108 controller is used.
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.
And a picture with big text that uses the bigger
16x16 font, displayed on the GLCD, progams made in BASCOM-AVR. The
program glcdks108_txt.bas can downloaded below.
This pictures shows text and a sine and cosin,
displayed on the GLCD, progams made in BASCOM-AVR.
This is a blue GLCD from Crystalfonts, it has
the same pinout, only the connection of the white background LED is reversed
'----------------------------------------------------------------------------
-------------
'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
'----------------------------------------------------------------------------
-------------
$regfile = "m16def.dat" ' specify the
used micro
$crystal = 10000000 ' used crystal
frequency
$lib "glcdKS108.lbx"
'First we define that we use a graphic LCD
Config Graphlcd = 128 * 64sed , Dataport = Portb , Controlport = Portd , Ce =
0 , Ce2 = 1 , Cd = 4 , Rd = 3 , Reset = 2 , Enable = 5
Setfont Font16x16
Dim Char As Byte , L As Byte , C As Byte
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
'----------------------------------------------------------------------------
-------------
$regfile = "m16def.dat" ' specify the
used micro
$crystal = 10000000 ' used crystal
frequency
$lib "glcdKS108.lbx"
'First we define that we use a graphic LCD
Config Graphlcd = 128 * 64sed , Dataport = Portb , Controlport = Portd , Ce =
0 , Ce2 = 1 , Cd = 4 , Rd = 3 , Reset = 2 , Enable = 5
Setfont Font8x8
Dim Char As Byte , L As Byte , C As Byte
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.
Source Code (Bascom AVR):
$regfile = "m16def.dat"
$crystal = 12000000
Config Portc = Output
Config Porta = Output
Config Pind.6 = Input
Config Pind.7 = Input
Dim C As Integer
Dim A As Integer
Tambah Alias Pind.6
Kurang Alias Pind.7
Set Tambah
Set Kurang
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
Config Portc.0 = Output
Config Portc.1 = Output
Config Portc.2 = Output
Datain Alias Portc.0
Clock Alias Portc.1
Strobe Alias Portc.2
Dim Kodesat As Byte , Npul As Integer , Nsat As Integer , Kodepul As Byte
Dim Koderat As Byte , Nrat As Integer
Mundur:
'Nrib = 9
Nrat = 9
Npul = 9
Nsat = 9
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
'Konfiguracja Timer2 w trybie asynchrinicznym
Config Timer2 = Timer , Async = On , Prescale = 128
On Timer2 Zegar
'Konfiguracja Timer0 dla wyœwietlania
Config Timer0 = Timer , Prescale = 64
On Timer0 Wyswietlanie
'Config Timer1 = Timer , Prescale = 1
'On Timer1 Przyciski
Enable Interrupts
Enable Timer2
Enable Timer0
'enable Timer1
'******************** ZMIENNE ********************
Dim S As Byte 'Sekunda
Dim M As Byte 'Minuta
Dim G As Byte 'Godzina
Dim Ga As Byte 'Godzina Alarmu
Dim Ma As Byte 'Minuta Alarmu
Dim Alarm As Bit 'Alarm ON/OFF
Dim Alarm2 As Bit
Dim Ktory_w As Byte
Dim Wysw As Byte
Config Portc = 11100000
Config Portb = Output
Config Portd = Output
Portb = &B11111111
Portd = &B11111111
Portc = &B11111111
'************* Program G³ówny ***********
Do
If Pinc.4 = 0 And Pinc.1 = 0 Then
Incr M
If M = 60 Then
M=0
End If
Waitms 200
End If
If Pinc.3 = 0 And Pinc.1 = 0 Then
Incr G
If G = 24 Then
G=0
End If
Waitms 200
End If
If Pinc.4 = 0 And Pinc.2 = 0 Then
Incr Ma
If Ma = 60 Then
Ma = 0
End If
Waitms 200
End If
If Pinc.3 = 0 And Pinc.2 = 0 Then
Incr Ga
If Ga = 24 Then
Ga = 0
End If
Waitms 200
End If
If Pinc.2 = 0 And Pinc.0 = 0 Then
Toggle Alarm2
Waitms 200
End If
If Alarm2 = 1 Then
Set Portb.4
If G = Ga And M = Ma Then
Alarm = 1
End If
If Alarm = 1 Then
'Pikanie buzzera podczas alarmu
Portc.5 = 0
Waitms 75
Portc.5 = 1
Waitms 75
Portc.5 = 0
Waitms 75
Portc.5 = 1
Waitms 500
Portc.5 = 0
Waitms 75
Portc.5 = 1
Waitms 75
Portc.5 = 0
Waitms 75
Portc.5 = 1
Waitms 500
End If
Else
Reset Portb.4
End If
Loop
End
'***************** Podprogramy *****************
Zegar: 'Przerywanie Timer2
Incr S
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.0 = 0 And Alarm = 1 Then
Alarm = 0
Alarm2 = 0
End If
If Pinc.2 = 1 Then
Select Case Ktory_w
Case 0:
Set Portb.3
Wysw = G / 10
Wysw = Lookup(wysw , Tabela)
Portd = Wysw
Reset Portb.0
Case 1:
Set Portb.0
Wysw = G Mod 10
Wysw = Lookup(wysw , Tabela)
Portd = Wysw
Reset Portb.1
Reset Portd.7
Case 2:
Set Portb.1
Set Portd.7
Wysw = M / 10
Wysw = Lookup(wysw , Tabela)
Portd = Wysw
Reset Portb.2
Case 3:
Set Portb.2
Wysw = M Mod 10
Wysw = Lookup(wysw , Tabela)
Portd = Wysw
Reset Portb.3
End Select
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