//----------------------------------------------------------------------------------------- // Portkonstanten #define DMRESPORT PORTA #define DMRES 0 #define DMCSPORT PORTA #define DMCS 1 #define DMCLKPORT PORTA #define DMCLK 2 #define DMSIDPORT PORTA #define DMSID 3 #define DMSODPIN PINA #define DMSOD 4 //----------------------------------------------------------------------------------------- // Funktions Makros #define SetBit(adr, bnr) ( (adr) |= (1 << (bnr)) ) #define ClrBit(adr, bnr) ( (adr) &= ~(1 << (bnr)) ) #define EorBit(adr, bnr) ( (adr) ^= (1 << (bnr)) ) #define TstBit(adr, bnr) ( ((adr) & (1 << (bnr))) > 0 ) //----------------------------------------------------------------------------------------- void SPIout(char out) { char i = 8; while(i-- > 0) { ClrBit(DMCLKPORT, DMCLK); if(out & 1) SetBit(DMSIDPORT, DMSID); else ClrBit(DMSIDPORT, DMSID); out >>= 1; _NOP(); _NOP(); SetBit(DMCLKPORT, DMCLK); } } char SPIin(void) { char i = 8, in = 0; while(i-- > 0) { ClrBit(DMCLKPORT, DMCLK); _NOP(); _NOP(); _NOP(); _NOP(); _NOP(); SetBit(DMCLKPORT, DMCLK); in >>= 1; if(TstBit(DMSODPIN, DMSOD)) in |= 0x80; } return in; } //----------------------------------------------------------------------------------------- void lcdbefout(char out) { ClrBit(DMCSPORT, DMCS); SPIout(0x1F); SPIout(out & 0x0F); SPIout(out >> 4); SetBit(DMCSPORT, DMCS); if(out > 0 && out < 4) waitms(3); else waitus(50); } void lcddatout(char out) { ClrBit(DMCSPORT, DMCS); SPIout(0x5F); SPIout(out & 0x0F); SPIout(out >> 4); SetBit(DMCSPORT, DMCS); waitus(50); } //----------------------------------------------------------------------------------------- GLOBAL void LcdClr(void) { lcdbefout(0x01); // Display l”schen } GLOBAL void LcdInit(void) { ClrBit(DMRESPORT, DMRES); waitms(2); SetBit(DMRESPORT, DMRES); waitms(50); lcdbefout(0x34); // Function Set: 8-Bit, Bit RE=1 lcdbefout(0x09); // ext. Function Set: 4 Zeilen Modus lcdbefout(0x30); // Function Set: 8-Bit, Bit RE=0 lcdbefout(0x0C); // Display On/Off: Display ein, Cursor aus lcdbefout(0x06); // Entry Mode Set: Cursor Auto-Increment LcdClr(); }