void main(void) { short mx, my, tmx, tmy, ignoreBtn; char stat[14]; // TODO initialise variables with the riht value //mx = -1; //my = -1; //ignoreBtn = 0; lcd_init(); initIO(); adc_init(); lcd_clear(0); drawField(); for (;;) { tmx = (short) (2 - adc_getValue(1) / 255.0 * 2 + 0.5); tmy = (short) (2 - adc_getValue(2) / 255.0 * 2 + 0.5); if (tmy != my || tmx != mx) { drawMarker(mx, my, 0); if (fields[mx][my] == 1) { placePlayerMark(mx, my, 1); } drawMarker(mx = tmx, my = tmy, 1); } if (!BUTTON_RIGHT && !ignoreBtn && !fields[mx][my]) { ignoreBtn = 1; pushes++; placePlayerMark(mx, my, player); if (checkStatus(mx, my)) { lcd_clear(0); sprintf(stat, "Player %u won!", player); lcd_drawString(27, 4, 0, 4, 0, 0, &stat[0], 1, 1); lcd_flush(); break; } if (pushes == 9) { lcd_clear(0); sprintf(stat, "Undecided!"); lcd_drawString(32, 4, 0, 4, 0, 0, &stat[0], 1, 1); lcd_flush(); break; } if (player == 1) { player = 2; } else if (player == 2) { player = 1; } } else if (BUTTON_RIGHT && ignoreBtn) { ignoreBtn = 0; } } }
/* enqueue a command into the buffer */ void lcd_enqueue(int command_type, int value) { if ((buffer_current_type >= 0) && (buffer_current_type != command_type)) lcd_flush(); /* add new item to buffer */ buffer_current_type = command_type; buffer[buffer_current_fill++] = value; /* flush buffer if it's full */ if (buffer_current_fill == BUFFER_MAX_CMD) lcd_flush(); }
/* write a data string to the first display */ void lcd_write(const char *data) { int ctrl = LCD_CTRL_0; while(*data) lcd_enqueue(LCD_DATA | ctrl, *data++); lcd_flush(); }
void main(void) { unsigned char ch, x, y, z; int i = 0; int j = 0; unsigned char mode = 0x00; unsigned char oldMode = 0x00; // init buttons and seven-segment displays initIO(); // init LCD initLCD(); // initialize I/O-ports PDR08 = 0x00; DDR08 = 0x00; PIER08 = 0x24; // SIN0, SIN1 input enable InitUart1(); // initialize UART Puts1("\nUART LCD Bridge\n"); // Output welcome string // reset buffer at startup //lcd_clear(); lcd_splash(); // loading splashscreen lcd_flush(); while (1) { if (SSR1_RDRF != 0) { // Wait for data received ch = RDR1; // Save receive register if ((SSR1 & 0xE0) != 0) { // Check for errors PE, ORE, FRE SCR1_CRE = 1; // Clear error flags } else { switch(mode) { case 0x00: // idle if(ch == 0xAA) { // cmd for setPixel mode if(oldMode == 0xBB || oldMode == 0x00) { lcd_clear(); lcd_flush(); } mode = 0xAA; i=0; } if(ch == 0xBB) { // cmd for framebuffer mode mode = 0xBB; i=0; j=0; } break; case 0xAA: // setPixel mode if (i == 0) { // x coordinate x = ch; i++; } else if (i == 1) { // y coordinate y = ch; i++; } else if (i == 2) { // value (1=black,0="white") z = ch; i = 0; lcd_drawPixelDirect(x, y, z); oldMode = mode; mode = 0x00; } break; case 0xBB: // framebuffer mode lcd_buffer[i][j] = ch; // write current uart buffer content to framebuffer if(j==7) { i++; j=0; } else j++; // print received framebuffer if(i>=128) { lcd_flush(); oldMode = mode; mode = 0x00; } break; } Putch1(ch); // debug output } } } }