#include #include #include #include #include #include #include "portbits.h" #include "lc7981.h" #include "6x8_horizontal_MSB_1.h" #include "16x16_Symbols.h" #include unsigned char lcd_xpos, lcd_ypos; void lcd_init(void) { // Die angegebenen Ports sind AUSGÄNGE DDRD |= (1 << PD7) | (1 << PD6) | (1 << PD5) | (1 << PD4) | (1 << PD3) | (1 << PD2); // Alle D - Ports sind Ausgänge LCD_DDR |= 0xFF; #ifdef RES RES = 0; // Reset wird eingeleitet _delay_us(100); // Delay RES = 1; // Reset ausschalten #endif _delay_ms(10); // Delay #ifdef CS CS = 0; // Chip Enable #endif lcd_writecom(0x01); // character pitch lcd_writedat(0x77); // 8x8 chars lcd_writecom(0x02); // characters lcd_writedat(19); lcd_writecom(0x08); // startadress low lcd_writedat(0x00); // 0 lcd_writecom(0x09); // startadress high lcd_writedat(0x00); // 0 lcd_writecom(0x03); // set duty lcd_writedat(79); // 1/80 lcd_writecom(0x00); // mode con lcd_writedat(0x32); // display on #ifdef CS CS = 1; // Chip Disable #endif lcd_clear(); // LCD löschen } void lcd_waitbusy(void) { unsigned char temp; CS = 0; // Chip Enable RW = 1; // Data Read RS = 1; // Reset ausschalten LCD_DDR = 0x00; // Alle D - PORTS sind Eingänge do { _delay_us(0.5); // Delay Enable = 1; // Enable _delay_us(0.6); // Delay temp = LCD_PIN; // Holen des LCD Pin Status Enable=0; // Disable } while (temp&128); // Busy LCD_DDR = 0xFF; // Alle D - Ports sind Ausgänge CS = 1; // Chip Disable } void lcd_write(unsigned char byte) { CS = 0; // Chip Enable RW = 0; LCD_PORT = (byte); _delay_us(0.1); // Delay Enable = 1; // Enable _delay_us(0.8); // Delay Enable = 0; // Disable CS = 1; // Chip Disable } void lcd_writedat( unsigned char byte ) { /* H: Instruction || L: Data */ RS = 0; /* Bytecode schreiben */ lcd_write( byte ); } void lcd_writecom( unsigned char byte ) { /* Wait for the busy flag to clear */ lcd_waitbusy(); lcd_write( byte ); // Bytecode schreiben } void lcd_clear( void ) { unsigned short i; lcd_setadress( 0,0 ); for (i=0; i<160/8*80; i++) lcd_writebyte( 0 ); } void lcd_setadress( unsigned char x, unsigned char y ) { unsigned short adress; adress = y*20+x; lcd_writecom(0x0A); // writeadress low lcd_writedat(adress&255); lcd_writecom(0x0B); // writeadress high lcd_writedat(adress/256); } void lcd_writebyte(unsigned char byte) { lcd_writecom(0x0C); lcd_writedat(byte); } void lcd_fill(unsigned char x1, unsigned char y1, unsigned char x2, unsigned char y2, unsigned char col) { unsigned char y,x; for (y=y1;y<=y2; y++) { for (x=x1;x<=x2; x++) { if (col) lcd_setpixel(x,y); else lcd_clrpixel(x,y); } } } void lcd_setpixel(unsigned char x, unsigned char y) { if ((x>=160)||(y>=80)) return; lcd_setadress(x/8,y); lcd_writecom(0x0F); lcd_writedat(x&7); } void lcd_clrpixel(unsigned char x, unsigned char y) { if ((x>=160)||(y>=80)) return; lcd_setadress(x/8,y); lcd_writecom(0x0E); lcd_writedat(x&7); } void lcd_gotoxy(unsigned char x, unsigned char y) { lcd_xpos=x; lcd_ypos=y; } void lcd_writechar(unsigned char b) { unsigned char c,i,j; if (lcd_xpos+5>=160) lcd_xpos=0; if (lcd_ypos+7>=80) lcd_ypos=0; for (i=0; i<8; i++) { c=pgm_read_byte(&font[b][i]); for (j=0; j<6; j++) { if (c&(32>>j)) lcd_setpixel(lcd_xpos+j,lcd_ypos+i); else lcd_clrpixel(lcd_xpos+j,lcd_ypos+i); } } lcd_xpos+=6; } void lcd_writeSymbol(unsigned char b) { unsigned char i,j,c; if (lcd_xpos+15>=160) lcd_xpos=0; if (lcd_ypos+15>=80) lcd_ypos=0; for (i=0; i<32; i++) { c = pgm_read_byte(&symbols[b][i]); if(i%2) { for (j=8; j<16; j++) { if (c&(128>>(j-8))) lcd_setpixel(lcd_xpos+j,lcd_ypos+floor(i/2)); else lcd_clrpixel(lcd_xpos+j,lcd_ypos+floor(i/2)); } }else{ for (j=0; j<8; j++) { if (c&(128>>j)) lcd_setpixel(lcd_xpos+j,lcd_ypos+floor(i/2)); else lcd_clrpixel(lcd_xpos+j,lcd_ypos+floor(i/2)); } } } lcd_xpos+=16; } void lcd_writestringP(const char *string) { char c; for(;;) { c=pgm_read_byte(string++); if (!c) break; lcd_writechar(c); } } void lcd_writestringP2(const char *string, unsigned char x, unsigned char y) { lcd_gotoxy(x,y); char c; for(;;) { c=pgm_read_byte(string++); if (!c) break; lcd_writechar(c); } } void bresenham_line (unsigned short x1, unsigned short y1, unsigned short x2, unsigned short y2) { signed short dx,dy,x,y; signed char sdx,sdy; unsigned short i,px,py; dx=(signed int)x2-x1; // the horizontal distance of the line dy=(signed int)y2-y1; // the vertical distance of the line if (dx==0) sdx=0; if (dx>0) sdx=1; else { sdx=-1; dx=-dx; } if (dy==0) sdy=0; if (dy>0) sdy=1; else { sdy=-1; dy=-dy; } x=dx*2; y=dy*2; px=x1; py=y1; lcd_setpixel (px,py); if (dx>=dy) // the line is more horizontal than vertical { for(i=0;i=dx) { y-=dx; py+=sdy; } px+=sdx; lcd_setpixel (px,py); } } else // the line is more vertical than horizontal { for(i=0;i=dy) { x-=dy; px+=sdx; } py+=sdy; lcd_setpixel (px,py); } } } void lcd_line (unsigned char x1, unsigned char y1, unsigned char x2, unsigned char y2) { unsigned char temp; if (y1==y2) { if (x1>x2) { temp=x1; x1=x2; x2=temp; } for (temp=x1; temp<=x2; temp++) lcd_setpixel (temp,y1); } else if (x1==x2) { if (y1>y2) { temp=y1; y1=y2; y2=temp; } for (temp=y1; temp<=y2; temp++) lcd_setpixel (x1,temp); } else bresenham_line (x1, y1, x2, y2); }