Kompatibilní zapojení: LCD panel s ATmega8

Ke stažení: wait.c == wait.pdf == wait.htm


/*---------------------------------------------------------------------------

soubor: wait.c
verze:  1.0
datum:  9.1.2012
popis:

Cekaci rutiny a makra pro bitove operace
Cekaci rutiny jsou mnohem uspornejsi nez bezne "delay.h"

Tento soubor vynikl ze souboru "mojelib.h" jehoz autora bohuzel neznam.

---------------------------------------------------------------------------*/

// Zmena bitu portu, IO registru nebo promenne:
#define setb(bajt,bit)    bajt |= 1<<(bit)    //nastav bit
#define clrb(bajt,bit)    bajt &= ~(1<<(bit)) //nuluj bit
#define negb(bajt,bit)    bajt ^= 1<<(bit)    //neguj bit

// Casove smycky:
void wait_ms  (unsigned int c);              // cekej milisekund(max65553):
void wait_us  (unsigned int c);              // cekej mikrosekund(max65553):

//cekej milisekund:
unsigned char reg21 = F_CPU / 60000;    // F_CPU = frekv. oscilatoru [Hz],
                                        // (vnitrni konstanta prekladace)
void wait_ms  (unsigned int c)
{
    asm("push    r20");
    asm("push    r21");
asm("_Wms0:");
    asm("ldi    r20,0x14");
asm("_Wms1:");
    asm("lds    r21,reg21");
asm("_Wms2:");
    asm("dec    r21");
    asm("brne    _Wms2");
    asm("dec        r20");
    asm("brne    _Wms1");
    asm("dec    r24");
    asm("brne    _Wms0");
    asm("dec    r25");
    asm("brpl    _Wms0");
    asm("pop       r21");
    asm("pop       r20");
}

//cekej mikrosekund:
unsigned char reg20 = F_CPU / 6000000 + 1;
void wait_us(unsigned int c)
{
    asm("push    r20");
asm("_wus0:");
    asm("lds    r20,reg20");  // 1-6MHz: r20=1  6-12MHz: r20=2
asm("_wus1:");
    asm("dec    r20");
    asm("brne    _wus1");
    asm("dec    r24");
    asm("brne    _wus0");
    asm("dec    r25");
    asm("brpl    _wus0");
    asm("pop    r20");
}

//eof
//(c) OK1ZKV 2012