Sie sind auf Seite 1von 7

THE COLLEGE OF ELECTRICAL AND ELECTRONIC TECHNOLOGY

Embedded System Lab

Experiment #4

Lcd Programming

Objective:
 Writing a program in mikroc and designing the application circuit in proteus.
 Students will implement different programs to program the lcd.

Programs Practice
1st program

Parts used for this projects :


 DEVICES => [ BUTTON , LED-RED , ARDUINO UNO, RESISTOR=220ohm & 1000ohm]
 TERMINALS => [ GROUND , POWER ]

Part 1: making the circuit on proteus :

Prepared by: Eng. Huda A. Elsuaysi 1


Code:

void main() {
DDRD=0xff;
DDRB=0x00;
while(1) {
if(PINB.B0){
PORTD.B0=1;
PORTD.B1=1;
}
else if(PINB.B1){
PORTD.B2=1;
PORTD.B3=1;
}
else{
PORTD.B0=0;
PORTD.B1=0;
PORTD.B2=0;
PORTD.B3=0;
}
}
}

Prepared by: Eng. Huda A. Elsuaysi 2


2nd program

Parts used for this projects :


 DEVICES => [ BUTTON , LED-RED , ARDUINO UNO, RESISTOR=330ohm & 1000ohm, POT-
Hig, LCD(LM016L)].
 TERMINALS => [ GROUND , POWER ].

Prepared by: Eng. Huda A. Elsuaysi 3


Code1:

// Lcd pinout settings


sbit LCD_RS at PORTD0_bit;
sbit LCD_EN at PORTD1_bit;
sbit LCD_D7 at PORTD5_bit;
sbit LCD_D6 at PORTD4_bit;
sbit LCD_D5 at PORTD3_bit;
sbit LCD_D4 at PORTD2_bit;
// Pin direction
sbit LCD_RS_Direction at DDD0_bit;
sbit LCD_EN_Direction at DDD1_bit;
sbit LCD_D7_Direction at DDD5_bit;
sbit LCD_D6_Direction at DDD4_bit;
sbit LCD_D5_Direction at DDD3_bit;
sbit LCD_D4_Direction at DDD2_bit;
void main() {
Lcd_Init();
// Clear Lcd display:
Lcd_Cmd(_LCD_CLEAR);
Lcd_Out(1, 3, "Hello!");
Lcd_Out(2, 3, "EMBEDDED!");
}

Prepared by: Eng. Huda A. Elsuaysi 4


Code2:

// Lcd pinout settings


sbit LCD_RS at PORTD0_bit;
sbit LCD_EN at PORTD1_bit;
sbit LCD_D7 at PORTD5_bit;
sbit LCD_D6 at PORTD4_bit;
sbit LCD_D5 at PORTD3_bit;
sbit LCD_D4 at PORTD2_bit;
// Pin direction
sbit LCD_RS_Direction at DDD0_bit;
sbit LCD_EN_Direction at DDD1_bit;
sbit LCD_D7_Direction at DDD5_bit;
sbit LCD_D6_Direction at DDD4_bit;
sbit LCD_D5_Direction at DDD3_bit;
sbit LCD_D4_Direction at DDD2_bit;
void main() {
char f;
DDRC=0XFF;
Lcd_Init();
// Clear Lcd display:
Lcd_Cmd(_LCD_CLEAR);
Lcd_Out(1, 3, "Hello!");
Lcd_Out(2, 3, "EMBEDDED!");
f=0;
while(1)
{
portc=f;
delay_ms(1000);
f++;
}
3nd } program

Prepared by: Eng. Huda A. Elsuaysi 5


Parts used for this projects :
 DEVICES => [ BUTTON , LED-RED , ARDUINO UNO, RESISTOR=330ohm & 1000ohm, POT-
Hig, LCD(LM016L)].
 TERMINALS => [ GROUND , POWER ].

Prepared by: Eng. Huda A. Elsuaysi 6


Code3:

// Lcd pinout settings DDRB.B2=0;

sbit LCD_RS at PORTD0_bit; DDRB.B3=0;


f=0;
sbit LCD_EN at PORTD1_bit;
d=0;
sbit LCD_D7 at PORTD5_bit;
h=0;
sbit LCD_D6 at PORTD4_bit; while(1){
sbit LCD_D5 at PORTD3_bit; if(PINB.B2){

sbit LCD_D4 at PORTD2_bit; while(PINB.B2){};


PORTC.B0=1;
// Pin direction
PORTC.B1=1;
sbit LCD_RS_Direction at DDD0_bit;
PORTC.B2=0;
sbit LCD_EN_Direction at DDD1_bit; PORTC.B3=0;
sbit LCD_D7_Direction at DDD5_bit; f++;

sbit LCD_D6_Direction at DDD4_bit; shortTOstr(f,TXT);


Lcd_Out(2, 1, TXT);
sbit LCD_D5_Direction at DDD3_bit;
d++;
sbit LCD_D4_Direction at DDD2_bit;
shortTOstr(d,TXT);
void main() { Lcd_Out(2, 6, TXT);
signed char f,d,h; }

unsigned char TXT[10]; if(PINB.B3){


while(PINB.B3){};
Lcd_Init();
PORTC.B2=1;
// Clear Lcd display:
PORTC.B3=1;
Lcd_Cmd(_LCD_CLEAR); PORTC.B0=0;
// Write text "Hello!" on Lcd PORTC.B1=0;

starting from row 1, column 3: h= f+d;


shortTOstr(h,TXT);
Lcd_Out(1, 3, "Hello!");
Lcd_Out(2, 10, TXT);
DDRD=0XFF;
}
DDRC=0XFF; }
}

Prepared by: Eng. Huda A. Elsuaysi 7

Das könnte Ihnen auch gefallen