0% found this document useful (0 votes)
46 views21 pages

Praktek 5 LCD Character: Tujuan

The document describes experiments with displaying characters and strings on a 20x2 LCD module connected to an AVR microcontroller. It includes initializing the LCD in 4-bit mode, writing characters to specific positions, clearing the display, and animating a rotating line. Library functions for initializing, writing to, and clearing the LCD are introduced. Four experiments are described: 1) Displaying single characters, 2) Displaying strings and clearing, 3) Displaying strings character-by-character, 4) Animating a rotating line.

Uploaded by

Liak
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
46 views21 pages

Praktek 5 LCD Character: Tujuan

The document describes experiments with displaying characters and strings on a 20x2 LCD module connected to an AVR microcontroller. It includes initializing the LCD in 4-bit mode, writing characters to specific positions, clearing the display, and animating a rotating line. Library functions for initializing, writing to, and clearing the LCD are introduced. Four experiments are described: 1) Displaying single characters, 2) Displaying strings and clearing, 3) Displaying strings character-by-character, 4) Animating a rotating line.

Uploaded by

Liak
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 21

Praktek 5

LCD character
Tujuan:
• Mahasiswa mengerti cara melakukan pemrograman LCD character 20x2 dengan
mikrokontroller AVR
• Mahasiswa mengerti cara membuat program C pada mikrokontroller AVR untuk
menampilkan data di LCD dan membaca data dari LCD

Peralatan yang digunakan:


• modul AVR
• Modul LED dan switch
• Kabel serial RS232 (cross)
• Modul LCD character 20x2

Deskripsi/ Dasar Teori:

Gambar5.1. LCD character (tampak visual)

Tabel.1. Pinout LCD character

Pins Description
1 Ground
2 Vcc
3 Contrast Voltage
4 "R/S" _Instruction/Register Select
"R/W" _Read/Write LCD
5
Registers
6 "E" Clock
7 - 14 Data I/O Pins (D0..D7)
15 Anoda (+) backlight
16 Katoda (-) backlight

1
Gambar5.2. Rangkaian pengatur kontras tampilan LCD

2
Gambar5.3. Setting LCD di Code Vision

Tabel.2. Daftar Instruksi LCD Character

R/S R/W D7 D6 D5 D4 D3 D2 D1 D0 Instruction/Description


4 5 14 13 12 11 10 9 8 7 Pins
0 0 0 0 0 0 0 0 0 1 Clear Display
0 0 0 0 0 0 0 0 1 * Return Cursor and LCD to Home Position
0 0 0 0 0 0 0 1 ID S Set Cursor Move Direction
0 0 0 0 0 0 1 D C B Enable Display/Cursor
0 0 0 0 0 1 SC RL * * Move Cursor/Shift Display
0 0 0 0 1 DL N F * * Set Interface Length
0 0 0 1 A A A A A A Move Cursor into CGRAM
0 0 1 A A A A A A A Move Cursor to Display
0 1 BF * * * * * * * Poll the "Busy Flag"
Write a Character to the Display at the Current
1 0 D D D D D D D D
Cursor Position
Read the Character on the Display at the
1 1 D D D D D D D D
Current Cursor Position

The bit descriptions for the different commands are:

"*" - Not Used/Ignored. This bit can be either "1" or "0"

3
Set Cursor Move Direction:
ID - Increment the Cursor After Each Byte Written to Display if Set
S - Shift Display when Byte Written to Display

Enable Display/Cursor
D - Turn Display On(1)/Off(0)
C - Turn Cursor On(1)/Off(0)
B - Cursor Blink On(1)/Off(0)

Move Cursor/Shift Display


SC - Display Shift On(1)/Off(0)
RL - Direction of Shift Right(1)/Left(0)

Set Interface Length


DL - Set Data Interface Length 8(1)/4(0)
N - Number of Display Lines 1(0)/2(1)
F - Character Font 5x10(1)/5x7(0)

Poll the "Busy Flag"


BF - This bit is set while the LCD is processing

Move Cursor to CGRAM/Display


