00001
00002
00003
00004
00005
00006
00007
00008
00009 #include <avr/io.h>
00010 #include "rprintf.h"
00011 #include <math.h>
00012 #include <avr/interrupt.h>
00013
00014 #define FOSC 16000000// Clock Speed
00015 #define BAUD 57600
00016 #define MYUBRR FOSC/16/BAUD-1
00017
00018 #define EN 0 //PC0
00019 #define RS 1 //PC1, D_I?
00020 #define R_W 2 //PC2
00021 #define RESET 3 //PC3
00022 #define CS1 4 //PC4
00023 #define CS2 5 //PC5
00024
00025 #define BL_EN 2 //PB2
00026
00027 #define X_ENDPOINT 127
00028 #define Y_ENDPOINT 63
00029
00030 #define DISPLAY_DELAY 6
00031
00032
00033
00034
00035
00036 void ioinit(void);
00037 void delay_ms(uint16_t x);
00038 void delay_us(uint8_t x);
00039 void delay(void);
00040 void USART_Init( unsigned int ubrr);
00041 void put_char(char byte);
00042 void demo(void);
00043
00044 void set_data(char data);
00045 void set_x(char x_spot);
00046 void set_page(char page);
00047 void clear_screen(void);
00048 void write_byte(char byte, char side);
00049 char read_byte(char byte, char side);
00050 void display_on(void);
00051 void set_port_out(void);
00052 void set_port_in(void);
00053
00054
00055 void print_char(char S_R, char txt);
00056 void del_char(char endpoint);
00057 void pixel(char S_R, char x, char y);
00058 void line(char S_R, char x1, char y1, char x2, char y2);
00059 void circle(char S_R, int x, int y, int r);
00060 void erase_block(char x1, char y1, char x2, char y2);
00061 void box(char x1, char y1, char x2, char y2);
00062 int rnd(float number);
00063
00064
00065
00066
00067 char x_offset = 0;
00068 char y_offset = 63;
00069
00070 char side_mark = 1;
00071 char page_mark = 0;
00072
00073 unsigned char RX_array[256];
00074 volatile unsigned short RX_in = 0;
00075 unsigned short RX_read = 0;
00076
00077 static char logo[30] = {0x01,0xC0,0x03,0x80,0x03,0x80,0x01,0xD0,
00078 0x01,0xF8,0x0C,0xF8,0x18,0xF8,0x1F,0xF8,
00079 0x1F,0xF8,0x1F,0xF0,0x1F,0xE0,0x1F,0xC0,
00080 0x1C,0x00,0x18,0x00,0x10,0x00};
00081
00082
00083
00084 static char text_array[475] = {0x00,0x00,0x00,0x00,0x00,
00085 0x00,0xF6,0xF6,0x00,0x00,
00086 0x00,0xE0,0x00,0xE0,0x00,
00087 0x28,0xFE,0x28,0xFE,0x28,
00088 0x00,0x64,0xD6,0x54,0x08,
00089 0xC2,0xCC,0x10,0x26,0xC6,
00090 0x4C,0xB2,0x92,0x6C,0x0A,
00091 0x00,0x00,0xE0,0x00,0x00,
00092 0x00,0x38,0x44,0x82,0x00,
00093 0x00,0x82,0x44,0x38,0x00,
00094 0x88,0x50,0xF8,0x50,0x88,
00095 0x08,0x08,0x3E,0x08,0x08,
00096 0x00,0x00,0x05,0x06,0x00,
00097 0x08,0x08,0x08,0x08,0x08,
00098 0x00,0x00,0x06,0x06,0x00,
00099 0x02,0x0C,0x10,0x60,0x80,
00100
00101 0x00,0x42,0xFE,0x02,0x00,
00102 0x42,0x86,0x8A,0x92,0x62,
00103 0x44,0x82,0x92,0x92,0x6C,
00104 0x10,0x30,0x50,0xFE,0x10,
00105 0xE4,0xA2,0xA2,0xA2,0x9C,
00106 0x3C,0x52,0x92,0x92,0x0C,
00107 0x80,0x86,0x98,0xE0,0x80,
00108 0x6C,0x92,0x92,0x92,0x6C,
00109 0x60,0x92,0x92,0x94,0x78,
00110 0x00,0x00,0x36,0x36,0x00,
00111 0x00,0x00,0x35,0x36,0x00,
00112 0x10,0x28,0x44,0x82,0x00,
00113 0x28,0x28,0x28,0x28,0x28,
00114 0x00,0x82,0x44,0x28,0x10,
00115 0x40,0x80,0x8A,0x90,0x60,
00116 0x7C,0x82,0xBA,0xBA,0x62,
00117 0x3E,0x48,0x88,0x48,0x3E,
00118 0xFE,0x92,0x92,0x92,0x6C,
00119 0x7C,0x82,0x82,0x82,0x44,
00120 0xFE,0x82,0x82,0x82,0x7C,
00121 0xFE,0x92,0x92,0x92,0x82,
00122 0xFE,0x90,0x90,0x90,0x80,
00123 0x7C,0x82,0x82,0x8A,0x4E,
00124 0xFE,0x10,0x10,0x10,0xFE,
00125 0x82,0x82,0xFE,0x82,0x82,
00126 0x84,0x82,0xFC,0x80,0x80,
00127 0xFE,0x10,0x28,0x44,0x82,
00128 0xFE,0x02,0x02,0x02,0x02,
00129 0xFE,0x40,0x20,0x40,0xFE,
00130 0xFE,0x60,0x10,0x0C,0xFE,
00131 0x7C,0x82,0x82,0x82,0x7C,
00132 0xFE,0x90,0x90,0x90,0x60,
00133 0x7C,0x82,0x82,0x86,0x7E,
00134 0xFE,0x90,0x98,0x94,0x62,
00135 0x64,0x92,0x92,0x92,0x4C,
00136 0x80,0x80,0xFE,0x80,0x80,
00137 0xFC,0x02,0x02,0x02,0xFC,
00138 0xF8,0x04,0x02,0x04,0xF8,
00139 0xFC,0x02,0x0C,0x02,0xFC,
00140 0xC6,0x28,0x10,0x28,0xC6,
00141 0xC0,0x20,0x1E,0x20,0xC0,
00142 0x86,0x8A,0x92,0xA2,0xC2,
00143 0x00,0x00,0xFE,0x82,0x00,
00144 0x00,0x00,0x00,0x00,0x00,
00145 0x80,0x60,0x10,0x0C,0x02,
00146 0x20,0x40,0x80,0x40,0x20,
00147 0x01,0x01,0x01,0x01,0x01,
00148 0x80,0x40,0x20,0x00,0x00,
00149 0x04,0x2A,0x2A,0x2A,0x1E,
00150 0xFE,0x12,0x22,0x22,0x1C,
00151 0x1C,0x22,0x22,0x22,0x14,
00152 0x1C,0x22,0x22,0x12,0xFE,
00153 0x1C,0x2A,0x2A,0x2A,0x18,
00154 0x10,0x7E,0x90,0x80,0x40,
00155 0x18,0x25,0x25,0x25,0x1E,
00156 0xFE,0x10,0x10,0x10,0x0E,
00157 0x00,0x12,0x5E,0x02,0x00,
00158 0x02,0x01,0x01,0x11,0x5E,
00159 0xFE,0x08,0x08,0x14,0x22,
00160 0x00,0x82,0xFE,0x02,0x00,
00161 0x3E,0x20,0x1C,0x20,0x1E,
00162 0x3E,0x20,0x20,0x20,0x1E,
00163 0x1C,0x22,0x22,0x22,0x1C,
00164 0x3F,0x24,0x24,0x24,0x18,
00165 0x18,0x24,0x24,0x3F,0x01,
00166 0x3E,0x10,0x20,0x20,0x10,
00167 0x12,0x2A,0x2A,0x2A,0x04,
00168 0x00,0x10,0x3C,0x12,0x04,
00169 0x3C,0x02,0x02,0x02,0x3E,
00170 0x30,0x0C,0x02,0x0C,0x30,
00171 0x38,0x06,0x18,0x06,0x38,
00172 0x22,0x14,0x08,0x14,0x22,
00173 0x38,0x05,0x05,0x05,0x3E,
00174 0x22,0x26,0x2A,0x32,0x22,
00175 0x00,0x10,0x6C,0x82,0x82,
00176
00177 0x04,0x02,0xFF,0x02,0x04,
00178 0x82,0x82,0x6C,0x10,0x00,
00179 0x08,0x10,0x18,0x08,0x10};
00180
00181
00182
00183 ISR (SIG_UART_RECV)
00184 {
00185 cli();
00186 RX_array[RX_in] = UDR;
00187
00188 RX_in++;
00189
00190 if (RX_in >= 256) RX_in = 0;
00191
00192 sei();
00193
00194 }
00195
00196
00197 int main (void)
00198 {
00199 char x, y;
00200
00201 ioinit();
00202 USART_Init( MYUBRR);
00203 rprintf_devopen(put_char);
00204
00205
00206
00207
00208
00209
00210
00211
00212
00213
00214
00215
00216
00217
00218
00219
00220
00221
00222
00223
00224
00225
00226
00227
00228
00229
00230
00231
00232
00233
00234
00235
00236 PORTC &= ~(1 << RESET);
00237 delay_ms(50);
00238 PORTC |= (1 << RESET);
00239 delay_ms(500);
00240
00241 clear_screen();
00242
00243 set_page(0);
00244 set_x(0);
00245
00246 display_on();
00247
00248
00249
00250
00251 PORTC &= ~((1 << EN) | (1 << R_W) | (1 << RS));
00252 set_port_out();
00253
00254 set_data(0xC0);
00255 delay_us(4);
00256 PORTC |= (1 << EN);
00257 delay_us(4);
00258 PORTC &= ~(1 << EN);
00259 delay_us(4);
00260 PORTC |= ((1 << EN) | (1 << R_W) | (1 << RS));
00261
00262 set_port_in();
00263 delay_us(4);
00264
00265
00266 x_offset = 0;
00267
00268 set_page(0);
00269
00270
00271 PORTB &= (~(1<<BL_EN));
00272
00273
00274
00275
00276 while(1)
00277 {
00278 if(RX_in != RX_read)
00279 {
00280 x = RX_array[RX_read];
00281 RX_read++;
00282 if(RX_read >= 256) RX_read = 0;
00283
00284
00285
00286
00287 if(x == 8) del_char(0);
00288
00289
00290 else if (x == 124)
00291 {
00292
00293 while(RX_in == RX_read);
00294
00295
00296 if(RX_array[RX_read] == 0)
00297 {
00298 clear_screen();
00299 RX_read++;
00300 if(RX_read >= 256) RX_read = 0;
00301 }
00302
00303
00304
00305 else if(RX_array[RX_read] == 2)
00306 {
00307 y = PINB;
00308 if (y & (1<<BL_EN)) PORTB &= (~(1<<BL_EN));
00309 else PORTB |= (1<<BL_EN);
00310 RX_read++;
00311 }
00312
00313
00314 else if(RX_array[RX_read] == 4)
00315 {
00316 RX_in = 0, RX_read = 0;
00317 demo();
00318 clear_screen();
00319 RX_in = 0;
00320 }
00321
00322 else
00323 {
00324
00325 if((RX_array[RX_read] == 24) | (RX_array[RX_read] == 25))
00326 {
00327 RX_read++;
00328 if(RX_read >= 256) RX_read = 0;
00329 while(RX_in == RX_read);
00330 if (RX_array[RX_read-1] == 24) x_offset = RX_array[RX_read];
00331 else if (RX_array[RX_read-1] == 25) y_offset = RX_array[RX_read];
00332
00333 RX_read++;
00334 if(RX_read >= 256) RX_read = 0;
00335
00336 if (x_offset > 127) x_offset = 127;
00337 if (y_offset > 63) y_offset = 63;
00338
00339 }
00340
00341
00342 if (RX_array[RX_read] == 16)
00343 {
00344
00345 for (y = 0; y < 3; y++)
00346 {
00347 RX_read++;
00348 if(RX_read >= 256) RX_read = 0;
00349 while(RX_in == RX_read);
00350 }
00351
00352 pixel(RX_array[RX_read], RX_array[RX_read-2], RX_array[RX_read-1]);
00353
00354 RX_read++;
00355 if(RX_read >= 256) RX_read = 0;
00356
00357 }
00358
00359
00360 if(RX_array[RX_read] == 3)
00361 {
00362
00363 for (y = 0; y < 4; y++)
00364 {
00365 RX_read++;
00366 if(RX_read >= 256) RX_read = 0;
00367 while(RX_in == RX_read);
00368 }
00369
00370 circle(RX_array[RX_read], RX_array[RX_read-3], RX_array[RX_read-2], RX_array[RX_read-1]);
00371
00372 RX_read++;
00373 if(RX_read >= 256) RX_read = 0;
00374 }
00375
00376
00377
00378 if(RX_array[RX_read] == 5)
00379 {
00380
00381 for (y = 0; y < 4; y++)
00382 {
00383 RX_read++;
00384 if(RX_read >= 256) RX_read = 0;
00385 while(RX_in == RX_read);
00386 }
00387
00388 erase_block(RX_array[RX_read-3], RX_array[RX_read-2], RX_array[RX_read-1], RX_array[RX_read]);
00389
00390 RX_read++;
00391 if(RX_read >= 256) RX_read = 0;
00392 }
00393
00394
00395
00396 if(RX_array[RX_read] == 15)
00397 {
00398
00399 for (y = 0; y < 4; y++)
00400 {
00401 RX_read++;
00402 if(RX_read >= 256) RX_read = 0;
00403 while(RX_in == RX_read);
00404 }
00405
00406 box(RX_array[RX_read-3], RX_array[RX_read-2], RX_array[RX_read-1], RX_array[RX_read]);
00407
00408 RX_read++;
00409 if(RX_read >= 256) RX_read = 0;
00410 }
00411
00412
00413
00414 else if (RX_array[RX_read] == 12)
00415 {
00416
00417 for (y = 0; y < 5; y++)
00418 {
00419 RX_read++;
00420 if(RX_read >= 256) RX_read = 0;
00421 while(RX_in == RX_read);
00422 }
00423
00424 line(RX_array[RX_read], RX_array[RX_read-4], RX_array[RX_read-3], RX_array[RX_read-2], RX_array[RX_read+-1]);
00425 RX_read++;
00426 if(RX_read >= 256) RX_read = 0;
00427 }
00428
00429
00430 }
00431
00432 }
00433
00434
00435 else
00436 {
00437
00438 del_char(1);
00439
00440 print_char(1, x);
00441
00442 }
00443
00444
00445
00446
00447
00448
00449 }
00450
00451 }
00452
00453 }
00454
00455 void ioinit (void)
00456 {
00457
00458
00459
00460
00461 PORTB |= (1<<BL_EN);
00462 DDRB |= (1<<BL_EN);
00463
00464 DDRC = ((1<<EN) | (1<<RS) | (1<<R_W) | (1<<RESET) | (1<<CS1) | (1<<CS2));
00465 PORTC = ((1<<EN) | (1<<RS) | (1<<R_W) | (1<<RESET) | (1<<CS1) | (1<<CS2));
00466
00467
00468
00469
00470 TCCR2 = (1<<CS21);
00471
00472 }
00473
00474
00475
00476 void delay_us(uint8_t x)
00477 {
00478 char temp;
00479
00480 if (x == 0) temp = 1;
00481 else temp = x;
00482
00483 TIFR |= 0x40;
00484
00485 TCNT2 = 256 - temp;
00486
00487
00488 while(!(TIFR & 0x40));
00489
00490 if (x == 0) return;
00491
00492
00493
00494 TIFR |= 0x40;
00495
00496 TCNT2 = 256 - temp;
00497
00498
00499 while(!(TIFR & 0x40));
00500
00501 }
00502
00503
00504 void delay_ms(uint16_t x)
00505 {
00506 for (; x > 0 ; x--)
00507 {
00508 delay_us(250);
00509 delay_us(250);
00510 delay_us(250);
00511 delay_us(250);
00512 }
00513
00514 }
00515
00516
00517 void USART_Init( unsigned int ubrr)
00518 {
00519
00520 UBRRH = (unsigned char)(ubrr>>8);
00521 UBRRL = (unsigned char)ubrr;
00522
00523
00524 UCSRB = (1<<RXCIE)|(1<<RXEN)|(1<<TXEN);
00525
00526
00527 UCSRC = (1<<URSEL)|(1<<UCSZ0)|(1<<UCSZ1);
00528 sei();
00529 }
00530
00531 void put_char(char byte)
00532 {
00533
00534 while ( !( UCSRA & (1<<UDRE)) );
00535
00536 UDR = byte;
00537 }
00538
00539
00540
00541 void delay(void)
00542 {
00543 char y;
00544
00545 for(y = 0; y < 20; y++)
00546 {
00547 asm volatile ("nop");
00548
00549 }
00550
00551
00552
00553
00554
00555
00556
00557
00558
00559 }
00560
00561
00562 void set_data(char data)
00563 {
00564
00565
00566
00567
00568 PORTB &= 0xFC;
00569
00570
00571
00572
00573
00574
00575
00576
00577
00578 PORTD &= 0x03;
00579
00580 PORTB |= (data & 0x03);
00581 PORTD |= (data & 0xFC);
00582
00583 }
00584
00585 void clear_screen(void)
00586 {
00587 char x, y;
00588 set_port_out();
00589
00590 delay_us(DISPLAY_DELAY);
00591
00592 for (x = 0; x < 8; x++)
00593 {
00594
00595
00596 PORTC &= ~((1 << EN) | (1 << R_W) | (1 << RS));
00597
00598 set_data(0xB8 | x);
00599
00600 delay_us(DISPLAY_DELAY);
00601 PORTC |= (1 << EN);
00602
00603 delay_us(DISPLAY_DELAY);
00604 PORTC &= ~(1 << EN);
00605
00606 delay_us(DISPLAY_DELAY);
00607 PORTC |= ((1 << EN) | (1 << R_W) |(1 << RS));
00608
00609
00610 delay_us(DISPLAY_DELAY);
00611
00612
00613
00614 PORTC &= ~((1 << EN) | (1 << R_W) | (1 << RS));
00615
00616 set_data(0x40);
00617
00618 delay_us(DISPLAY_DELAY);
00619 PORTC |= (1 << EN);
00620
00621 delay_us(DISPLAY_DELAY);
00622 PORTC &= ~(1 << EN);
00623
00624 delay_us(DISPLAY_DELAY);
00625 PORTC |= ((1 << EN) | (1 << R_W) | (1 << RS));
00626
00627 set_data(0);
00628
00629 for (y = 0; y < 64; y++)
00630 {
00631
00632 delay_us(DISPLAY_DELAY);
00633
00634
00635 PORTC &= ~((1 << EN) | (1 << R_W) | (1 << CS1));
00636
00637 delay_us(DISPLAY_DELAY);
00638 PORTC |= (1 << EN);
00639
00640 delay_us(DISPLAY_DELAY);
00641 PORTC &= ~(1 << EN);
00642
00643 delay_us(DISPLAY_DELAY);
00644 PORTC |= ((1 << EN) | (1 << R_W) | (1 << CS1));
00645
00646
00647 delay_us(DISPLAY_DELAY);
00648
00649
00650 PORTC &= ~((1 << EN) | (1 << R_W) | (1 << CS2));
00651
00652 delay_us(DISPLAY_DELAY);
00653 PORTC |= (1 << EN);
00654
00655 delay_us(DISPLAY_DELAY);
00656 PORTC &= ~(1 << EN);
00657
00658 delay_us(DISPLAY_DELAY);
00659 PORTC |= ((1 << EN) | (1 << R_W) | (1 << CS2));
00660 }
00661
00662 }
00663
00664 set_port_in();
00665
00666 }
00667
00668
00669 void set_x(char x_spot)
00670 {
00671
00672
00673
00674
00675
00676
00677 set_port_out();
00678
00679 if (x_spot == 0) x_spot = 63;
00680 else x_spot--;
00681
00682 PORTC &= ~((1 << EN) | (1 << R_W) | (1 << RS));
00683
00684 set_data(0x40 | x_spot);
00685
00686 delay_us(DISPLAY_DELAY);
00687 PORTC |= (1 << EN);
00688
00689 delay_us(DISPLAY_DELAY);
00690 PORTC &= ~(1 << EN);
00691
00692 delay_us(DISPLAY_DELAY);
00693 PORTC |= ((1 << EN) | (1 << R_W) | (1 << RS));
00694
00695 set_port_in();
00696 delay_us(DISPLAY_DELAY);
00697
00698 }
00699
00700
00701
00702 void print_char(char S_R, char txt)
00703 {
00704 short text_array_offset = (txt - 32)*5, j;
00705 char x, k;
00706
00707
00708 for (j = text_array_offset; j < text_array_offset+5; j++)
00709 {
00710
00711
00712 k = text_array[j];
00713
00714 for (x = 0; x < 8; x++)
00715 {
00716 if(k & 0x80) pixel(S_R, x_offset, y_offset - x);
00717 k <<= 1;
00718
00719 }
00720
00721
00722
00723
00724 x_offset++;
00725
00726
00727 }
00728
00729 x_offset++;
00730
00731 if ((x_offset + 6) > X_ENDPOINT)
00732 {
00733 x_offset = 0;
00734 if (y_offset <= 7) y_offset = Y_ENDPOINT;
00735 else y_offset -= 8;
00736
00737 }
00738
00739 }
00740
00741
00742
00743 void set_page(char page)
00744 {
00745
00746 PORTC &= ~((1 << EN) | (1 << R_W) | (1 << RS));
00747
00748 set_port_out();
00749
00750 set_data(0xB8 | page);
00751
00752 delay_us(DISPLAY_DELAY);
00753 PORTC |= (1 << EN);
00754
00755 delay_us(DISPLAY_DELAY);
00756 PORTC &= ~(1 << EN);
00757
00758 delay_us(DISPLAY_DELAY);
00759 PORTC |= ((1 << EN) | (1 << R_W) |(1 << RS));
00760
00761 set_port_in();
00762
00763
00764 delay_us(DISPLAY_DELAY);
00765 }
00766
00767
00768 void write_byte(char byte, char side)
00769 {
00770 PORTC |= (1 << RS);
00771
00772 set_port_out();
00773
00774 set_data(byte);
00775
00776
00777 delay_us(DISPLAY_DELAY);
00778
00779
00780 if (side == 1) PORTC &= ~((1 << EN) | (1 << R_W) | (1 << CS1));
00781 else if (side == 2) PORTC &= ~((1 << EN) | (1 << R_W) | (1 << CS2));
00782
00783
00784
00785
00786
00787 delay_us(DISPLAY_DELAY);
00788 PORTC |= (1 << EN);
00789
00790 delay_us(DISPLAY_DELAY);
00791 PORTC &= ~(1 << EN);
00792
00793 delay_us(DISPLAY_DELAY);
00794 PORTC |= ((1 << EN) | (1 << R_W) | (1 << CS1) | (1 << CS2));
00795 delay_us(DISPLAY_DELAY);
00796
00797 set_port_in();
00798 set_data(0xFF);
00799
00800 }
00801
00802
00803
00804 void display_on(void)
00805 {
00806 set_port_out();
00807 set_data(0x3F);
00808 PORTC &= ~((1 << EN) | (1 << R_W) | (1 << RS));
00809
00810 delay_us(DISPLAY_DELAY);
00811 PORTC |= (1 << EN);
00812
00813 delay_us(DISPLAY_DELAY);
00814 PORTC &= ~(1 << EN);
00815 PORTC |= ((1 << EN) | (1 << R_W) | (1 << RS));
00816
00817 set_port_in();
00818
00819 }
00820
00821
00822 void pixel(char S_R, char x, char y)
00823 {
00824 static char temp_page, temp_side, temp_x = 0, temp_data1 = 0, temp_data2 = 0;
00825
00826 if ((x > X_ENDPOINT) | (y > Y_ENDPOINT)) return;
00827
00828
00829 if (x >= 64) temp_side = 2, temp_x = x - 64;
00830 else temp_side = 1, temp_x = x;
00831
00832 temp_page = 7 - (y >> 3);
00833
00834
00835 temp_data1 = (1 << (7 - (y - ((7 - temp_page) * 8))));
00836 if (S_R == 0) temp_data1 = ~temp_data1;
00837
00838
00839 set_page(temp_page);
00840 set_x(temp_x);
00841
00842
00843
00844 temp_data2 = read_byte(temp_x, temp_side);
00845
00846 if (S_R == 1) temp_data1 |= temp_data2;
00847 else if (S_R == 0) temp_data1 &= temp_data2;
00848 set_x(temp_x);
00849
00850 write_byte(temp_data1, temp_side);
00851
00852
00853
00854 }
00855
00856
00857
00858
00859
00860
00861
00862
00863
00864
00865
00866
00867
00868
00869
00870
00871
00872
00873
00874
00875
00876
00877 void line(char S_R, char x1, char y1, char x2, char y2)
00878 {
00879 float m, q;
00880 int x_dif, y_dif;
00881 int a, b, c;
00882
00883 if ((x1 > X_ENDPOINT) | (x2 > X_ENDPOINT)) return;
00884
00885 if ((y1 > Y_ENDPOINT) | (y2 > Y_ENDPOINT)) return;
00886
00887
00888 x_dif = x2 - x1;
00889 y_dif = y2 - y1;
00890 if (y_dif < 0) y_dif *= (-1);
00891
00892
00893 m = (float)(y2 - y1) / (float)(x2 - x1);
00894
00895 b = y1-(m*x1);
00896
00897 if(x_dif >= y_dif)
00898 {
00899 for (a = x1; a <= x2; a++)
00900 {
00901 pixel(S_R, (char)a, (char)((m*a)+b));
00902
00903 }
00904 }
00905
00906 else
00907 {
00908 if (y2 > y1)
00909 {
00910 for (a = y1; a <= y2; a++)
00911 {
00912 if (x_dif == 0) c = x1;
00913 else
00914 {
00915 q = (((float)(a-b))/m);
00916 c = rnd(q);
00917 }
00918
00919 pixel(S_R, (char)c, (char)a);
00920
00921 }
00922 }
00923
00924 else if (y1 > y2)
00925 {
00926 for (a = y1; a >= y2; a--)
00927 {
00928 if (x_dif == 0) c = x1;
00929 else
00930 {
00931 q = (((float)(a-b))/m);
00932 c = rnd(q);
00933 }
00934
00935 pixel(S_R, (char)c, (char)a);
00936
00937 }
00938 }
00939 }
00940
00941 }
00942
00943
00944
00945 char read_byte(char byte, char side)
00946 {
00947 char data1 = 0, data2 = 0;
00948
00949 if (byte == 0) byte = 63;
00950 else byte--;
00951
00952 set_x(byte);
00953
00954 PORTC |= ((1 << RESET) | (1 << EN) | (1 << R_W) | (1 << CS1) | (1 << CS2) | (1 << RS));
00955
00956
00957
00958
00959 set_port_in();
00960
00961 delay_us(DISPLAY_DELAY);
00962
00963 if (side == 1) PORTC &= ~((1 << EN) | (1 << CS1));
00964 else if (side == 2) PORTC &= ~((1 << EN) | (1 << CS2));
00965
00966 delay_us(DISPLAY_DELAY);
00967 PORTC |= (1 << EN);
00968
00969 delay_us(DISPLAY_DELAY);
00970
00971 PORTC &= ~(1 << EN);
00972
00973 delay_us(DISPLAY_DELAY);
00974
00975 PORTC |= ((1 << RESET) | (1 << EN) | (1 << R_W) | (1 << CS1) | (1 << CS2) | (1 << RS));
00976
00977 delay_us(DISPLAY_DELAY);
00978
00979 if (side == 1) PORTC &= ~((1 << EN) | (1 << CS1));
00980 else if (side == 2) PORTC &= ~((1 << EN) | (1 << CS2));
00981
00982 delay_us(DISPLAY_DELAY);
00983 PORTC |= (1 << EN);
00984
00985 delay_us(DISPLAY_DELAY);
00986 data1 = PINB;
00987 data1 &= 0x03;
00988
00989 data2 = PIND;
00990 data2 &= 0xFC;
00991
00992 data1 |= data2;
00993
00994 PORTC &= ~(1 << EN);
00995
00996 PORTC |= ((1 << RESET) | (1 << EN) | (1 << R_W) | (1 << CS1) | (1 << CS2) | (1 << RS));
00997
00998
00999
01000
01001 delay_us(DISPLAY_DELAY);
01002
01003 return data1;
01004
01005 }
01006
01007 int rnd(float number)
01008 {
01009 int a;
01010 float b;
01011
01012 a = number / 1;
01013 b = number - a;
01014
01015 if (b >= 0.5) a++;
01016
01017 return a;
01018
01019 }
01020
01021
01022 void circle(char S_R, int x, int y, int r)
01023 {
01024 int x1 = 0, x2 = 0;
01025 int x_line = 0, y_line = 0;
01026 int temp_y;
01027 int temp_x;
01028
01029
01030 x1 = x - r;
01031 x2 = x + r;
01032
01033 for (temp_x = x1; temp_x <= x2; temp_x++)
01034 {
01035 temp_y = ((sqrt((r*r) - ((temp_x - x)*(temp_x - x)))) - y);
01036
01037 temp_y *= (-1);
01038
01039
01040
01041
01042
01043
01044
01045
01046 if (temp_x > x1)
01047 {
01048 line(S_R, (char)x_line, (char)y_line, (char)temp_x, (char)temp_y);
01049 line(S_R, (char)x_line, (char)(2*y - y_line), (char)temp_x, (char)(2*y - temp_y));
01050 }
01051
01052 else
01053 {
01054 pixel(S_R, (char)temp_x, (char)temp_y);
01055 pixel(S_R, (char)temp_x, (char)(y + y - temp_y));
01056 }
01057
01058 x_line = temp_x;
01059 y_line = temp_y;
01060
01061
01062
01063
01064 }
01065
01066
01067 }
01068
01069
01070 void demo(void)
01071 {
01072 char x, y, temp;
01073 int q = 0;
01074
01075 while(1)
01076 {
01077
01078 x_offset = 0;
01079 y_offset = 63;
01080
01081 for (y = 0; y < 5; y++)
01082 {
01083 for (x = 32; x < 123; x++)
01084 {
01085 del_char(1);
01086 print_char(1, x);
01087 if (RX_in > 0) return;
01088 }
01089 }
01090
01091 clear_screen();
01092
01093 for (y = 0; y < 5; y++)
01094 {
01095 for (x = 32; x < 123; x++)
01096 {
01097
01098 y_offset -= 3;
01099 if (y_offset <= 8) y_offset = 63;
01100 del_char(1);
01101 print_char(1, x);
01102 if (RX_in > 0) return;
01103 }
01104 }
01105
01106 clear_screen();
01107
01108
01109 for (x = 5; x < 60; x += 5)
01110 {
01111 circle(1,64,32,x);
01112 if (RX_in > 0) return;
01113 }
01114
01115
01116 y = Y_ENDPOINT;
01117
01118 for (x = 0; x < X_ENDPOINT; x += 8)
01119 {
01120 line(1,0,y,x,0);
01121 y -= 8;
01122 }
01123
01124 y = 0;
01125
01126 for (x = 0; x < X_ENDPOINT; x += 8)
01127 {
01128 line(1,x,0,X_ENDPOINT,y);
01129 y += 8;
01130 }
01131
01132 y = Y_ENDPOINT;
01133
01134 for (x = 0; x < X_ENDPOINT; x += 8)
01135 {
01136 line(1,x,Y_ENDPOINT,X_ENDPOINT,y);
01137 y -= 8;
01138 }
01139
01140 y = 0;
01141
01142 for (x = 0; x < X_ENDPOINT; x += 8)
01143 {
01144 line(1,0,y,x,Y_ENDPOINT);
01145 y += 8;
01146 }
01147
01148
01149 for (x = 5; x < 60; x += 5)
01150 {
01151 circle(0,64,32,x);
01152 if (RX_in > 0) return;
01153 }
01154
01155
01156 y = Y_ENDPOINT;
01157
01158 for (x = 0; x < X_ENDPOINT; x += 8)
01159 {
01160 line(0,0,y,x,0);
01161 y -= 8;
01162 }
01163
01164 y = 0;
01165
01166 for (x = 0; x < X_ENDPOINT; x += 8)
01167 {
01168 line(0,x,0,X_ENDPOINT,y);
01169 y += 8;
01170 }
01171
01172 y = Y_ENDPOINT;
01173
01174 for (x = 0; x < X_ENDPOINT; x += 8)
01175 {
01176 line(0,x,Y_ENDPOINT,X_ENDPOINT,y);
01177 y -= 8;
01178 }
01179
01180 y = 0;
01181
01182 for (x = 0; x < X_ENDPOINT; x += 8)
01183 {
01184 line(0,0,y,x,Y_ENDPOINT);
01185 y += 8;
01186 }
01187
01188 if (RX_in > 0) return;
01189
01190
01191 y = 47;
01192 for (x = 0; x <= 110; x += 10)
01193 {
01194 erase_block(x, y, x+16, y+16);
01195 box(x, y, x+16, y+16);
01196 y -= 4;
01197 }
01198
01199
01200
01201 y = 18;
01202
01203 q = 0;
01204 while(q < 30)
01205 {
01206 temp = logo[q];
01207 for (x = 110; x < 118; x++)
01208 {
01209 if (temp & 0x80) pixel(1,x,y);
01210
01211 temp <<= 1;
01212 }
01213 q++;
01214 temp = logo[q];
01215 for (x = 118; x < 126; x++)
01216 {
01217 if (temp & 0x80) pixel(1,x,y);
01218
01219 temp <<= 1;
01220 }
01221 y--;
01222 q++;
01223 }
01224
01225 delay_ms(3000);
01226 clear_screen();
01227 }
01228
01229
01230 }
01231
01232
01233
01234
01235 void del_char(char endpoint)
01236 {
01237 char a, y;
01238
01239 if (endpoint == 0)
01240 {
01241 if (x_offset <= 5)
01242 {
01243 x_offset += 120;
01244 y_offset += 8;
01245
01246 if (y_offset > 63) y_offset -= 64;
01247
01248 }
01249
01250 else x_offset -= 6;
01251 }
01252
01253
01254
01255
01256 for (a = x_offset; a < x_offset + 6; a++)
01257 {
01258 for (y = y_offset - 7; y <= y_offset; y++)
01259 {
01260 pixel(0, a, y);
01261
01262 }
01263 }
01264
01265 pixel(0, 0, 0);
01266
01267 }
01268
01269 void erase_block(char x1, char y1, char x2, char y2)
01270 {
01271 static char temp_x = 0, temp_y = 0;
01272
01273 for (temp_y = y2; temp_y >= y1; temp_y--)
01274 {
01275 for (temp_x = x1; temp_x <= x2; temp_x++)
01276 {
01277 pixel(0, temp_x, temp_y);
01278
01279
01280
01281
01282
01283 }
01284 }
01285
01286
01287
01288 }
01289
01290 void box(char x1, char y1, char x2, char y2)
01291 {
01292
01293
01294 line(1, x1, y1, x1, y2);
01295 line(1, x1, y1, x2, y1);
01296 line(1, x2, y1, x2, y2);
01297 line(1, x1, y2, x2, y2);
01298
01299 }
01300
01301
01302 void set_port_out(void)
01303 {
01304 DDRB = 0x07;
01305 DDRD |= 0xFC;
01306 }
01307
01308
01309 void set_port_in(void)
01310 {
01311 DDRB = 0x04;
01312 DDRD &= 0x03;
01313 }
01314
01315
01316
01317
01318