Sei sulla pagina 1di 7

KONEKSI ARDUINO UNO DENGAN GLCD 128X64:

PIN NAME PORT STANDARD PORT REVISI


1 VSS GND GND
2 VDD +5 +5
3 VO
4 RS A3 A0
5 R/W A2 A1
6 E A4 A2
7 D0 8 2
8 D1 9 3
9 D2 10 4
10 D3 11 5
11 D4 4 6
12 D5 5 7
13 D6 6 8
14 D7 7 9
15 CS1 A0 11
16 CS2 A1 12
17 RST RST RST
18 VOUT
19 LED+
20 LED- GND GND

PORT REVISI dilakukan agar A4 dan A5 bisa digunakan sebagai I2C.


Langkah-langkah programming GLCD 128x64 dengan Arduino Uno

1. Download openGLCD (zip file)


2. Biarkan dalam bentuk zip file (Jangan diekstrak)
3. Jalankan Arduino
4. Pilih Skecth -> Include Library-> Add.ZIP Library spt gambar di bawah ini

5. Add Library openGLCD :

6. Edit software PinConfig_ks0108_Uno disesuaikan dengan pin revisi


/*
* define name for pin configuration
*/
#define glcd_PinConfigName "ks0108-Uno"

/*********************************************************/
/* Configuration for assigning LCD bits to Arduino Pins */
/*********************************************************/

/*
* Pins can be assigned using Arduino pin numbers 0-n
* Pins can also be assigned using AVRPIN_Pb
* where P is port A-L and b is bit 0-7
* Example: port D bit 3 is AVRPIN_D3
*
* Pins can also be assigned using 0xPb for ports A to F
* Example: port D bit 3 is 0xD3
*/

/* Data pin definitions


*/
#define glcdPinData0 2 //8
#define glcdPinData1 3 //9
#define glcdPinData2 4 //10
#define glcdPinData3 5 //11
#define glcdPinData4 6 //4
#define glcdPinData5 7 //5
#define glcdPinData6 8 //6
#define glcdPinData7 9 //7

/* Arduino pins used for Control


* default assignment uses the first five analog pins
*/

#define glcdPinCSEL1 12 //A0


#define glcdPinCSEL2 11 //A1

#define glcdPinRW A1 //A2


#define glcdPinDI A0 //A3
#define glcdPinEN A2

#endif //GLCD_PIN_CONFIG_H

SOFTWARE :

7. Ketik Program berikut dan upload ke ARDUINO Uno

#include <openGLCD.h>
#include "Wire.h"

#define DS3231_I2C_ADDRESS 0x68


#define DELAY 3000 // ms delay between examples
gText textAreaFull; // Creates an area for the full
display, but no font yet
gText textAreaBot(textAreaBOTTOM, System5x7); // bottom half of
display
gText textAreaNums(GLCD.Left, GLCD.Top, 7, 1, fixednums7x15); // 7 columns, 1
line in upper left corner
gText textAreaUpRt(GLCD.CenterX, 0, GLCD.Right, GLCD.CenterY); // upper right
quadrant, no font yet
uint8_t dat,i,jam,men,det,sat,pul;

void setup()
{
GLCD.Init();
Wire.begin();
GLCD.SelectFont(System5x7); // use SystemFont in "default" text area
textAreaFull.SelectFont(font8x8);
textAreaUpRt.SelectFont(Arial14);
// DS3231 seconds, minutes, hours, day, date, month, year
//setDS3231time(0,35,21,7,17,12,16);
}