A - Address

Read/Write ASCII to the Display


D - Data

Proses inisialisasi pemrograman LCD dalam mode 4 four bit:

1. Wait more than 15 msecs after power is applied.


2. Write 0x03 to LCD and wait 5 msecs for the instruction to complete
3. Write 0x03 to LCD and wait 160 usecs for instruction to complete
4. Write 0x03 AGAIN to LCD and wait 160 usecs (or poll the Busy Flag)
5. Set the Operating Characteristics of the LCD
o Write 0x02 to the LCD to Enable Four Bit Mode

All following instruction/Data Writes require two nibble writes.

o Write "Set Interface Length"


o Write 0x01/0x00 to turn off the Display
o Write 0x00/0x01 to Clear the Display
o Write "Set Cursor Move Direction" Setting Cursor Behaviour Bits
o Write "Enable Display/Cursor" & enable Display and Optional Cursor

4
Gambar5.4. Daftar Kode Karakter yang bisa ditampilkan di LCD karakter

Fungsi-fungsi yang sudah disediakan dalam pustaka (library) file LCD.H:

• _lcd_ready() Î memeriksa kesiapan LCD untuk melakukan perintah


selanjutnya (memeriksa status busy flag)
• _lcd_write_data(unsigned char data) Î beri perintah ke LCD
• lcd_write_byte(unsigned char addr, unsigned char data) Î write a byte to the
LCD character generator or display RAM
• unsigned char lcd_read_byte(unsigned char addr) Î read a byte from the
LCD character generator or display RAM
• lcd_gotoxy(unsigned char x, unsigned char y) Î set the LCD display position
x=0..39 y=0..3
• lcd_clear() Î clear the LCD
• lcd_putchar(char c) Î write the string str located in SRAM to the LCD
• lcd_puts(char *str) Î write the string str located in SRAM to the LCD
• lcd_putsf(char flash *str) Î write the string str located in FLASH to the LCD
• unsigned char lcd_init(unsigned char lcd_columns) Î initialize the LCD
controller

5
PERCOBAAN 1
Menampilkan 1 karakter di LCD (dengan library lcd.h). LCD dipasang di PORT A.

#include <mega16.h>

// Alphanumeric LCD Module functions


#asm
.equ __lcd_port=0x1B ;PORTA
#endasm
#include <lcd.h>

// **** main program ****

void main(void)
{

// LCD module initialization


lcd_init(20);

while (1)
{
// Place your code here
lcd_gotoxy(0,0); // baris 1 kolom 1
lcd_putchar('a');
lcd_putchar('x'); //kursor otomatis ke kanan/ kolom berikutnya

lcd_gotoxy(7,0); // baris 1 kolom 8


lcd_putchar(0x30);

lcd_gotoxy(0,1); // baris 2 kolom 1


lcd_putchar('b');
}
}

Jika dibuat dengan menggunakan fungsi kita sendiri, programnya seperti di bawah ini.
Coba dan bandingkan (terutama ukuran program hexa yang dihasilkan):

/*****************************************************/
#include <mega16.h>

char init[7] = {0x33,0x32,0x28,0x0e,0x02,0x01,0xff};

void tunda_ms()
{
int i,j;
for(j=0;j<100;j++);
for(i=0;i<5000;i++);
}

void send_char(char datcom,char huruf)


