#define F_CPU 1000000 // Taktfrequenz des Atmega32 #include // AVR Register und Konstantendefinitionen #include // Bibliothek mit Warteroutinen //variablen deklarieren uint8_t contrast = 0xFF; uint8_t Xpixel = 128; uint8_t Ypages = 8; uint8_t xoffset; uint8_t topview = 0; // Versorgung 3,3V, 4fach-Boost an //----------------------------------------------------------------------------------------- // Konstanten fuer ST7565 //----------------------------------------------------------------------------------------- #define DISPOFF 0xAE #define DISPON 0xAF #define DISPSTART 0x40 #define PAGEADR 0xB0 #define COLADRL 0x00 #define COLADRH 0x10 #define ADCNORMAL 0xA0 #define ADCREVERSE 0xA1 #define COMNORMAL 0xC0 #define COMREVERSE 0xC8 #define DISPNORMAL 0xA6 #define DISPREVERSE 0xA7 #define LCDBIAS9 0xA2 #define LCDBIAS7 0xA3 #define RESET 0xE2 #define SETPOWERCTRL 0x28 #define REGRESISTOR 0x20 #define SETCONTRAST 0x81 #define STATINDMODE 0xAC #define BOOSTERRATIO 0xF8 //----------------------------------------------------------------------------------------- // Portdefinitionen //----------------------------------------------------------------------------------------- #define DOGCSPORT PORTB #define DOGCS 4 #define DOGRESPORT PORTC #define DOGRES 6 #define DOGA0PORT PORTC #define DOGA0 2 #define DOGSCLPORT PORTB #define DOGSCL 7 #define DOGSIPORT PORTB #define DOGSI 5 //----------------------------------------------------------------------------------------- // Makrodefinitionen //----------------------------------------------------------------------------------------- #define SetBit(adr, bnr) ( (adr) |= (1 << (bnr)) ) #define ClrBit(adr, bnr) ( (adr) &= ~(1 << (bnr)) ) #define DOGENABLE ClrBit(DOGCSPORT, DOGCS) #define DOGDISABLE SetBit(DOGCSPORT, DOGCS) #define DOGCOMMAND ClrBit(DOGA0PORT, DOGA0) #define DOGDATA SetBit(DOGA0PORT, DOGA0) //----------------------------------------------------------------------------------------- void dogSPIout(char out) { char msk; msk = 0x80; do { ClrBit(DOGSCLPORT, DOGSCL); if(out & msk) SetBit(DOGSIPORT, DOGSI); else ClrBit(DOGSIPORT, DOGSI); SetBit(DOGSCLPORT, DOGSCL); msk >>= 1; } while(msk > 0); } //----------------------------------------------------------------------------------------- void initDOGM128(void) { DOGENABLE; DOGCOMMAND; dogSPIout(DISPSTART + 0); if(topview) { xoffset = 4; dogSPIout(ADCNORMAL); dogSPIout(COMREVERSE); } else { xoffset = 0; dogSPIout(ADCREVERSE); dogSPIout(COMNORMAL); } dogSPIout(DISPNORMAL); dogSPIout(LCDBIAS9); dogSPIout(SETPOWERCTRL+7); dogSPIout(BOOSTERRATIO); dogSPIout(0); dogSPIout(REGRESISTOR+7); dogSPIout(SETCONTRAST); dogSPIout(contrast); dogSPIout(STATINDMODE); dogSPIout(0); dogSPIout(DISPON); DOGDISABLE; } //----------------------------------------------------------------------------------------- void ResetDOG(void) { SetBit(DOGCSPORT, DOGCS); SetBit(DOGSCLPORT, DOGSCL); SetBit(DOGSIPORT, DOGSI); SetBit(DOGA0PORT, DOGA0); ClrBit(DOGRESPORT, DOGRES); _delay_us(5); SetBit(DOGRESPORT, DOGRES); } //----------------------------------------------------------------------------------------- void DogKontrast(void) { DOGENABLE; DOGCOMMAND; dogSPIout(SETCONTRAST); dogSPIout(contrast); DOGDISABLE; } //----------------------------------------------------------------------------------------- // Makro zum ausgeben von irgendwas auf dem Display //----------------------------------------------------------------------------------------- void ausgabe(void) { DOGENABLE; DOGDATA; dogSPIout(0xF0);dogSPIout(0xF0);dogSPIout(0xF0);dogSPIout(0xF0);dogSPIout(0xF0);dogSPIout(0xF0); DOGDISABLE; } //----------------------------------------------------------------------------------------- //Variablen-Deklarationen volatile char FCV_TASTER; //Hauptprogramm int main() { //Ausgänge Definieren DDRB = 0xFF; DDRC = 0xFF; //Hauptschleife while(1) { //Output; High auf A0/Pullup für Taster //Output: 1 -> A0 DDRA = DDRA | 0x01; if (1) PORTA = (PORTA & 0xfe) | 0x01; else PORTA = PORTA & 0xfe; //Input; Taster gedrückt = LOW //Input: A0 -> taster DDRA = DDRA & 0xfe; FCV_TASTER = ((PINA & 0x01) == 0x01); //Entscheidung //Entscheidung: taster=0? if (FCV_TASTER==0) { //Schleife //Schleife: While taster=0 while (FCV_TASTER==0) { } initDOGM128(); ausgabe(); } } mainendloop: goto mainendloop; }