#include <90s8535.h> #include #include #include #include #include #include #define wr PORTB.0 #define rd PORTB.1 #define cd PORTB.2 #define XTAL 8000000 #define DEBOUNCE 256 void pause(void); void PORTC_output(void); void PORTC_input(void); void out(char commando,char dataa, char datab); void lcd_data(char daten); void lcd_commando(char commando); void lcd_status(void); void autoreset(void); unsigned char tasten(void); void autowrite(void); void t6963cinit(void); void lcd_PutPixel(unsigned char x, unsigned char y, unsigned char Set); void lcd_Clear_Graphics(void); void lcd_Clear_Text(void); void lcd_write_zahl(unsigned int x, unsigned int y, unsigned char *text); void lcd_write_text(unsigned int x, unsigned int y, unsigned char flash *text); void lcd_write_char(unsigned char const data, unsigned char x,unsigned char y, ); void lcd_printfz(unsigned int x, unsigned int y, unsigned char flash *format, unsigned char *zahl); void lcd_printft(unsigned int x, unsigned int y, unsigned char flash *text); void f_UART2_SendText(unsigned char Text[]); unsigned char pos=0; char text_buffer[10]; char zahl_buffer[10]; char flash format[5]; char Zeichen; unsigned char uca_Test[10] = {"Ein Test"}; unsigned char prescaler,sekunde; interrupt [UART_RXC] void uart_rx_isr(void) { Zeichen = UDR; } interrupt [UART_TXC] void uart_tx_isr(void) { } interrupt [TIM1_COMPA] void timer1_compa_isr(void) { #if XTAL % DEBOUNCE // bei rest OCR1A = XTAL / DEBOUNCE - 1; // compare DEBOUNCE - 1 times #endif if( --prescaler == 0 ) { prescaler = DEBOUNCE; //sekunde++; // exact one second over #if XTAL % DEBOUNCE // handle remainder OCR1A = XTAL / DEBOUNCE + XTAL % DEBOUNCE - 1; // compare once per second #endif } tasten(); } // Taster werden hier entprellt unsigned char tasten(void) { if (PIND.6 == 1) { return 1; } if (PIND.5 == 1) { return 2; } if (PIND.4 == 1) { return 3; } } void pause(void) { #asm nop nop #endasm } void PORTC_output(void) { DDRC = 0xFF; PORTC = 0; } void PORTC_input(void) { DDRC = 0x00; PORTC = 0xFF; } void autoreset(void) { PORTC = 0xB2; pause(); wr = 0; pause(); wr = 1; } void autowrite(void) { PORTC = 0xB0; pause(); wr = 0; pause(); wr = 1; } void lcd_status(void) { unsigned char lcd_status; PORTC_input(); pause(); cd = 1; pause(); wr = 1; pause(); do { rd = 0; pause(); lcd_status = PINC; rd = 1; pause(); } while ((lcd_status & 0x03) != 0x03); PORTC_output(); } void out(char commando,char dataa, char datab) { lcd_status(); pause(); rd = 1; pause(); cd = 0; pause(); PORTC = dataa; pause(); wr = 0; pause(); wr = 1; pause(); PORTC = datab; pause(); wr = 0; pause(); wr = 1; pause(); cd = 1; pause(); PORTC = commando; pause(); wr = 0; pause(); wr = 1; pause(); cd = 1; pause(); } void lcd_data(char daten) { lcd_status(); cd = 0; pause(); PORTC = daten; pause(); wr = 0; pause(); wr = 1; pause(); cd = 1; } void lcd_commando(char commando) { pause(); rd = 1; pause(); cd = 1; pause(); PORTC = commando; pause(); wr = 0; pause(); wr = 1; pause(); cd = 1; pause(); } void LCD_PutPixel(unsigned char x, unsigned char y, unsigned char Set) { unsigned int XY; unsigned char bitByte; XY=0x000; XY=XY+(y*22); XY=XY+(x/6); out(0x24, XY & 0x00FF, XY>>8); bitByte=5-(x % 6); if (0 != Set) { bitByte |= 0xF8; } else { bitByte|=0xF0; } out(bitByte, 0, 0); //0b1111SXXX , s is set/reset, xxx is bit number xxx //(Each memorybyte i six graphics bits (pixels)) } void t6963cinit(void) { out(0x42, 0, 0); out(0x43, 22, 0); out(0x40, 0, 0x10); out(0x41, 22, 0); out(0x21, 0, 0x10); out(0x24, 0, 0x10); out(0x80, 0, 0); out(0xA7, 0, 0); out(0x90, 0, 0); lcd_Clear_Graphics(); lcd_Clear_Text(); out(0x9C, 0, 0); } void lcd_Clear_Graphics(void) { unsigned int i; out(0x24,0,0); for(i=0;i<4192;i++) { out(0xC0, 0, 0); } out(0x24,0,0); } void LCD_Clear_Text(void) { unsigned char address_l, address_h; unsigned int address, address_limit; /* Set Address Pointer */ address = 0x1000; address_l = address & 0xff; address_h = address >> 8; out(0x24,address_l,address_h); address_limit = (0x1000 + 3072); while (address < address_limit) { out(0xC0,0,0); address = address + 1; } out(0x21,0x0 & 0xff,0x0 >> 8); //set cursor position } void lcd_gotoxy(unsigned int x, unsigned int y) // Set Adresspointer { unsigned int address; address = ((unsigned int)y * 22) + x + 0x1000; out(0x24,address & 0xff,address >> 8); } void lcd_write_zahl(unsigned int x, unsigned int y, unsigned char *text) // write String an pos x, y { unsigned int address; address = ((unsigned int)y * 22) + x + 0x1000; out(0x24,address & 0xff,address >> 8); while (*text) { out(0xC0,0,(*text++)-0x20); } } void lcd_write_text(unsigned int x, unsigned int y, unsigned char flash *text) // write String an pos x, y { unsigned int address; address = ((unsigned int)y * 22) + x + 0x1000; out(0x24,address & 0xff,address >> 8); while (*text) { out(0xC0,0,(*text++)-0x20); } } void lcd_printfz(unsigned int x, unsigned int y, unsigned char flash *format, unsigned char *zahl) { sprintf(zahl_buffer,format,zahl); lcd_write_zahl(x, y, zahl_buffer); } void lcd_printft(unsigned int x, unsigned int y, unsigned char flash *text) { sprintf(text_buffer,text); lcd_write_zahl(x, y, text_buffer); } void lcd_write_char(unsigned char const data, unsigned char x,unsigned char y, ) { unsigned int address; address= y * 22 + x + 0x1000; out(0x24, address & 0xff,address >> 8); out(0xC0, 0, data-0x20); } void f_UART2_SendText(unsigned char Text[]) // Übergabe Zeiger auf Textarray das { // gesendet werden soll unsigned char ucl_i, ucl_Laenge; ucl_Laenge = strlen(Text); for (ucl_i=0; ucl_i< ucl_Laenge; ucl_i++) { putchar(Text[ucl_i]); // RS232_Port2-Ausgabe } } //Hauptprogramm void main(void) { DDRB = 0xFF; PORTB = 0; DDRD = 0x00; PORTD = 0; PORTC_output(); t6963cinit(); // UART initialization // Communication Parameters: 8 Data, 1 Stop, No Parity // UART Receiver: On // UART Transmitter: On // UART Baud rate: 9600 UCR=0xD8; UBRR=0x33; // Analog Comparator initialization // Analog Comparator: Off // Analog Comparator Input Capture by Timer/Counter 1: Off ACSR=0x80; #asm("sei") while (1) { lcd_printfz(0,1,"Zeichen:%2x",Zeichen); if(tasten() == 1) { lcd_printft(1,3,"A"); putchar(65); } if(tasten() == 2) { lcd_printft(1,3,"B"); putchar(66); } if(Zeichen == 'y') { lcd_printft(1,3,"y"); } }; }