void loop()
{
GLCD.ClearScreen();
//GLCD.DrawString(F("Tugas Mikro"), gTextfmt_center, 0);
GLCD.CursorTo(0,0);GLCD.print("Tugas Mikrokontroler");

byte second, minute, hour, dayOfWeek, dayOfMonth, month, year;


// retrieve data from DS3231
GLCD.SelectFont(Arial14);
while(1)
{

readDS3231time(&second, &minute, &hour, &dayOfWeek, &dayOfMonth,


&month, &year);
sat = hour % 10;
pul = hour / 10;
GLCD.CursorTo(1,1);GLCD.PutChar(pul+0x30);
GLCD.CursorTo(2,1);GLCD.PutChar(sat+0x30);
GLCD.CursorTo(3,1);GLCD.print(":");
sat = minute % 10;
pul = minute / 10;
GLCD.CursorTo(4,1);GLCD.PutChar(pul+0x30);
GLCD.CursorTo(5,1);GLCD.PutChar(sat+0x30);
GLCD.CursorTo(6,1);GLCD.print(":");
sat = second % 10;
pul = second / 10;
GLCD.CursorTo(7,1);GLCD.PutChar(pul+0x30);
GLCD.CursorTo(8,1);GLCD.PutChar(sat+0x30);
switch(dayOfWeek)
{
case 1:
GLCD.CursorTo(3,2);GLCD.print("Sunday");
break;
case 2:
GLCD.CursorTo(3,2);GLCD.print("Monday");
break;
case 3:
GLCD.CursorTo(3,2);GLCD.print("Tuesday");
break;
case 4:
GLCD.CursorTo(3,2);GLCD.print("Wednesday");
break;
case 5:
GLCD.CursorTo(3,2);GLCD.print("Thursday");
break;
case 6:
GLCD.CursorTo(3,2);GLCD.print("Friday");
break;
case 7:
GLCD.CursorTo(3,2);GLCD.print("Saturday");
break;
}
sat = dayOfMonth % 10;
pul = dayOfMonth / 10;
GLCD.CursorTo(1,3);GLCD.PutChar(pul+0x30);
GLCD.CursorTo(2,3);GLCD.PutChar(sat+0x30);
GLCD.CursorTo(3,3);GLCD.print("-");
sat = month % 10;
pul = month / 10;
GLCD.CursorTo(4,3);GLCD.PutChar(pul+0x30);
GLCD.CursorTo(5,3);GLCD.PutChar(sat+0x30);
GLCD.CursorTo(6,3);GLCD.print("-");
sat = year % 10;
pul = year / 10;
GLCD.CursorTo(7,3);GLCD.PutChar(pul+0x30);
GLCD.CursorTo(8,3);GLCD.PutChar(sat+0x30);

delay(500);
}
}

// Convert normal decimal numbers to binary coded decimal


byte decToBcd(byte val)
{
return((val/10*16) + (val%10));
}

// Convert binary coded decimal to normal decimal numbers


byte bcdToDec(byte val)
{
return( (val/16*10) + (val%16) );
}

void setDS3231time(byte second, byte minute, byte hour, byte dayOfWeek, byte
dayOfMonth, byte month, byte year)
{
// sets time and date data to DS3231
Wire.beginTransmission(DS3231_I2C_ADDRESS);
Wire.write(0); // set next input to start at the seconds register
Wire.write(decToBcd(second)); // set seconds
Wire.write(decToBcd(minute)); // set minutes
Wire.write(decToBcd(hour)); // set hours
Wire.write(decToBcd(dayOfWeek)); // set day of week (1=Sunday, 7=Saturday)
Wire.write(decToBcd(dayOfMonth)); // set date (1 to 31)
Wire.write(decToBcd(month)); // set month
Wire.write(decToBcd(year)); // set year (0 to 99)
Wire.endTransmission();
9
void readDS3231time(byte *second, byte *minute, byte *hour, byte *dayOfWeek,
byte *dayOfMonth, byte *month, byte *year)
{
Wire.beginTransmission(DS3231_I2C_ADDRESS);
Wire.write(0); // set DS3231 register pointer to 00h
Wire.endTransmission();
Wire.requestFrom(DS3231_I2C_ADDRESS, 7);
// request seven bytes of data from DS3231 starting from
register 00h
*second = bcdToDec(Wire.read() & 0x7f);
*minute = bcdToDec(Wire.read());
*hour = bcdToDec(Wire.read() & 0x3f);
*dayOfWeek = bcdToDec(Wire.read());
*dayOfMonth = bcdToDec(Wire.read());
*month = bcdToDec(Wire.read());
*year = bcdToDec(Wire.read());
}