Difference between revisions of "Lcd text"

From Electriki
Jump to navigationJump to search
Line 24: Line 24:
  
 
void out_d()
 
void out_d()
 +
 
{
 
{
 +
 
DDRD = 0xff;
 
DDRD = 0xff;
 +
 
}
 
}
  
 
void in_c()
 
void in_c()
 +
 
{
 
{
 +
 
DDRC = 0x00;
 
DDRC = 0x00;
 +
 
}
 
}
  
 
void out_c()
 
void out_c()
 +
 
{
 
{
 +
 
DDRC = 0xff;
 
DDRC = 0xff;
 +
 
}
 
}
  
 
write_i()
 
write_i()
 +
 
{
 
{
 +
 
PORTC = 4;
 
PORTC = 4;
 
PORTC = 0;
 
PORTC = 0;
 +
 
}
 
}
  
 
read_bf()
 
read_bf()
 +
 
{
 
{
 +
 
// PORTC = 4;
 
// PORTC = 4;
 
PORTC = 6;
 
PORTC = 6;
 +
 
}
 
}
  
 
write_d()
 
write_d()
 +
 
{
 
{
 +
 
PORTC = 5;
 
PORTC = 5;
 
PORTC = 1;
 
PORTC = 1;
 +
 
}
 
}
  
 
read_d()
 
read_d()
 +
 
{
 
{
 +
 
// PORTC = 4;
 
// PORTC = 4;
 
PORTC = 7;
 
PORTC = 7;
 +
 
}
 
}
  
 
clear()
 
clear()
 +
 
{
 
{
 +
 
PORTD = 1;  // clear display
 
PORTD = 1;  // clear display
 
write_i();
 
write_i();
Line 73: Line 96:
  
 
_delay_ms(100);
 
_delay_ms(100);
 +
 
}
 
}
  
  
 
void init(void)
 
void init(void)
 +
 
{
 
{
 +
 
out_d();
 
out_d();
 
out_c();
 
out_c();
Line 114: Line 140:
  
 
void bf()
 
void bf()
 +
 
{
 
{
 +
 
unsigned int bf;
 
unsigned int bf;
 
DDRB=0xff;
 
DDRB=0xff;
Line 125: Line 153:
  
 
while(bf) {
 
while(bf) {
 +
 
read_bf();
 
read_bf();
 
bf = PORTD;
 
bf = PORTD;
Line 132: Line 161:
 
PORTB=0x0;
 
PORTB=0x0;
 
_delay_ms(50);
 
_delay_ms(50);
 +
 
}
 
}
  
Line 140: Line 170:
  
 
void left()
 
void left()
 +
 
{
 
{
 +
  
 
PORTD = 0x18;
 
PORTD = 0x18;
 
write_i();
 
write_i();
 
bf();
 
bf();
 +
 
}
 
}
  
  
 
int main()
 
int main()
 +
 
{
 
{
 +
 
unsigned int i;
 
unsigned int i;
  
Line 327: Line 362:
 
}
 
}
 
return 0;
 
return 0;
 +
 
}
 
}

Revision as of 08:54, 1 April 2009

2 row lcd

Hello fellows, i've finally decided to write little bit on this wiki page. So, what i'll be writing about ? For last few days i was playing with little lcd display and i finally managed to write some text with it ;)

Here is video how does it look like: http://www.youtube.com/watch?v=i1tZwHCo_g4

and here is source code:

  1. define F_CPU 1000000UL
  2. include <util/delay.h>
  3. include <avr/io.h>

void bf();


void in_d()

{

DDRD = 0x00;

}

void out_d()

{

DDRD = 0xff;

}

void in_c()

{

DDRC = 0x00;

}

void out_c()

{

DDRC = 0xff;

}

write_i()

{

PORTC = 4; PORTC = 0;

}

read_bf()

{

// PORTC = 4; PORTC = 6;

}

write_d()

{

PORTC = 5; PORTC = 1;

}

read_d()

{

// PORTC = 4; PORTC = 7;

}

clear()

{

PORTD = 1; // clear display write_i(); bf();

PORTD = 0b00000110; // entry mode write_d(); bf();

_delay_ms(100);

}


void init(void)

{

out_d(); out_c();


_delay_ms(15); PORTD = 0b00110000; // function set ( DL, N, F ) write_i();

_delay_ms(4.1); PORTD = 0b00110000; // function set ( DL,N,F ) write_i();

_delay_us(100); PORTD = 0b00110000; // function set ( DL,N,F ) write_i();

_delay_ms(4.1); PORTD = 0b00111000; // set N and F write_i();

_delay_ms(4.1); PORTD = 0b00001000; // display off write_i();

_delay_ms(4.1); PORTD = 0b00001100; // display on write_i();

_delay_ms(4.1); PORTD = 0b00000110; // entry mode write_i();


}

void bf()

{

unsigned int bf; DDRB=0xff;

in_d();

read_bf(); bf = PORTD; bf &= 0b10000000;

while(bf) {

read_bf(); bf = PORTD; bf &= 0b10000000; PORTB=0xff; _delay_ms(100); PORTB=0x0; _delay_ms(50);

}

out_d();


}

void left()

{


PORTD = 0x18; write_i(); bf();

}


int main()

{

unsigned int i;

init(); _delay_ms(11);

clear(); bf();

while(1) {

PORTD = 0x23; // # write_d(); bf(); _delay_ms(500);

PORTD = 101; // e write_d(); bf(); _delay_ms(500);

PORTD = 108; // l write_d(); bf(); _delay_ms(500);

PORTD = 101; // e write_d(); bf(); _delay_ms(500);

PORTD = 99; // c write_d(); bf(); _delay_ms(500);

PORTD = 116; // t write_d(); bf(); _delay_ms(500);


PORTD = 114; // r write_d(); bf(); _delay_ms(500);


PORTD = 111; // o write_d(); bf(); _delay_ms(500);

PORTD = 110; // n write_d(); bf(); _delay_ms(500);

PORTD = 105; // i write_d(); bf(); _delay_ms(500);

PORTD = 99; // c write_d(); bf(); _delay_ms(500);

PORTD = 115; // s write_d(); bf(); _delay_ms(500);

PORTD = 0x20; // " " write_d(); bf(); _delay_ms(500);

PORTD = 0x28; // ( write_d(); bf(); _delay_ms(500);

PORTD = 97; // a write_d(); bf(); _delay_ms(500);

PORTD = 116; // t write_d(); bf(); _delay_ms(500);

left(); PORTD = 0x29; // ) write_d(); bf(); _delay_ms(500);

left(); PORTD = 0x20; // " " write_d(); bf(); _delay_ms(500);

left(); PORTD = 0x49; // I write_d(); bf(); _delay_ms(500);

left(); PORTD = 82; // R write_d(); bf(); _delay_ms(500);

left(); PORTD = 67; // C write_d(); bf(); _delay_ms(500);

left(); PORTD = 78; // N write_d(); bf(); _delay_ms(500);

left(); PORTD = 101; // e write_d(); bf(); _delay_ms(500);

left(); PORTD = 116; // t write_d(); bf(); _delay_ms(500);

left(); PORTD = 0x20; // " " write_d(); bf(); _delay_ms(500);

left(); PORTD = 114; // r write_d(); bf(); _delay_ms(500);

left(); PORTD = 117; // u write_d(); bf(); _delay_ms(500);

left(); PORTD = 108; // l write_d(); bf(); _delay_ms(500);

left(); PORTD = 101; // e write_d(); bf(); _delay_ms(1000);


clear(); _delay_ms(500);

} return 0;

}