{
PORTA.1=0; //wr pin
PORTA.0= datcom; // rs pin
PORTA.2=0; //enable pin
PORTA.4 = (huruf & 0x10) ? 1:0;
PORTA.5 = (huruf & 0x20) ? 1:0;
PORTA.6 = (huruf & 0x40) ? 1:0;

6
PORTA.7 = (huruf & 0x80) ? 1:0;
PORTA.2=1;
PORTA.2=0;

tunda_ms();

PORTA.4 = (huruf & 0x01) ? 1:0;


PORTA.5 = (huruf & 0x02) ? 1:0;
PORTA.6 = (huruf & 0x04) ? 1:0;
PORTA.7 = (huruf & 0x08) ? 1:0;
PORTA.2=1;
PORTA.2=0;

tunda_ms();

void init_lcd()
{
char n;
for (n=0;n<7;n++)
{ send_char(0,init[n]); }
}

//************** program utama ***********


void main()
{ PORTA=0xff;
DDRA=0xff;

init_lcd();
send_char(0,0x80);
send_char(1,'x');
send_char(0,0xc0);
send_char(1,'y');

while(1)
{}

PERCOBAAN 2
Menampilkan 1 string di LCD dan proses ganti tampilan (dengan rutin clear). LCD
dipasang di PORT A.

#include <mega16.h>
#include <delay.h>

// Alphanumeric LCD Module functions


#asm
.equ __lcd_port=0x1B ;PORTA
#endasm
#include <lcd.h>

// **** main program ****

void main(void)
{

7
// LCD module initialization
lcd_init(20);

while (1)
{
lcd_gotoxy(0,0); // baris 1 kolom 1
lcd_putsf("hallo, baris 1");
lcd_gotoxy(0,1); // baris 2 kolom 1
lcd_putsf("ini baris 2");

delay_ms(2000);
lcd_clear();
delay_ms(1000);

lcd_gotoxy(0,0); // baris 1 kolom 1


lcd_putsf("baris 1 - yang baru");
lcd_gotoxy(0,1); // baris 2 kolom 1
lcd_putsf("ini baris 2 :P …");

delay_ms(2000);
lcd_clear();
delay_ms(1000);
}
}

PERCOBAAN 3
Sama dengan percobaan 4 tapi karakter ditampilkan satu persatu. LCD dipasang di PORT
A.

#include <mega16.h>
#include <delay.h>

// Alphanumeric LCD Module functions


#asm
.equ __lcd_port=0x1B ;PORTA
#endasm
#include <lcd.h>

// **** main program ****

void tampil(flash unsigned char *pesan)


{ int i;

i=0;
while(pesan[i]!=0)
{ lcd_putchar(pesan[i]);
delay_ms(100);
i++;
}
}

void main(void)
{

// LCD module initialization


lcd_init(20);

while (1)

8
{
lcd_gotoxy(0,0); // baris 1 kolom 1
tampil("hallo, baris 1");
lcd_gotoxy(0,1); // baris 2 kolom 1
tampil("ini baris 2");

delay_ms(2000);
lcd_clear();
delay_ms(1000);

lcd_gotoxy(0,0); // baris 1 kolom 1


tampil("baris 1 - yang baru");
lcd_gotoxy(0,1); // baris 2 kolom 1
tampil("ini baris 2 :P …");

delay_ms(2000);
lcd_clear();
delay_ms(1000);
}
}

PERCOBAAN 4
Animasi garis yang berputar. LCD dipasang di PORT A.

#include <mega16.h>

// Alphanumeric LCD Module functions


#asm
.equ __lcd_port=0x1B ;PORTA
#endasm
#include <lcd.h>

// Standard Input/Output functions


#include <delay.h>

// Declare your global variables here

void main(void)
{
lcd_init(20);
//012345678
lcd_putsf ("Loading.. ");
while (1)
{
lcd_gotoxy(10,0);
lcd_putchar('-');
delay_ms(100);

lcd_gotoxy(10,0);
lcd_putchar('|');
delay_ms(100);

lcd_gotoxy(10,0);
lcd_putchar('/');
delay_ms(100);
};
}

9
PERCOBAAN 5
Animasi Loading data. LCD dipasang di PORT A.

#include <mega16.h>

// Alphanumeric LCD Module functions


#asm
.equ __lcd_port=0x1B ;PORTA
#endasm
#include <lcd.h>

// Standard Input/Output functions


#include <delay.h>

// Declare your global variables here

void main(void)
{
int a;
lcd_init(20);
//012345678

while (1)
{
lcd_putsf ("Loading.. ");
lcd_gotoxy(0,1);
for (a=1;a<=20;a++)
{
lcd_putchar(0xff);
delay_ms(300);
}

lcd_gotoxy(0,0);
lcd_putsf ("Process Complete. ");
delay_ms(2000);
lcd_clear();
};
}

PERCOBAAN 6
Menampilkan kode heksadesimal dari switch ke LCD. LCD dipasang di PORT A. Switch
di PORT C.

#include <mega16.h>

// Alphanumeric LCD Module functions


#asm
.equ __lcd_port=0x1B ;PORTA
#endasm
#include <lcd.h>

///////////////////////////////
void H2BCD(int bilangan)
{

10
int ratusan,puluhan,satuan;

ratusan= bilangan/100; // misal bilangan=231


// 231/100= 2
puluhan = (bilangan - (ratusan*100))/10; // (231-(2*100))/10
// (231-200)/10 = 31/10 = 3
satuan = bilangan - (puluhan*10) - (ratusan*100);

lcd_putchar(ratusan+0x30);
lcd_putchar(puluhan+0x30);
lcd_putchar(satuan+0x30);
}

////////////////////////////
int ubahASCII(int bilangan)
{
if (bilangan<10)
bilangan= bilangan+0x30; // 0 = 0x30
else
bilangan=bilangan+0x37; // A = 0x41 berarti
// 0x41 - 10 = 0x41 - 0x0a
// 0x37
return(bilangan);
}

/////////////////////////////////////////
void H2ASC(int bilangan)
{
int high,low;

high= bilangan/16;
low = bilangan - (high*16);

high = ubahASCII(high);
low = ubahASCII(low);

lcd_putchar(high);
lcd_putchar(low);

/////////////// program utama //////////////


void main(void)
{
int a;

PORTA=0x00;
DDRA=0xFF;

PORTC=0x00;
DDRC=0x00;

// LCD module initialization


lcd_init(20);

#asm("nop")

while (1)
{
lcd_gotoxy(0,0);
a=PINC;
lcd_putchar(a);
lcd_putchar(' ');

11
H2ASC(a);
lcd_putchar(' ');
H2BCD(a);
}

PERCOBAAN 7
Menampilkan status nilai ADC dalam bentuk heksadesimal, BCD dan karakter ASCII
nya di LCD. LCD dipasang di PORT C. Potensio di PORTA bit 0.

#include <mega16.h>

// Alphanumeric LCD Module functions


#asm
.equ __lcd_port=0x15 ;PORTC
#endasm
#include <lcd.h>
#include <delay.h>

#define ADC_VREF_TYPE 0x20

// Read the 8 most significant bits


// of the AD conversion result
unsigned char read_adc(unsigned char adc_input)
{
ADMUX=adc_input | (ADC_VREF_TYPE & 0xff);
// Start the AD conversion
ADCSRA|=0x40;
// Wait for the AD conversion to complete
while ((ADCSRA & 0x10)==0);
ADCSRA|=0x10;
return ADCH;
}

// Declare your global variables here

///////////////////////////////
void H2BCD(int bilangan)
{
int ratusan,puluhan,satuan;

ratusan= bilangan/100; // misal bilangan=231


// 231/100= 2
puluhan = (bilangan - (ratusan*100))/10; // (231-(2*100))/10
// (231-200)/10 = 31/10 = 3
satuan = bilangan - (puluhan*10) - (ratusan*100);

lcd_putchar(ratusan+0x30);
lcd_putchar(puluhan+0x30);
lcd_putchar(satuan+0x30);
}

////////////////////////////
int ubahASCII(int bilangan)
{
if (bilangan<10)
bilangan= bilangan+0x30; // 0 = 0x30
else

12
bilangan=bilangan+0x37; // A = 0x41 berarti
// 0x41 - 10 = 0x41 - 0x0a
// 0x37
return(bilangan);
}

/////////////////////////////////////////
void H2ASC(int bilangan)
{
int high,low;

high= bilangan/16;
low = bilangan - (high*16);

high = ubahASCII(high);
low = ubahASCII(low);

lcd_putchar(high);
lcd_putchar(low);

/////////////////////////////
void main(void)
{
int a;

PORTA=0x00;
DDRA=0x00;

// ADC initialization
// ADC Clock frequency: 691.200 kHz
// ADC Voltage Reference: AREF pin
// ADC Auto Trigger Source: Free Running
// Only the 8 most significant bits of
// the AD conversion result are used
ADMUX=ADC_VREF_TYPE & 0xff;
ADCSRA=0xA4;
SFIOR&=0x1F;

// LCD module initialization


lcd_init(20);

while (1)
{
lcd_gotoxy(0,0);
a= read_adc(0);
lcd_putchar(a);
lcd_putchar(' ');
H2BCD(a); //ubah ke BCD ASCII
lcd_putchar(' ');
H2ASC(a); //ubah ke hexadecimal ASCII
}
}

13
PERCOBAAN 8
Menampilkan status nilai ADC dalam bentuk bar chart di LCD (seperti tampilan
dashboard digital di mobil atau motor). LCD dipasang di PORT C. Potensio di PORTA
bit 0.

#include <mega16.h>

// Alphanumeric LCD Module functions


#asm
.equ __lcd_port=0x15 ;PORTC
#endasm
#include <lcd.h>
#include <delay.h>

#define ADC_VREF_TYPE 0x20

// Read the 8 most significant bits


// of the AD conversion result
unsigned char read_adc(unsigned char adc_input)
{
ADMUX=adc_input | (ADC_VREF_TYPE & 0xff);
// Start the AD conversion
ADCSRA|=0x40;
// Wait for the AD conversion to complete
while ((ADCSRA & 0x10)==0);
ADCSRA|=0x10;
return ADCH;
}

// Declare your global variables here

///////////////////////////////
void H2BCD(int bilangan)
{
int ratusan,puluhan,satuan;

ratusan= bilangan/100; // misal bilangan=231


// 231/100= 2
puluhan = (bilangan - (ratusan*100))/10; // (231-(2*100))/10
// (231-200)/10 = 31/10 = 3
satuan = bilangan - (puluhan*10) - (ratusan*100);

lcd_putchar(ratusan+0x30);
lcd_putchar(puluhan+0x30);
lcd_putchar(satuan+0x30);
}

/////////////////////////////
void main(void)
{
int ratio, a, b, nilaiADC;

PORTA=0x00;
DDRA=0x00;

// ADC initialization
// ADC Clock frequency: 691.200 kHz
// ADC Voltage Reference: AREF pin

14
// ADC Auto Trigger Source: Free Running
// Only the 8 most significant bits of
// the AD conversion result are used
ADMUX=ADC_VREF_TYPE & 0xff;
ADCSRA=0xA4;
SFIOR&=0x1F;

// LCD module initialization


lcd_init(20);

ratio= 255/18;

while (1)
{
lcd_gotoxy (0,0);
//01234567890123456789
lcd_putsf ("Status Bensin:");
lcd_gotoxy (0,1);
lcd_putchar('E');
lcd_gotoxy (19,1);
lcd_putchar('F');

lcd_gotoxy(17,0);
b=read_adc(0);
H2BCD(b);

lcd_gotoxy(1,1); //baris2

nilaiADC= b/ratio;
//if (b>0x02)
//{
for(a=0;a<nilaiADC;a++)
{
lcd_putchar(0xff);
}
//}

delay_ms(300);
lcd_clear();

}
}

PERCOBAAN 9
Menampilkan karakter yang diterima dari port serial ke LCD. LCD dipasang di PORT A.
TUGAS: Kemudian buatlah program Interfacenya dengan menggunakan Visual Basic.

#include <mega16.h>

// Alphanumeric LCD Module functions


#asm
.equ __lcd_port=0x1B ;PORTA
#endasm
#include <lcd.h>

// Standard Input/Output functions


#include <stdio.h>

15
// Declare your global variables here

void main(void)
{
int a;

// USART initialization
// Communication Parameters: 8 Data, 1 Stop, No Parity
// USART Receiver: On
// USART Transmitter: On
// USART Mode: Asynchronous
// USART Baud rate: 9600
UCSRA=0x00;
UCSRB=0x18;
UCSRC=0x86;
UBRRH=0x00;
UBRRL=0x47;

// LCD module initialization


lcd_init(20);

while (1)
{
a=getchar();
lcd_putchar(a);
}
}

PERCOBAAN 10
Menampilkan angka atau kode yang diterima dari keypad ke LCD. LCD dipasang di
PORT A.

#include <mega16.h>

// Alphanumeric LCD Module functions


#asm
.equ __lcd_port=0x1B ;PORTA
#endasm
#include <lcd.h>
#include <delay.h>
// Declare your global variables here

int baca_keypad()
{
int a,tombol;
PORTC= 0xff;

tombol=' '-0x30; // jika tdk ada tombol ditekan

PORTC.1=0; // baris 1
#asm("nop")
a = PINC;
if (a==0xf9) {tombol=1; goto selesai;}
if (a==0xfc) {tombol=2; goto selesai;}
if (a==0xed) {tombol=3; goto selesai;}

PORTC.6=0; PORTC.1=1; // baris 2


#asm("nop")
a = PINC;

16
if (a==0xbb) {tombol=4; goto selesai;}
if (a==0xbe) {tombol=5; goto selesai;}
if (a==0xaf) {tombol=6; goto selesai;}

PORTC.5=0; PORTC.6=1; // baris 3


#asm("nop")
a = PINC;
if (a==0xdb) {tombol=7; goto selesai;}
if (a==0xde) {tombol=8; goto selesai;}
if (a==0xcf) {tombol=9; goto selesai;}

PORTC.3=0; PORTC.5=1; // baris 4


#asm("nop")
a = PINC;
if (a==0xf3) {tombol='*'-0x30; goto selesai;}
if (a==0xf6) {tombol=0; goto selesai;}
if (a==0xe7) tombol='#'-0x30;

selesai:
return(tombol);
}

/////////////////// program utama //////////


void main(void)
{
// Declare your global variables here
int nilai;

// Port D initialization
// d7=In d6=Out d5=Out d4=In d3=Out d2=In d1=Out d0=In
PORTC=0x00;
DDRC=0x6A;

// LCD module initialization


lcd_init(20);

// 01234567890123456789
lcd_putsf("Exp. LCD dgn keypad");

while (1)
{
nilai= baca_keypad();
lcd_gotoxy(0,1);
lcd_putchar(nilai+0x30);
delay_ms(100);
}
}

PERCOBAAN 11
Menampilkan angka atau kode yang diterima dari keypad ke LCD dengan kursor kotak.
LCD dipasang di PORT A. Cobalah pengkodean diubah agar kursornya berubah menjadi
garis bawah.

#include <mega16.h>

17
// Alphanumeric LCD Module functions
#asm
.equ __lcd_port=0x1B ;PORTA
#endasm
#include <lcd.h>
#include <delay.h>
// Declare your global variables here

int baca_keypad()
{
int a,tombol;
PORTC= 0xff;

tombol=' '-0x30; // jika tdk ada tombol ditekan

PORTC.1=0; // baris 1
#asm("nop")
a = PINC;
if (a==0xf9) {tombol=1; goto selesai;}
if (a==0xfc) {tombol=2; goto selesai;}
if (a==0xed) {tombol=3; goto selesai;}

PORTC.6=0; PORTC.1=1; // baris 2


#asm("nop")
a = PINC;
if (a==0xbb) {tombol=4; goto selesai;}
if (a==0xbe) {tombol=5; goto selesai;}
if (a==0xaf) {tombol=6; goto selesai;}

PORTC.5=0; PORTC.6=1; // baris 3


#asm("nop")
a = PINC;
if (a==0xdb) {tombol=7; goto selesai;}
if (a==0xde) {tombol=8; goto selesai;}
if (a==0xcf) {tombol=9; goto selesai;}

PORTC.3=0; PORTC.5=1; // baris 4


#asm("nop")
a = PINC;
if (a==0xf3) {tombol='*'-0x30; goto selesai;}
if (a==0xf6) {tombol=0; goto selesai;}
if (a==0xe7) tombol='#'-0x30;

selesai:
return(tombol);
}

/////////////////// program utama //////////


void main(void)
{
// Declare your global variables here
int nilai;

// Port D initialization
// d7=In d6=Out d5=Out d4=In d3=Out d2=In d1=Out d0=In
PORTC=0x00;
DDRC=0x6A;

// LCD module initialization


lcd_init(20);

18
//**** tampilkan kursor (diambil dari lcd.inc)***
//0x0c => tanpa kursor
//0x0d => kursor kotak hitam
//0x0e => kursor garis bawah

_lcd_ready();
_lcd_write_data(0xd); // cursor on
//***********************************************

// 01234567890123456789
lcd_putsf("Exp. LCD dgn keypad");

while (1)
{
lcd_gotoxy(0,1);
ulang:
nilai= baca_keypad();
if (nilai==' '-0x30)
{goto ulang;}
else
{lcd_putchar(nilai+0x30);
delay_ms(100); }
}
}

PERCOBAAN 12
Menampilkan angka atau kode yang diterima dari keypad ke LCD kemudian ditulis lagi
(dengan rutin membaca data lcd). Ini sangat diperlukan untuk aplikasi password atau
setting peralatan.

#include <mega16.h>

// Alphanumeric LCD Module functions


#asm
.equ __lcd_port=0x1B ;PORTA
#endasm
#include <lcd.h>
#include <delay.h>
// Declare your global variables here

int baca_keypad()
{
int a,tombol;
PORTC= 0xff;

tombol=' '-0x30; // jika tdk ada tombol ditekan

PORTC.1=0; // baris 1
#asm("nop")
a = PINC;
if (a==0xf9) {tombol=1; goto selesai;}
if (a==0xfc) {tombol=2; goto selesai;}
if (a==0xed) {tombol=3; goto selesai;}

PORTC.6=0; PORTC.1=1; // baris 2


#asm("nop")
a = PINC;
if (a==0xbb) {tombol=4; goto selesai;}
if (a==0xbe) {tombol=5; goto selesai;}

19
if (a==0xaf) {tombol=6; goto selesai;}

PORTC.5=0; PORTC.6=1; // baris 3


#asm("nop")
a = PINC;
if (a==0xdb) {tombol=7; goto selesai;}
if (a==0xde) {tombol=8; goto selesai;}
if (a==0xcf) {tombol=9; goto selesai;}

PORTC.3=0; PORTC.5=1; // baris 4


#asm("nop")
a = PINC;
if (a==0xf3) {tombol='*'-0x30; goto selesai;}
if (a==0xf6) {tombol=0; goto selesai;}
if (a==0xe7) tombol='#'-0x30;

selesai:
return(tombol);
}

/////////////////// program utama //////////


void main(void)
{
// Declare your global variables here
int a,b,nilai;

// Port D initialization
// d7=In d6=Out d5=Out d4=In d3=Out d2=In d1=Out d0=In
PORTC=0x00;
DDRC=0x6A;

// LCD module initialization


lcd_init(20);

//**** tampilkan kursor (diambil dari lcd.inc)***


//0x0c => tanpa kursor
//0x0d => kursor kotak hitam
//0x0e => kursor garis bawah

_lcd_ready();
_lcd_write_data(0xe); // cursor on
//***********************************************
lcd_putsf(">");

for(a=1;a<=19;a++)
{
ulang:
nilai= baca_keypad();
if (nilai!=' '-0x30)
{lcd_putchar(nilai+0x30);
delay_ms(600); }
else
{goto ulang;}

// mulai menyalin
for(a=1;a<=19;a++)
{
b= lcd_read_byte(0x80+a);
lcd_gotoxy(a-1,1);
lcd_putchar(b);

20
}

while(1);
}

by:Ary Sulistyo U, 2008


[email protected]
Staf Teknis Politeknik Cilacap.
.

21

You might also like