Ovladani LCD displeje

Miroslav Hatina hatina at chromspec.sk
Fri May 18 10:41:36 CEST 2001


Ahoj,

pouzivam stvorbitovu celkom spolahlivo podla nasledujuceho kodu -

#define RS     P1_1             /* register select A0  */
#define enable P1_3             /* enable displej      */
#define RW     P1_2             /* R/W                 */

// data D7-D4	->	P1_7-P1_4

#define clear      0x01
#define home       0x02
#define cur_left   0x10
#define cur_right  0x14
#define cur_on     0x0E
#define cur_off    0x0C
#define cur_blink  0x0F
#define set_1line  0x80
#define set_2line  0xC0
#define set_fnc    0x38
#define set_mod    0x06

void o(unsigned char a)
{
    while(a--) { _nop_(); }
}

void en()               // enable disp
{
    enable = 1;
    o(20);
    enable = 0;
}

void cwr (unsigned char z)
{
    P1 = z & 0xf0;
    en();
    o(20);
    P1 = z << 4;
    en();
    o(20);
    if(z < 3)
    {
        t1ms(3);			// pre istotu pockaj 3 ms
    }
}

void inic()                     // inicializuje displej
{                               // 4 bitovu zbernicu
    P1 = 0x30;
    en();
    t1ms(5);
    en();
    en();                       // dolezite inak to nefachci
    P1 = 0x20;
    en();

    cwr(set_mod);
    cwr(cur_off);
    cwr(0x28);                  // set fnc mode 2 line
    cwr(clear);
}

snad to niekomu pomoze.

S pozdravom			Miro





More information about the HW-list mailing list