Laboratorium Dasar Teknik Elektro - Sekolah Teknik Elektro dan Informatika ITB
Abstrak
Beberapa
interface
yang
umum
digunakan sebagai masukan maupun
keluaran
dalam
penggunaan
mikrokontroller
ATMega8535
adalah
seven segment, keypad, dan LCD. Dalam
percobaan di modul 4 ini akan dipelajari
bagaimana menggunakan ketiganya.
Kata kunci: seven segment, keypad, LCD,
scanning.
1. PENDAHULUAN
Dalam menggunakan mikrokontroller ATMega
8535, seringkali diperlukan suatu devais
untuk
menampilkan
keluaran
maupun
memberikan suatu masukan. Untuk itu dapat
digunakan devais tambahan seperti seven
segment,
keypad,
dan
LCD.
Dalam
penggunaannya, seven segment dan keypad
memerlukan
proses
scanning
untuk
menampilkan keluaran maupun membaca
masukan. Sementara untuk menggunakan
LCD, telah terdapat library yang berisi fungsifungsi untuk menampilkan dalam LCD.
2. STUDI PUSTAKA
2.1
2.2
SCANNING KEYPAD
2.3
LCD
3.2
3. LANGKAH PERCOBAAN
Untuk melakukan percobaan-percobaan pada
modul
ini
digunakan
Sismin
dengan
mikrokontroller ATMega 8535. Untuk interface
digunakan Trainer Board yang sudah memiliki
keypad, seven segment, dan LCD. Sebagai
sumber daya digunakan power supply 9 V.
Untuk melakukan pemrograman digunakan
usbasp.
Sebagai persiapan, hal berikut dilakukan:
Buka Programmer Notepad, lalu buat New
Project. Kemudian masukkan script program.
Lalu simpan dan add files tersebut pada
project.
Setelah itu, buka Mfile untuk membuat
Makefile guna melakukan compiling dari script
yang telah dibuat. Pada Mfile, diatur jenis
Mikrokontroller
yang
digunakan
yaitu
ATMega8535, jenis programmer yaitu usbasp,
port programmer yang digunakan yaitu com1,
dan Clock Frequency dari osilator yang
digunakan yaitu 7,378 MHz.
Setelah script dan Mfile selesai dibuat,
kembali ke Programmer Notepad, lakukan
Make All untuk meng-compile program.
Apabila berhasil, lakukan download program
untuk
memasukkan
program
ke
mikrokontroller.
3.1
3.3
TUGAS IV.C.4
Modifikasi
file
main.c
sehingga
LCD
menampilkan keypad 3x3 yang ditekan. Amati
keluaran dari penekanan tombol pada LCD.
4.2
telah
SW1
akan
akan
SW4
4.3
LCDsendChar,
karakter
untuk
menampilkan
LCDsendCommand,
LCDsendChar
LCDclr,
LCD
LCDcursorOn,
mengaktifkan
kursor dengan underline
LCDcursorOFF,
cursor
untuk
sama
mengosongkan
mematikan
seperti
layar
posisi
posisi
TUGAS IV.C.4
Untuk
menggunakan
LCD,
telah
tersedia library yang dapat langsung
digunakan beserta dnegan prosedurprosedur di dalamnya.
5. KESIMPULAN
Dari
percobaan-percobaan
yang
telah
dilakukan
pada
modul
ini
diperoleh
kesimpulan bahwa
-
DAFTAR PUSTAKA
[1]
Datasheet ATMega8535
[2]
LAMPIRAN
1. Tugas A.1
#include <avr/io.h>
#define F_CPU 7372800L
#include <util/delay.h>
char angka;
char kodehex;
unsigned int SSegmen(char angka);
int main (void)
{
DDRA = 0xFF;
DDRD = 0xFF;
while (1)
{
PORTD =(0<<PD7)|(1<<PD6);
PORTA =SSegmen('7')|(1<<7);
_delay_ms(1);
PORTD =(1<<PD7)|(0<<PD6);
PORTA =SSegmen('2');
_delay_ms(1);
}
return 0;
}
unsigned int SSegmen(char angka)
{
switch (angka)
{
case
case
case
case
case
case
case
case
case
case
'0':
'1':
'2':
'3':
'4':
'5':
'6':
'7':
'8':
'9':
kodehex
kodehex
kodehex
kodehex
kodehex
kodehex
kodehex
kodehex
kodehex
kodehex
=
=
=
=
=
=
=
=
=
=
0x3f;
0x06;
0x5b;
0x4f;
0x66;
0x6d;
0x7d;
0x07;
0x7f;
0x6f;
break;
break;
break;
break;
break;
break;
break;
break;
break;
break;
}
return kodehex;
}
2. Tugas A.2
#include <avr/io.h>
#include <util/delay.h>
char angka;
char kodehex;
unsigned int SSegmen(char angka);
int main (void)
{
char i;
DDRA = 0xFF;
DDRD = 0xFF;
TIMSK |= (1<<TOIE1);
TCCR1A = 0;
TCCR1B = 0b00001101;
//penentuan nilai awal timer
TCNT1H = 0;
TCNT1L = 0;
//penentuan nilai compare untuk delay 1 detik
OCR1AH = 0x1C;
OCR1AL = 0x20;
while(1)
{
do{
TIFR|=(0<<OCF1A);
PORTD =(0<<PD7)|(1<<PD6);
PORTA =SSegmen('5');
_delay_ms(1);
PORTD =(1<<PD7)|(0<<PD6);
PORTA =SSegmen('0')|(1<<7);
_delay_ms(1);
}while(bit_is_clear(TIFR,OCF1A));
do{
TIFR|=(0<<OCF1A);
PORTD =(0<<PD7)|(1<<PD6);
PORTA =SSegmen('4');
_delay_ms(1);
PORTD =(1<<PD7)|(0<<PD6);
PORTA =SSegmen('0')|(1<<7);
_delay_ms(1);
}while(bit_is_clear(TIFR,OCF1A));
do{
TIFR|=(0<<OCF1A);
PORTD =(0<<PD7)|(1<<PD6);
PORTA =SSegmen('3');
_delay_ms(1);
PORTD =(1<<PD7)|(0<<PD6);
PORTA =SSegmen('0')|(1<<7);
_delay_ms(1);
}while(bit_is_clear(TIFR,OCF1A));
do{
TIFR|=(0<<OCF1A);
PORTD =(0<<PD7)|(1<<PD6);
PORTA =SSegmen('2');
_delay_ms(1);
PORTD =(1<<PD7)|(0<<PD6);
PORTA =SSegmen('0')|(1<<7);
_delay_ms(1);
}while(bit_is_clear(TIFR,OCF1A));
do{
TIFR|=(0<<OCF1A);
PORTD =(0<<PD7)|(1<<PD6);
PORTA =SSegmen('1');
_delay_ms(1);
PORTD =(1<<PD7)|(0<<PD6);
PORTA =SSegmen('0')|(1<<7);
_delay_ms(1);
}while(bit_is_clear(TIFR,OCF1A));
for(i=1;i<=3;i++){
//penentuan nilai awal timer
TCNT1H = 0;
TCNT1L = 0;
//penentuan nilai compare untuk delay 0.5 detik
OCR1AH = 0x0E;
OCR1AL = 0x10;
do{
TIFR|=(0<<OCF1A);
PORTD =(0<<PD7)|(1<<PD6);
PORTA =SSegmen('F');
_delay_ms(1);
PORTD =(1<<PD7)|(0<<PD6);
PORTA =SSegmen('F')|(1<<7);
_delay_ms(1);
}while(bit_is_clear(TIFR,OCF1A));
do{
TIFR|=(0<<OCF1A);
PORTD =(0<<PD7)|(1<<PD6);
PORTA = 0x00;
_delay_ms(1);
PORTD =(1<<PD7)|(0<<PD6);
PORTA = 0x00;
_delay_ms(1);
}while(bit_is_clear(TIFR,OCF1A));
}
}
return 0;
}
unsigned int SSegmen(char angka)
{
switch (angka)
{
case '0': {kodehex =
case '1': {kodehex =
case '2': {kodehex =
case '3': {kodehex =
case '4': {kodehex =
case '5': {kodehex =
case '6': {kodehex =
case '7': {kodehex =
case '8': {kodehex =
case '9': {kodehex =
0x3f;
0x06;
0x5b;
0x4f;
0x66;
0x6d;
0x7d;
0x07;
0x7f;
0x6f;
break;}
break;}
break;}
break;}
break;}
break;}
break;}
break;}
break;}
break;}
3. Tugas B.1
#include <avr/io.h>
#define F_CPU 7372800UL
#include <util/delay.h>
int main (void)
{
DDRA=0xFF;
PORTA=0x00;
DDRD=(1<<PD4)|(1<<PD5);
SFIOR=(0<<PUD);
while(1)
{
PORTD=(1<<PD4)|(0<<PD5);
if(bit_is_clear(PIND,0))
PORTA=0b00000001;
_delay_ms(50);
if(bit_is_clear(PIND,1))
PORTA=0b00001111;
_delay_ms(50);
PORTD=(0<<PD4)|(1<<PD5);
if(bit_is_clear(PIND,0))
PORTA=0b00000011;
_delay_ms(50);
if(bit_is_clear(PIND,1))
PORTA=0b00000111;
_delay_ms(50);
}
return 0;
}
4. Tugas B.2
#include <avr/io.h>
#include <util/delay.h>
char angka, kodehex;
unsigned int SSegmen(char angka);
int main (void)
{
char state = 0;
DDRA=0xFF;
PORTA=0x00;
DDRD=(1<<PD4)|(1<<PD5);
SFIOR=(0<<PUD);
while(1)
{
switch(state)
{
case 0 : {
PORTD =(0<<PD7)|(1<<PD6);
PORTA =SSegmen('0');
_delay_ms(1);
PORTD =(1<<PD7)|(0<<PD6);
PORTA =SSegmen('0');
_delay_ms(1);
break;
}
case 1 : {
PORTD =(0<<PD7)|(1<<PD6);
PORTA =SSegmen('1');
_delay_ms(1);
PORTD =(1<<PD7)|(0<<PD6);
PORTA =SSegmen('1');
_delay_ms(1);
break;
}
case 2 : {
PORTD =(0<<PD7)|(1<<PD6);
PORTA =SSegmen('2');
_delay_ms(1);
PORTD =(1<<PD7)|(0<<PD6);
PORTA =SSegmen('2');
_delay_ms(1);
break;
}
case 3 : {
PORTD =(0<<PD7)|(1<<PD6);
PORTA =SSegmen('3');
_delay_ms(1);
PORTD =(1<<PD7)|(0<<PD6);
PORTA =SSegmen('3');
_delay_ms(1);
break;
}
case 4 : {
PORTD =(0<<PD7)|(1<<PD6);
PORTA =SSegmen('4');
_delay_ms(1);
PORTD =(1<<PD7)|(0<<PD6);
PORTA =SSegmen('4');
_delay_ms(1);
break;
}
}
PORTD=(1<<PD4)|(0<<PD5);
if(bit_is_clear(PIND,0))
if(bit_is_clear(PIND,1))
PORTD=(0<<PD4)|(1<<PD5);
if(bit_is_clear(PIND,0))
if(bit_is_clear(PIND,1))
}
return 0;
state = 1;
state = 4;
state = 2;
state = 3;
0x3f;
0x06;
0x5b;
0x4f;
0x66;
0x6d;
0x7d;
0x07;
0x7f;
0x6f;
break;}
break;}
break;}
break;}
break;}
break;}
break;}
break;}
break;}
break;}
<avr/io.h>
<avr/pgmspace.h>
<util/delay.h>
"lcd_lib.h"
"lcd_lib.c"
CopyStringtoLCD(LCDprogress, 3, 0);
for(uint8_t i=0;i<255;i++)
{
_delay_ms(10);
LCDGotoXY(0, 1);
LCDprogressBar(i, 255, 16);
}
}
//demonstration of animation
void demoanimation(void)
{
LCDclr();
LCDdefinechar(backslash,0);
CopyStringtoLCD(LCDanimation, 0, 0);
for(uint8_t i=0;i<3;i++)
{
LCDGotoXY(8, 1);
LCDsendChar(0);
delay1s();
LCDGotoXY(8, 1);
LCDsendChar('-');
delay1s();
LCDGotoXY(8, 1);
LCDsendChar('/');
delay1s();
LCDGotoXY(8, 1);
LCDsendChar('|');
delay1s();
LCDGotoXY(8, 1);
LCDsendChar(8);//backslash
delay1s();
LCDGotoXY(8, 1);
LCDsendChar('-');
delay1s();
LCDGotoXY(8, 1);
LCDsendChar('/');
delay1s();
LCDGotoXY(8, 1);
LCDsendChar('|');
delay1s();
}
}
int main(void)
{
LCDinit();//init LCD bit, dual line, cursor right
LCDclr();//clears LCD
while(1)//loop demos
{
progress();
delay1s();
demoanimation();
}
return 0;
}
// Title
: 8 and 4 bit LCd interface
// Author
: Scienceprog.com - Copyright (C) 2007
// Created
: 2007-03-29
// Revised
: 2007-08-08
// Version
: 1.0
// Target MCU
: Atmel AVR series
//
// This code is distributed under the GNU Public License
//
which can be found at http://www.gnu.org/licenses/gpl.txt
//
//****************************************************************************
*
#include "lcd_lib.h"
#include <inttypes.h>
#include <avr/io.h>
#include <avr/pgmspace.h>
#include <util/delay.h>
const uint8_t LcdCustomChar[]
{
0x00, 0x1F, 0x00, 0x00,
block
0x00, 0x1F, 0x10, 0x10,
block
0x00, 0x1F, 0x18, 0x18,
block
0x00, 0x1F, 0x1C, 0x1C,
block
0x00, 0x1F, 0x1E, 0x1E,
block
0x00, 0x1F, 0x1F, 0x1F,
block
0x03, 0x07, 0x0F, 0x1F,
0x18, 0x1C, 0x1E, 0x1F,
};
#endif
}
void LCDsendCommand(uint8_t cmd)
//Sends Command to LCD
{
#ifdef LCD_4bit
//4 bit part
LDP=(cmd&0b11110000);
LCP|=1<<LCD_E;
_delay_ms(1);
LCP&=~(1<<LCD_E);
_delay_ms(1);
LDP=((cmd&0b00001111)<<4);
LCP|=1<<LCD_E;
_delay_ms(1);
LCP&=~(1<<LCD_E);
_delay_ms(1);
#else
//8 bit part
LDP=cmd;
LCP|=1<<LCD_E;
_delay_ms(1);
LCP&=~(1<<LCD_E);
_delay_ms(1);
#endif
}
void LCDinit(void)//Initializes LCD
{
#ifdef LCD_4bit
//4 bit part
_delay_ms(15);
LDP=0x00;
LCP=0x00;
LDDR|=1<<LCD_D7|1<<LCD_D6|1<<LCD_D5|1<<LCD_D4;
LCDR|=1<<LCD_E|1<<LCD_RW|1<<LCD_RS;
//---------one-----LDP=0<<LCD_D7|0<<LCD_D6|1<<LCD_D5|1<<LCD_D4; //4 bit mode
LCP|=1<<LCD_E|0<<LCD_RW|0<<LCD_RS;
_delay_ms(1);
LCP&=~(1<<LCD_E);
_delay_ms(1);
//-----------two----------LDP=0<<LCD_D7|0<<LCD_D6|1<<LCD_D5|1<<LCD_D4; //4 bit mode
LCP|=1<<LCD_E|0<<LCD_RW|0<<LCD_RS;
_delay_ms(1);
LCP&=~(1<<LCD_E);
_delay_ms(1);
//-------three------------LDP=0<<LCD_D7|0<<LCD_D6|1<<LCD_D5|0<<LCD_D4; //4 bit mode
LCP|=1<<LCD_E|0<<LCD_RW|0<<LCD_RS;
_delay_ms(1);
LCP&=~(1<<LCD_E);
_delay_ms(1);
//--------4 bit--dual line--------------LCDsendCommand(0b00101000);
//-----increment address, invisible cursor shift-----LCDsendCommand(0b00001100);
//init 8 custom chars
uint8_t ch=0, chn=0;
while(ch<64)
{
LCDdefinechar((LcdCustomChar+ch),chn++);
ch=ch+8;
}
#else
#endif
}
void LCDclr(void)
//Clears LCD
{
LCDsendCommand(1<<LCD_CLR);
}
void LCDhome(void)
//LCD cursor home
{
LCDsendCommand(1<<LCD_HOME);
}
void LCDstring(uint8_t* data, uint8_t nBytes)
//Outputs string to LCD
{
register uint8_t i;
}
else
{
#define LCD_RW
#define LCD_E
#define LCD_D0
#define LCD_D1
#define LCD_D2
#define LCD_D3
#define LCD_D4
#define LCD_D5
#define LCD_D6
#define LCD_D7
#define LDP PORTC
#define LCP PORTC
#define LDDR DDRC
data pins
#define LCDR DDRC
control pins
1
//define MCU pin connected to LCD R/W
2
//define MCU pin connected to LCD E
0
//define MCU pin connected to LCD D0
1
//define MCU pin connected to LCD D1
2
//define MCU pin connected to LCD D1
3
//define MCU pin connected to LCD D2
4
//define MCU pin connected to LCD D3
5
//define MCU pin connected to LCD D4
6
//define MCU pin connected to LCD D5
7
//define MCU pin connected to LCD D6
//define MCU port connected to LCD data pins
//define MCU port connected to LCD control pins
//define MCU direction register for port connected to LCD
//define MCU direction register for port connected to LCD
#define LCD_CLR
0 //DB0: clear display
#define LCD_HOME
1 //DB1: return to home position
#define LCD_ENTRY_MODE
2 //DB2: set entry mode
#define LCD_ENTRY_INC
1 //DB1: increment
#define LCD_ENTRY_SHIFT
0 //DB2: shift
#define LCD_ON_CTRL
3 //DB3: turn lcd/cursor on
#define LCD_ON_DISPLAY
2 //DB2: turn display on
#define LCD_ON_CURSOR
1 //DB1: turn cursor on
#define LCD_ON_BLINK
0 //DB0: blinking cursor
#define LCD_MOVE
4 //DB4: move cursor/display
#define LCD_MOVE_DISP
3 //DB3: move display (0-> move cursor)
#define LCD_MOVE_RIGHT
2 //DB2: move right (0-> left)
#define LCD_FUNCTION
5 //DB5: function set
#define LCD_FUNCTION_8BIT
4 //DB4: set 8BIT mode (0->4BIT mode)
#define LCD_FUNCTION_2LINES 3 //DB3: two lines (0->one line)
#define LCD_FUNCTION_10DOTS 2 //DB2: 5x10 font (0->5x7 font)
#define LCD_CGRAM
6 //DB6: set CG RAM address
#define LCD_DDRAM
7 //DB7: set DD RAM address
// reading:
#define LCD_BUSY
7 //DB7: LCD is busy
#define LCD_LINES
2
//visible lines
#define LCD_LINE_LENGTH
16
//line length (in characters)
// cursor position to DDRAM mapping
#define LCD_LINE0_DDRAMADDR
0x00
#define LCD_LINE1_DDRAMADDR
0x40
#define LCD_LINE2_DDRAMADDR
0x14
#define LCD_LINE3_DDRAMADDR
0x54
// progress bar defines
#define PROGRESSPIXELS_PER_CHAR
6
void LCDsendChar(uint8_t);
//forms data ready to send to 74HC164
void LCDsendCommand(uint8_t); //forms data ready to send to 74HC164
void LCDinit(void);
//Initializes LCD
void LCDclr(void);
//Clears LCD
void LCDhome(void);
//LCD cursor home
void LCDstring(uint8_t*, uint8_t); //Outputs string to LCD
void LCDGotoXY(uint8_t, uint8_t);
//Cursor to X Y position
void CopyStringtoLCD(const uint8_t*, uint8_t, uint8_t);//copies flash string
to LCD at x,y
void LCDdefinechar(const uint8_t *,uint8_t);//write char to LCD CGRAM
void LCDshiftRight(uint8_t); //shift by n characters Right
void LCDshiftLeft(uint8_t);
//shift by n characters Left
void LCDcursorOn(void);
//Underline cursor ON
void LCDcursorOnBlink(void); //Underline blinking cursor ON
void LCDcursorOFF(void);
//Cursor OFF
void LCDblank(void);
//LCD blank but not cleared
void LCDvisible(void);
//LCD visible
8. Tugas C.2
#include <avr/io.h>
#include <avr/pgmspace.h>
#include <util/delay.h>
#include "lcd_lib.h"
#include "lcd_lib.c"
//Strings stored in AVR Flash memory
const uint8_t LCDtombol1[] PROGMEM="***Tekan Tombol Scanning Keypad***\0";
//delay 1s
void delay1s(void)
{
uint8_t i;
for(i=0;i<100;i++)
{
_delay_ms(10);
}
}
int main(void)
{
LCDinit();//init LCD bit, dual line, cursor right
LCDclr();//clears LCD
DDRA=0xFF;
PORTA=0x00;
DDRD=(1<<PD4)|(1<<PD5)|(1<<PC7)|(1<<PC6);
SFIOR=(0<<PUD);
delay1s();
LCDGotoXY(0, 1);
delay1s();
while(1)//loop demos
{
CopyStringtoLCD(LCDtombol1, 0, 0);
LCDshiftRight(1);
PORTD =(1<<PD4)|(0<<PD5);
if(bit_is_clear(PIND,0))
{
LCDclr();
LCDGotoXY(8, 1);
LCDsendChar('&');
delay1s();
LCDclr();
}
_delay_ms(50);
if(bit_is_clear(PIND,1))
{
LCDclr();
LCDGotoXY(8, 1);
LCDsendChar('a');
delay1s();
LCDclr();
}
_delay_ms(50);
PORTD =(0<<PD4)|(1<<PD5);
if(bit_is_clear(PIND,0))
{
LCDclr();
LCDGotoXY(8, 1);
LCDsendChar('5');
delay1s();
LCDclr();
}
_delay_ms(50);
if(bit_is_clear(PIND,1))
{
LCDclr();
LCDGotoXY(8, 1);
LCDsendChar('7');
delay1s();
LCDclr();
}
_delay_ms(50);
}
return 0;
}
9. Tugas C.3
#include <avr/io.h>
#include <avr/pgmspace.h>
#include <util/delay.h>
#include "lcd_lib.h"
#include "lcd_lib.c"
//Strings stored in AVR Flash memory
const uint8_t LCDtombol1[] PROGMEM="Percobaan LCD\0";
//delay 1s
void delay1s(void)
{
uint8_t i;
for(i=0;i<100;i++)
{
_delay_ms(10);
}
}
uint8_t counter = 0;
int main(void)
{
LCDinit();//init LCD bit, dual line, cursor right
LCDclr();//clears LCD
DDRA=0xFF;
PORTA=0x00;
DDRD=(1<<PD4)|(1<<PD5);
SFIOR=(0<<PUD);
delay1s();
while(1)//loop demos
{
LCDGotoXY(counter, 1);
PORTD =(1<<PD4)|(0<<PD5);
if(bit_is_clear(PIND,0))
{
if(counter%2==1 && counter!=1)
{
LCDshiftRight(2);
}
counter++;
LCDsendChar('1');
delay1s();
}
_delay_ms(50);
if(bit_is_clear(PIND,1))
{
if(counter%2==1 && counter!=1)
{
LCDshiftRight(2);
}
counter++;
LCDsendChar('4');
delay1s();
}
_delay_ms(50);
PORTD =(0<<PD4)|(1<<PD5);
if(bit_is_clear(PIND,0))
{
if(counter%2==1 && counter!=1)
{
LCDshiftRight(2);
}
counter++;
LCDsendChar('2');
delay1s();
}
_delay_ms(50);
if(bit_is_clear(PIND,1))
{
if(counter%2==1 && counter!=1)
{
LCDshiftRight(2);
}
counter++;
LCDsendChar('3');
delay1s();
}
_delay_ms(50);
}
return 0;
}
10.Tugas C.4
#include <avr/io.h>
#include <avr/pgmspace.h>
#include <util/delay.h>
#include "lcd_lib.h"
#include "lcd_lib.c"
//Strings stored in AVR Flash memory
const uint8_t LCDtombol1[] PROGMEM="Percobaan LCD\0";
//delay 1s
void delay1s(void)
{
uint8_t i;
for(i=0;i<100;i++)
{
_delay_ms(10);
}
}
uint8_t counter = 0;
int main(void)
{
LCDinit();//init LCD bit, dual line, cursor right
LCDclr();//clears LCD
DDRA=0xFF;
PORTA=0x00;
DDRD=(1<<PD4)|(1<<PD5);
SFIOR=(0<<PUD);
delay1s();
while(1)//loop demos
{
LCDGotoXY(counter, 1);
PORTD =(0<<PD4)|(1<<PD5)|(1<<PD6)|(1<<PD7);
if(bit_is_clear(PIND,0))
{
if(counter%2==1 && counter!=1)
{
LCDshiftRight(2);
}
counter++;
LCDsendChar('4');
delay1s();
}
_delay_ms(50);
if(bit_is_clear(PIND,1))
{
if(counter%2==1 && counter!=1)
{
LCDshiftRight(2);
}
counter++;
LCDsendChar('2');
delay1s();
}
_delay_ms(50);
if(bit_is_clear(PIND,2))
{
if(counter%2==1 && counter!=1)
{
LCDshiftRight(2);
}
counter++;
LCDsendChar('3');
delay1s();
}
_delay_ms(50);
if(bit_is_clear(PIND,3))
}
_delay_ms(50);
PORTD =(1<<PD4)|(0<<PD5)|(1<<PD6)|(1<<PD7);
if(bit_is_clear(PIND,0))
{
if(counter%2==1 && counter!=1)
{
LCDshiftRight(2);
}
counter++;
LCDsendChar('7');
delay1s();
}
_delay_ms(50);
if(bit_is_clear(PIND,1))
{
if(counter%2==1 && counter!=1)
{
LCDshiftRight(2);
}
counter++;
LCDsendChar('5');
delay1s();
}
_delay_ms(50);
if(bit_is_clear(PIND,2))
{
if(counter%2==1 && counter!=1)
{
LCDshiftRight(2);
}
counter++;
LCDsendChar('6');
delay1s();
}
_delay_ms(50);
if(bit_is_clear(PIND,3))
{
if(counter%2==1 && counter!=1)
{
LCDshiftRight(2);
}
counter++;
LCDsendChar('B');
delay1s();
}
_delay_ms(50);
PORTD =(1<<PD4)|(1<<PD5)|(0<<PD6)|(1<<PD7);
if(bit_is_clear(PIND,0))
{
if(counter%2==1 && counter!=1)
LCDshiftRight(2);
}
counter++;
LCDsendChar('7');
delay1s();
}
_delay_ms(50);
if(bit_is_clear(PIND,1))
{
if(counter%2==1 && counter!=1)
{
LCDshiftRight(2);
}
counter++;
LCDsendChar('8');
delay1s();
}
_delay_ms(50);
if(bit_is_clear(PIND,2))
{
if(counter%2==1 && counter!=1)
{
LCDshiftRight(2);
}
counter++;
LCDsendChar('9');
delay1s();
}
_delay_ms(50);
if(bit_is_clear(PIND,3))
{
if(counter%2==1 && counter!=1)
{
LCDshiftRight(2);
}
counter++;
LCDsendChar('C');
delay1s();
}
_delay_ms(50);
PORTD =(1<<PD4)|(1<<PD5)|(1<<PD6)|(0<<PD7);
if(bit_is_clear(PIND,0))
{
if(counter%2==1 && counter!=1)
{
LCDshiftRight(2);
}
counter++;
LCDsendChar('*');
delay1s();
}
_delay_ms(50);
if(bit_is_clear(PIND,1))
{
if(counter%2==1 && counter!=1)
{
LCDshiftRight(2);
}
counter++;
LCDsendChar('0');
delay1s();
}
_delay_ms(50);
if(bit_is_clear(PIND,2))
{
if(counter%2==1 && counter!=1)
{
LCDshiftRight(2);
}
counter++;
LCDsendChar('#');
delay1s();
}
_delay_ms(50);
if(bit_is_clear(PIND,3))
{
if(counter%2==1 && counter!=1)
{
LCDshiftRight(2);
}
counter++;
LCDsendChar('D');
delay1s();
}
_delay_ms(50);
}
return 0;
}