00001
00002
00003
00004
00005
00006
00007
00008 #include <avr/io.h>
00009 #include <stdlib.h>
00010 #include <stdio.h>
00011 #include "rprintf.h"
00012 #include <string.h>
00013 #include <math.h>
00014 #include <avr/interrupt.h>
00015
00016
00017 #define FOSC 16000000// Clock Speed
00018
00019
00020
00021
00022 #define EN 0 //PC0
00023 #define RS 1 //PC1, D_I?
00024 #define R_W 2 //PC2
00025 #define RESET 3 //PC3
00026 #define CS1 4 //PC4
00027 #define CS2 5 //PC5
00028
00029
00030 #define WR 0 //PC0
00031 #define RD 1 //PC1
00032 #define CE 2 //PC2
00033 #define CD 3 //PC3
00034 #define HALT 4 //PC4
00035 #define RST 5 //PC5
00036
00037 #define BL_EN 2 //PB2
00038
00039 #define BPS 0
00040 #define BACKLIGHT 1
00041 #define SPLASH 2
00042 #define REV 3
00043
00044 #define BAUD 6
00045 #define BUFFER 416
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058 void EEPROM_write(unsigned int uiAddress, unsigned char ucData);
00059 unsigned char EEPROM_read(unsigned int uiAddress);
00060
00061 void ioinit(void);
00062 void delay_ms(uint16_t x);
00063 void delay_us(uint8_t x);
00064 void delay(void);
00065 void USART_Init( unsigned int ubrr);
00066 void put_char(char byte);
00067
00068 void set_data(char data);
00069 void set_x(char x_spot);
00070 void set_page(char page);
00071 void clear_screen(void);
00072 void write_byte(char byte, char side);
00073 char read_byte(char byte, char side);
00074 void display_on(void);
00075 void set_backlight(unsigned char dutycycle);
00076
00077
00078 char read(char D_S);
00079 void write(char D_C, char byte);
00080 void display_init(void);
00081
00082
00083 void set_baud(char b);
00084 void print_char(char S_R, char txt);
00085 void print_string(char S_R, char str[]);
00086 void print_dec(char S_R,int number);
00087
00088 void del_char(char endpoint);
00089 void pixel(char S_R, char x, char y);
00090 void pixel_h(char S_R, char x, char y);
00091
00092 void line(char S_R, char x1, char y1, char x2, char y2);
00093 int rnd(float number);
00094 void circle(char S_R, int x, int y, int r);
00095 void thick_circle(char S_R, int x, int y, int r,int thickness);
00096
00097 void demo(void);
00098 void erase_block(char x1, char y1, char x2, char y2);
00099 void box(char x1, char y1, char x2, char y2);
00100 void solid_box(char x1, char y1, char x2, char y2);
00101 void bar(char x1, char y1, char width, char length,char value,char v_h);
00102
00103
00104 void ilab_logo(void);
00105 void small_ilab_logo(void);
00106 void motor_screen(void);
00107 void bar_move(void);
00108 void motor_value(int speed,int turn,int cap,int mode,int estop);
00109
00110
00111 char x_offset = 0;
00112 char y_offset = 63;
00113 char side_mark = 1;
00114 char page_mark = 0;
00115 char baud_rate = BAUD;
00116 char reverse = 0;
00117 unsigned char display = 0;
00118 unsigned char RX_array[BUFFER];
00119 volatile unsigned short RX_in = 0;
00120 unsigned short RX_read = 0;
00121 unsigned char BL_dutycycle = 100;
00122 unsigned char splash_screen = 1;
00123
00124
00125
00126
00127
00128
00129
00130
00131 static char logo[30] ={
00132 0b00000111,0b11100000,
00133 0b00001000,0b00010000,
00134 0b00110000,0b00001100,
00135 0b00100100,0b00000100,
00136 0b01010100,0b00010010,
00137 0b10101100,0b00010001,
00138 0b10010100,0b11011001,
00139 0b10010101,0b00110101,
00140 0b10010101,0b00110101,
00141 0b10010110,0b11011001,
00142 0b01000000,0b00000010,
00143 0b00100000,0b00000100,
00144 0b00110000,0b00001100,
00145 0b00001000,0b00010000,
00146 0b00000111,0b11100000
00147
00148
00149
00150
00151
00152
00153
00154
00155
00156
00157
00158
00159
00160
00161 };
00162
00163
00164
00165
00166
00167 static char text_array[475] = {0x00,0x00,0x00,0x00,0x00,
00168 0x00,0xF6,0xF6,0x00,0x00,
00169 0x00,0xE0,0x00,0xE0,0x00,
00170 0x28,0xFE,0x28,0xFE,0x28,
00171 0x00,0x64,0xD6,0x54,0x08,
00172 0xC2,0xCC,0x10,0x26,0xC6,
00173 0x4C,0xB2,0x92,0x6C,0x0A,
00174 0x00,0x00,0xE0,0x00,0x00,
00175 0x00,0x38,0x44,0x82,0x00,
00176 0x00,0x82,0x44,0x38,0x00,
00177 0x88,0x50,0xF8,0x50,0x88,
00178 0x08,0x08,0x3E,0x08,0x08,
00179 0x00,0x00,0x05,0x06,0x00,
00180 0x08,0x08,0x08,0x08,0x08,
00181 0x00,0x00,0x06,0x06,0x00,
00182 0x02,0x0C,0x10,0x60,0x80,
00183
00184 0x00,0x42,0xFE,0x02,0x00,
00185 0x42,0x86,0x8A,0x92,0x62,
00186 0x44,0x82,0x92,0x92,0x6C,
00187 0x10,0x30,0x50,0xFE,0x10,
00188 0xE4,0xA2,0xA2,0xA2,0x9C,
00189 0x3C,0x52,0x92,0x92,0x0C,
00190 0x80,0x86,0x98,0xE0,0x80,
00191 0x6C,0x92,0x92,0x92,0x6C,
00192 0x60,0x92,0x92,0x94,0x78,
00193 0x00,0x00,0x36,0x36,0x00,
00194 0x00,0x00,0x35,0x36,0x00,
00195 0x10,0x28,0x44,0x82,0x00,
00196 0x28,0x28,0x28,0x28,0x28,
00197 0x00,0x82,0x44,0x28,0x10,
00198 0x40,0x80,0x8A,0x90,0x60,
00199 0x7C,0x82,0xBA,0xBA,0x62,
00200 0x3E,0x48,0x88,0x48,0x3E,
00201 0xFE,0x92,0x92,0x92,0x6C,
00202 0x7C,0x82,0x82,0x82,0x44,
00203 0xFE,0x82,0x82,0x82,0x7C,
00204 0xFE,0x92,0x92,0x92,0x82,
00205 0xFE,0x90,0x90,0x90,0x80,
00206 0x7C,0x82,0x82,0x8A,0x4E,
00207 0xFE,0x10,0x10,0x10,0xFE,
00208 0x82,0x82,0xFE,0x82,0x82,
00209 0x84,0x82,0xFC,0x80,0x80,
00210 0xFE,0x10,0x28,0x44,0x82,
00211 0xFE,0x02,0x02,0x02,0x02,
00212 0xFE,0x40,0x20,0x40,0xFE,
00213 0xFE,0x60,0x10,0x0C,0xFE,
00214 0x7C,0x82,0x82,0x82,0x7C,
00215 0xFE,0x90,0x90,0x90,0x60,
00216 0x7C,0x82,0x82,0x86,0x7E,
00217 0xFE,0x90,0x98,0x94,0x62,
00218 0x64,0x92,0x92,0x92,0x4C,
00219 0x80,0x80,0xFE,0x80,0x80,
00220 0xFC,0x02,0x02,0x02,0xFC,
00221 0xF8,0x04,0x02,0x04,0xF8,
00222 0xFC,0x02,0x0C,0x02,0xFC,
00223 0xC6,0x28,0x10,0x28,0xC6,
00224 0xC0,0x20,0x1E,0x20,0xC0,
00225 0x86,0x8A,0x92,0xA2,0xC2,
00226 0x00,0x00,0xFE,0x82,0x00,
00227 0x00,0x00,0x00,0x00,0x00,
00228 0x80,0x60,0x10,0x0C,0x02,
00229 0x20,0x40,0x80,0x40,0x20,
00230 0x01,0x01,0x01,0x01,0x01,
00231 0x80,0x40,0x20,0x00,0x00,
00232 0x04,0x2A,0x2A,0x2A,0x1E,
00233 0xFE,0x12,0x22,0x22,0x1C,
00234 0x1C,0x22,0x22,0x22,0x14,
00235 0x1C,0x22,0x22,0x12,0xFE,
00236 0x1C,0x2A,0x2A,0x2A,0x18,
00237 0x10,0x7E,0x90,0x80,0x40,
00238 0x18,0x25,0x25,0x25,0x1E,
00239 0xFE,0x10,0x10,0x10,0x0E,
00240 0x00,0x12,0x5E,0x02,0x00,
00241 0x02,0x01,0x01,0x11,0x5E,
00242 0xFE,0x08,0x08,0x14,0x22,
00243 0x00,0x82,0xFE,0x02,0x00,
00244 0x3E,0x20,0x1C,0x20,0x1E,
00245 0x3E,0x20,0x20,0x20,0x1E,
00246 0x1C,0x22,0x22,0x22,0x1C,
00247 0x3F,0x24,0x24,0x24,0x18,
00248 0x18,0x24,0x24,0x3F,0x01,
00249 0x3E,0x10,0x20,0x20,0x10,
00250 0x12,0x2A,0x2A,0x2A,0x04,
00251 0x00,0x10,0x3C,0x12,0x04,
00252 0x3C,0x02,0x02,0x02,0x3E,
00253 0x30,0x0C,0x02,0x0C,0x30,
00254 0x38,0x06,0x18,0x06,0x38,
00255 0x22,0x14,0x08,0x14,0x22,
00256 0x38,0x05,0x05,0x05,0x3E,
00257 0x22,0x26,0x2A,0x32,0x22,
00258 0x00,0x10,0x6C,0x82,0x82,
00259
00260 0x04,0x02,0xFF,0x02,0x04,
00261 0x82,0x82,0x6C,0x10,0x00,
00262 0x08,0x10,0x18,0x08,0x10};
00263
00264
00265
00266
00267
00268 ISR (SIG_USART_RECV)
00269 {
00270 cli();
00271 RX_array[RX_in] = UDR0;
00272
00273 RX_in++;
00274
00275 if (RX_in >= BUFFER) RX_in = 0;
00276
00277 sei();
00278
00279 }
00280
00281 ISR (TIMER0_COMPA_vect)
00282 {
00283 unsigned char y;
00284
00285
00286
00287 TCCR0B = 0;
00288 TIMSK0 = 0;
00289
00290 TIFR0 = 0x02;
00291 TCNT0 = 0;
00292
00293
00294
00295
00296 y = PINB;
00297 if (y & (1<<BL_EN))
00298 {
00299 PORTB &= (~(1<<BL_EN));
00300 OCR0A = BL_dutycycle;
00301 }
00302
00303 else
00304 {
00305 PORTB |= (1<<BL_EN);
00306 OCR0A = 100 - BL_dutycycle;
00307 }
00308
00309
00310
00311 TIMSK0 = 0x02;
00312 TCCR0B = 0x02;
00313
00314 }
00315
00316
00317 int main (void)
00318 {
00319 char x, y, temp;
00320
00321
00322 PORTB |= 0x08;
00323 delay();
00324 x = PINB;
00325 if ((x & 0x08) == 0x08) display = 1;
00326 else display = 0;
00327
00328 ioinit();
00329 set_baud(BAUD);
00330 rprintf_devopen(put_char);
00331
00332
00333 temp = EEPROM_read((unsigned int)BPS);
00334
00335 if ((temp < 1) | (temp > 6))
00336 {
00337 cli();
00338
00339 EEPROM_write((unsigned int) BPS, 6);
00340 EEPROM_write((unsigned int) BACKLIGHT, 100);
00341 EEPROM_write((unsigned int) SPLASH, 1);
00342 EEPROM_write((unsigned int) REV, 0);
00343
00344 sei();
00345
00346 BL_dutycycle = 100;
00347 baud_rate = BAUD;
00348 splash_screen = 1;
00349 reverse = 0;
00350 }
00351
00352 else
00353 {
00354 baud_rate = temp;
00355 BL_dutycycle = EEPROM_read((unsigned int)BACKLIGHT);
00356 splash_screen = EEPROM_read((unsigned int)SPLASH);
00357 reverse = EEPROM_read((unsigned int)REV);
00358 }
00359
00360
00361
00362 if (display == 0)
00363 {
00364 PORTC &= ~(1 << RESET);
00365 delay_ms(50);
00366 PORTC |= (1 << RESET);
00367
00368 clear_screen();
00369
00370 set_page(0);
00371
00372 set_x(0);
00373
00374 display_on();
00375
00376
00377
00378 PORTC &= ~((1 << EN) | (1 << R_W) | (1 << RS));
00379
00380 set_data(0xC0);
00381
00382 delay();
00383 PORTC |= (1 << EN);
00384 delay();
00385 PORTC &= ~(1 << EN);
00386 delay();
00387 PORTC |= ((1 << EN) | (1 << R_W) | (1 << RS));
00388
00389 delay();
00390
00391 x_offset = 0;
00392
00393 set_page(0);
00394
00395 }
00396
00397 else if (display == 1)
00398 {
00399 PORTC &= ~(1 << RST);
00400 delay_ms(50);
00401 PORTC |= (1 << RST);
00402
00403
00404 display_init();
00405
00406 clear_screen();
00407 }
00408
00409
00410 set_backlight(BL_dutycycle);
00411
00412 delay_ms(500);
00413
00414
00415
00416 if (splash_screen == 1)
00417 {
00418
00419
00420
00421
00422
00423
00424
00425
00426
00427
00428
00429
00430
00431
00432
00433
00434
00435
00436
00437
00438
00439
00440
00441
00442
00443
00444
00445
00446
00447
00448
00449
00450 ilab_logo();
00451
00452 }
00453
00454
00455 if (display == 0) pixel(0,0,0);
00456
00457 RX_in = 0;
00458
00459 delay_ms(1000);
00460 clear_screen();
00461
00462 if (RX_in > 0)
00463 {
00464 print_char(1,'1');
00465 print_char(1,'1');
00466 print_char(1,'5');
00467 print_char(1,'2');
00468 print_char(1,'0');
00469 print_char(1,'0');
00470
00471 baud_rate = BAUD;
00472 set_baud(BAUD);
00473
00474 cli();
00475
00476 EEPROM_write((unsigned int) BPS, 6);
00477
00478 sei();
00479 }
00480
00481 else (set_baud(baud_rate));
00482
00483 delay_ms(1000);
00484 clear_screen();
00485
00486
00487 motor_screen();
00488 motor_value(22,44,66,2,1);
00489
00490 while(1)
00491 {
00492 if(RX_in != RX_read)
00493 {
00494 x = RX_array[RX_read];
00495 RX_read++;
00496 if(RX_read >= BUFFER) RX_read = 0;
00497
00498
00499 if(x == 8) del_char(0);
00500
00501
00502 else if (x == 124)
00503 {
00504
00505 while(RX_in == RX_read);
00506
00507
00508 if(RX_array[RX_read] == 0)
00509 {
00510 clear_screen();
00511 RX_read++;
00512 if(RX_read >= BUFFER) RX_read = 0;
00513 }
00514
00515
00516 else if(RX_array[RX_read] == 4)
00517 {
00518 RX_in = 0, RX_read = 0;
00519 demo();
00520 clear_screen();
00521 RX_in = 0;
00522 }
00523
00524
00525
00526 else if(RX_array[RX_read] == 18)
00527 {
00528 reverse ^= 1;
00529 clear_screen();
00530 RX_read++;
00531 if(RX_read >= BUFFER) RX_read = 0;
00532
00533 cli();
00534 EEPROM_write((unsigned int) REV, reverse);
00535 sei();
00536 }
00537
00538
00539
00540 else if(RX_array[RX_read] == 19)
00541 {
00542 splash_screen ^= 1;
00543
00544 RX_read++;
00545 if(RX_read >= BUFFER) RX_read = 0;
00546
00547 cli();
00548 EEPROM_write((unsigned int) SPLASH, splash_screen);
00549 sei();
00550 }
00551
00552
00553 else if(RX_array[RX_read] == 20)
00554 {
00555
00556
00557 RX_in = 0, RX_read = 0;
00558 ilab_logo();
00559 RX_in = 0;
00560
00561 }
00562 else
00563 {
00564
00565 if(RX_array[RX_read] == 2)
00566 {
00567 RX_read++;
00568 if(RX_read >= BUFFER) RX_read = 0;
00569 while(RX_in == RX_read);
00570 BL_dutycycle = RX_array[RX_read];
00571
00572 RX_read++;
00573 if(RX_read >= BUFFER) RX_read = 0;
00574
00575 set_backlight(BL_dutycycle);
00576
00577 cli();
00578 EEPROM_write((unsigned int) BACKLIGHT, BL_dutycycle);
00579 sei();
00580
00581
00582
00583 }
00584
00585
00586
00587 else if(RX_array[RX_read] == 7)
00588 {
00589 RX_read++;
00590 if(RX_read >= BUFFER) RX_read = 0;
00591 while(RX_in == RX_read);
00592
00593
00594
00595
00596
00597
00598
00599 if ((RX_array[RX_read] > '0') * (RX_array[RX_read] < '7')) baud_rate = (RX_array[RX_read]) - 48;
00600
00601 set_baud(baud_rate);
00602
00603 cli();
00604 EEPROM_write((unsigned int) BPS, baud_rate);
00605 sei();
00606
00607 RX_read++;
00608 if(RX_read >= BUFFER) RX_read = 0;
00609
00610 }
00611
00612
00613
00614 else if((RX_array[RX_read] == 24) | (RX_array[RX_read] == 25))
00615 {
00616 RX_read++;
00617 if(RX_read >= BUFFER) RX_read = 0;
00618 while(RX_in == RX_read);
00619 if (RX_array[RX_read-1] == 24) x_offset = RX_array[RX_read];
00620 else if (RX_array[RX_read-1] == 25) y_offset = RX_array[RX_read];
00621
00622 RX_read++;
00623 if(RX_read >= BUFFER) RX_read = 0;
00624
00625 if (x_offset > 159) x_offset = 159;
00626 if (y_offset > 127) y_offset = 127;
00627
00628 }
00629
00630
00631 else if (RX_array[RX_read] == 16)
00632 {
00633
00634 for (y = 0; y < 3; y++)
00635 {
00636 RX_read++;
00637 if(RX_read >= BUFFER) RX_read = 0;
00638 while(RX_in == RX_read);
00639 }
00640
00641 pixel(RX_array[RX_read], RX_array[RX_read-2], RX_array[RX_read-1]);
00642
00643 RX_read++;
00644 if(RX_read >= BUFFER) RX_read = 0;
00645
00646 }
00647
00648
00649
00650 else if(RX_array[RX_read] == 3)
00651 {
00652
00653 for (y = 0; y < 4; y++)
00654 {
00655 RX_read++;
00656 if(RX_read >= BUFFER) RX_read = 0;
00657 while(RX_in == RX_read);
00658 }
00659
00660 circle(RX_array[RX_read], RX_array[RX_read-3], RX_array[RX_read-2], RX_array[RX_read-1]);
00661
00662 RX_read++;
00663 if(RX_read >= BUFFER) RX_read = 0;
00664 }
00665
00666
00667
00668 else if(RX_array[RX_read] == 5)
00669 {
00670
00671 for (y = 0; y < 4; y++)
00672 {
00673 RX_read++;
00674 if(RX_read >= BUFFER) RX_read = 0;
00675 while(RX_in == RX_read);
00676 }
00677
00678 erase_block(RX_array[RX_read-3], RX_array[RX_read-2], RX_array[RX_read-1], RX_array[RX_read]);
00679
00680 RX_read++;
00681 if(RX_read >= BUFFER) RX_read = 0;
00682 }
00683
00684
00685
00686 else if(RX_array[RX_read] == 15)
00687 {
00688
00689 for (y = 0; y < 4; y++)
00690 {
00691 RX_read++;
00692 if(RX_read >= BUFFER) RX_read = 0;
00693 while(RX_in == RX_read);
00694 }
00695
00696 box(RX_array[RX_read-3], RX_array[RX_read-2], RX_array[RX_read-1], RX_array[RX_read]);
00697
00698 RX_read++;
00699 if(RX_read >= BUFFER) RX_read = 0;
00700 }
00701
00702
00703
00704 else if (RX_array[RX_read] == 12)
00705 {
00706
00707 for (y = 0; y < 5; y++)
00708 {
00709 RX_read++;
00710 if(RX_read >= BUFFER) RX_read = 0;
00711 while(RX_in == RX_read);
00712 }
00713
00714 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]);
00715 RX_read++;
00716 if(RX_read >= BUFFER) RX_read = 0;
00717 }
00718
00719
00720
00721
00722
00723
00724
00725
00726 else
00727 if(RX_array[RX_read] == 14)
00728 {
00729
00730 for (y = 0; y < 4; y++)
00731 {
00732 RX_read++;
00733 if(RX_read >= BUFFER) RX_read = 0;
00734 while(RX_in == RX_read);
00735 }
00736
00737 solid_box(RX_array[RX_read-3], RX_array[RX_read-2], RX_array[RX_read-1], RX_array[RX_read]);
00738
00739 RX_read++;
00740 if(RX_read >= BUFFER) RX_read = 0;
00741 }
00742
00743 else if(RX_array[RX_read] == 6)
00744 {
00745
00746 for (y = 0; y < 5; y++)
00747 {
00748 RX_read++;
00749 if(RX_read >= BUFFER) RX_read = 0;
00750 while(RX_in == RX_read);
00751 }
00752
00753 thick_circle(RX_array[RX_read], RX_array[RX_read-4],RX_array[RX_read-3], RX_array[RX_read-2], RX_array[RX_read-1]);
00754
00755 RX_read++;
00756 if(RX_read >= BUFFER) RX_read = 0;
00757 }
00758
00759 else if(RX_array[RX_read] == 8)
00760 {
00761
00762 for (y = 0; y < 6; y++)
00763 {
00764 RX_read++;
00765 if(RX_read >= BUFFER) RX_read = 0;
00766 while(RX_in == RX_read);
00767 }
00768
00769
00770
00771
00772
00773
00774
00775
00776
00777
00778 bar(RX_array[RX_read-5],RX_array[RX_read-4],RX_array[RX_read-3], RX_array[RX_read-2], RX_array[RX_read-1],RX_array[RX_read]);
00779 RX_read++;
00780 if(RX_read >= BUFFER) RX_read = 0;
00781 }
00782
00783 else if(RX_array[RX_read] == 9)
00784 {
00785
00786
00787 for (y = 0; y < 5; y++)
00788 {
00789 RX_read++;
00790 if(RX_read >= BUFFER) RX_read = 0;
00791 while(RX_in == RX_read);
00792 }
00793
00794
00795 motor_value(RX_array[RX_read-4],RX_array[RX_read-3], RX_array[RX_read-2], RX_array[RX_read-1],RX_array[RX_read]);
00796 RX_read++;
00797 if(RX_read >= BUFFER) RX_read = 0;
00798 }
00799 else if(RX_array[RX_read] == 10)
00800 {
00801 RX_in = 0, RX_read = 0;
00802 motor_screen();
00803 RX_in = 0;
00804 }
00805
00806
00807 }
00808
00809 }
00810
00811
00812 else
00813 {
00814 del_char(1);
00815 print_char(1, x);
00816 }
00817 }
00818
00819 }
00820
00821
00822
00823
00824
00825
00826 }
00827
00828
00829
00830
00831
00832
00833
00834
00835
00836
00837
00838
00839
00840
00841
00842
00843
00844
00845
00846
00847
00848
00849
00850
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
00878
00879
00880
00881
00882
00883
00884
00885
00886
00887
00888
00889
00890
00891
00892
00893
00894
00895
00896
00897 void ilab_logo(void)
00898 {
00899
00900 circle(1,80,64,55);
00901 circle(1,80,64,56);
00902 circle(1,80,64,57);
00903 circle(1,80,64,58);
00904 circle(1,80,64,59) ;
00905 circle(1,80,64,60);
00906
00907
00908 circle(1,47,80,10);
00909 circle(1,47,80,9) ;
00910 solid_box(44,75,50,40);
00911
00912
00913 solid_box(58,85,65,40);
00914 solid_box(58,47,80,40);
00915
00916
00917 thick_circle(1,85,50,10,2);
00918
00919 solid_box(93,62,99,40);
00920
00921
00922 solid_box(103,80,108,40);
00923 circle(1,114,50,10);
00924 circle(1,114,50,9) ;
00925
00926
00927
00928 }
00929 void small_ilab_logo(void)
00930 {
00931 circle(1,135,50,24) ;
00932 circle(1,135,50,22);
00933
00934
00935 circle(1,121,56,4);
00936 solid_box(120,38,122,54);
00937
00938
00939 solid_box(126,38,128,60);
00940 solid_box(126,38,133,40);
00941
00942
00943 circle(1,135,43,4);
00944 solid_box(139,39,141,47);
00945
00946
00947 solid_box(143,39,145,60);
00948 circle(1,149,43,4);
00949
00950 }
00951
00952 void move(int x,int y)
00953 {
00954 x_offset = x;
00955 y_offset = y;
00956
00957 }
00958
00959 void motor_screen(void)
00960 {
00961
00962
00963
00964 move(0,68);
00965 print_string(1,"Speed:");
00966 bar(55,60,50,10,0,1);
00967
00968 move(0,55);
00969 print_string(1,"Turn :");
00970 bar(55,47,50,10,0,1);
00971
00972
00973 move(0,42);
00974 print_string(1,"CAP :");
00975 bar(55,34,50,10,0,1);
00976
00977 move(0,30);
00978 print_string(1,"Mode :");
00979 move(37,30);
00980 print_string(1,"Auto");
00981
00982 move(20,90);
00983 print_string(1,"Emergency Mode: ON");
00984 box(20,100,130,120);
00985
00986
00987 small_ilab_logo();
00988
00989
00990 }
00991 void bar_move(void)
00992 {
00993 int i;
00994 for(i = 0; i< 20 ;i++)
00995 bar(55,60,50,10,100-i*5,1);
00996
00997 for(i = 0; i< 20 ;i++)
00998 bar(55,47,50,10,100-i*5,1);
00999
01000 for(i = 0; i< 20 ;i++)
01001 bar(55,34,50,10,100-i*5,1);
01002
01003 }
01004
01005 void motor_value(int speed,int turn,int cap,int mode,int estop)
01006 {
01007 char manual[] = "Manual";
01008 erase_block(37,60,37+6*3,68);
01009 move(37,68);
01010 print_dec(1,speed);
01011 bar(55,60,50,10,speed,1);
01012
01013 erase_block(37,47,37+6*3,55);
01014 move(37,55);
01015 print_dec(1,turn);
01016 bar(55,47,50,10,turn,1);
01017
01018 erase_block(37,34,37+6*3,42);
01019 move(37,42);
01020 print_dec(1,cap);
01021 bar(55,34,50,10,cap,1);
01022 move(37,30);
01023
01024
01025 erase_block(37,22,100,30);
01026
01027 move(37,30);
01028
01029 if(mode == 1)
01030 print_string(1,manual);
01031 else if (mode ==2)
01032 print_string(1,"Semi-Auto");
01033 else if (mode ==3)
01034 print_string(1,"Auto");
01035
01036
01037 erase_block(116,82,116+6*3,90);
01038
01039 move(116,90);
01040 if(estop == 1)
01041 {
01042 print_string(1,"ON ");
01043 solid_box(21,101,129,120);
01044 }
01045 else
01046 {
01047 print_string(1,"OFF");
01048 erase_block(21,101,129,119);
01049 }
01050
01051 }
01052
01053
01054 void ioinit (void)
01055 {
01056
01057
01058
01059 DDRB = 0b00000011;
01060 DDRD = 0b11111100;
01061
01062 PORTB |= (1<<BL_EN);
01063 DDRB |= (1<<BL_EN);
01064
01065 if (display == 0)
01066 {
01067 DDRC = ((1<<EN) | (1<<RS) | (1<<R_W) | (1<<RESET) | (1<<CS1) | (1<<CS2));
01068 PORTC = ((1<<EN) | (1<<RS) | (1<<R_W) | (1<<RESET) | (1<<CS1) | (1<<CS2));
01069 }
01070
01071 else if (display == 1)
01072 {
01073 PORTC = ((1<<WR) | (1<<RD) | (1<<CE) | (1<<CD) | (1<<HALT) | (1<<RST));
01074 DDRC = ((1<<WR) | (1<<RD) | (1<<CE) | (1<<CD) | (1<<HALT) | (1<<RST));
01075 }
01076
01077
01078 TCCR2B = (1<<CS21);
01079
01080
01081 TCCR0A = 0x02;
01082
01083 TIMSK0 = 0x02;
01084
01085
01086
01087 OCR0A = BL_dutycycle;
01088
01089 }
01090
01091
01092 void delay_ms(uint16_t x)
01093 {
01094 for (; x > 0 ; x--)
01095 {
01096 delay_us(250);
01097 delay_us(250);
01098 delay_us(250);
01099 delay_us(250);
01100 }
01101
01102 }
01103
01104
01105 void delay_us(uint8_t x)
01106 {
01107 char temp;
01108
01109 if (x == 0) temp = 1;
01110 else temp = x;
01111
01112 TIFR2 |= 0x01;
01113
01114 TCNT2 = 256 - temp;
01115
01116 while(!(TIFR2 & 0x01));
01117
01118 if (x == 0) return;
01119
01120
01121 TIFR2 |= 0x01;
01122
01123 TCNT2 = 256 - temp;
01124
01125 while(!(TIFR2 & 0x01));
01126
01127 }
01128
01129 void USART_Init( unsigned int ubrr)
01130 {
01131
01132 UBRR0H = (unsigned char)(ubrr>>8);
01133 UBRR0L = (unsigned char)ubrr;
01134
01135
01136 UCSR0A = (1<<U2X0);
01137 UCSR0B = (1<<RXCIE0)|(1<<RXEN0)|(1<<TXEN0);
01138
01139 UCSR0C = (1<<UCSZ00)|(1<<UCSZ01);
01140 sei();
01141 }
01142
01143 void put_char(char byte)
01144 {
01145
01146 while ( !( UCSR0A & (1<<UDRE0)) );
01147
01148 UDR0 = byte;
01149 }
01150
01151
01152 void delay(void)
01153 {
01154 char y;
01155
01156
01157 for(y = 0; y < 30; y++)
01158 {
01159 asm volatile ("nop");
01160
01161 }
01162
01163
01164
01165
01166
01167
01168
01169
01170
01171 }
01172
01173
01174 void set_data(char data)
01175 {
01176
01177
01178
01179
01180 PORTB &= 0xFC;
01181
01182
01183
01184
01185
01186
01187
01188
01189
01190 PORTD &= 0x03;
01191
01192 PORTB |= (data & 0x03);
01193 PORTD |= (data & 0xFC);
01194
01195 }
01196
01197 void clear_screen(void)
01198 {
01199 char x, y;
01200 int z;
01201
01202 if (display == 0)
01203 {
01204 delay();
01205
01206 for (x = 0; x < 8; x++)
01207 {
01208
01209
01210 PORTC &= ~((1 << EN) | (1 << R_W) | (1 << RS));
01211
01212 set_data(0xB8 | x);
01213 delay();
01214 PORTC |= (1 << EN);
01215 delay();
01216 PORTC &= ~(1 << EN);
01217 delay();
01218 PORTC |= ((1 << EN) | (1 << R_W) |(1 << RS));
01219
01220 delay();
01221
01222
01223
01224 PORTC &= ~((1 << EN) | (1 << R_W) | (1 << RS));
01225
01226 set_data(0x40);
01227 delay();
01228 PORTC |= (1 << EN);
01229 delay();
01230 PORTC &= ~(1 << EN);
01231 delay();
01232 PORTC |= ((1 << EN) | (1 << R_W) | (1 << RS));
01233
01234 if (reverse == 1) set_data(0xFF);
01235 else set_data(0);
01236
01237 for (y = 0; y < 64; y++)
01238 {
01239 delay();
01240
01241
01242 PORTC &= ~((1 << EN) | (1 << R_W) | (1 << CS1));
01243 delay();
01244 PORTC |= (1 << EN);
01245 delay();
01246 PORTC &= ~(1 << EN);
01247 delay();
01248 PORTC |= ((1 << EN) | (1 << R_W) | (1 << CS1));
01249
01250 delay();
01251
01252
01253 PORTC &= ~((1 << EN) | (1 << R_W) | (1 << CS2));
01254 delay();
01255 PORTC |= (1 << EN);
01256 delay();
01257 PORTC &= ~(1 << EN);
01258 delay();
01259 PORTC |= ((1 << EN) | (1 << R_W) | (1 << CS2));
01260 }
01261
01262 }
01263
01264 x_offset = 0;
01265 y_offset = 63;
01266 }
01267
01268 else if (display == 1)
01269 {
01270 while(!(read(0) & 3));
01271 write(1, 0);
01272 while(!(read(0) & 3));
01273 write(1, 0);
01274 while(!(read(0) & 3));
01275 write(0, 0x24);
01276
01277 for(z = 0; z < 0xA00; z++)
01278 {
01279 while(!(read(0) & 3));
01280 if (reverse == 1) write(1,0xFF);
01281 else if (reverse == 0) write(1, 0);
01282 while(!(read(0) & 3));
01283 write(0, 0xC0);
01284 }
01285
01286 x_offset = 0;
01287 y_offset = 127;
01288 }
01289
01290 }
01291
01292
01293 void set_x(char x_spot)
01294 {
01295
01296
01297
01298
01299
01300
01301 if (x_spot == 0) x_spot = 63;
01302 else x_spot--;
01303
01304 PORTC &= ~((1 << EN) | (1 << R_W) | (1 << RS));
01305
01306 set_data(0x40 | x_spot);
01307 delay();
01308 PORTC |= (1 << EN);
01309 delay();
01310 PORTC &= ~(1 << EN);
01311 delay();
01312 PORTC |= ((1 << EN) | (1 << R_W) | (1 << RS));
01313 delay();
01314
01315 }
01316
01317 void print_string(char S_R, char str[])
01318 {
01319 int i;
01320 for(i=0;i<strlen(str);i++)
01321 print_char(S_R,str[i]);
01322 }
01323
01324 void print_dec(char S_R,int number)
01325 {
01326 char buf[5];
01327
01328 itoa(number,buf,10);
01329 print_string(S_R,buf);
01330
01331 }
01332
01333
01334
01335 void print_char(char S_R, char txt)
01336 {
01337 short text_array_offset = (txt - 32)*5, j;
01338 char x, k;
01339
01340
01341
01342 for (j = text_array_offset; j < text_array_offset+5; j++)
01343 {
01344 k = text_array[j];
01345
01346 for (x = 0; x < 8; x++)
01347 {
01348 if(k & 0x80) pixel(S_R, x_offset, y_offset - x);
01349
01350 k <<= 1;
01351 }
01352
01353 x_offset++;
01354
01355 }
01356
01357 x_offset++;
01358
01359 if ((x_offset + 6) > (127 + display*32))
01360 {
01361 x_offset = 0;
01362 if (y_offset <= 7)
01363 {
01364 y_offset = 63 + display*64;
01365
01366 }
01367 else y_offset -= 8;
01368
01369 }
01370
01371 if (display == 0) pixel(0,0,0);
01372
01373 }
01374
01375
01376 void set_page(char page)
01377 {
01378
01379 PORTC &= ~((1 << EN) | (1 << R_W) | (1 << RS));
01380
01381 set_data(0xB8 | page);
01382 delay();
01383 PORTC |= (1 << EN);
01384 delay();
01385 PORTC &= ~(1 << EN);
01386 delay();
01387 PORTC |= ((1 << EN) | (1 << R_W) |(1 << RS));
01388
01389 delay();
01390 }
01391
01392
01393 void write_byte(char byte, char side)
01394 {
01395 PORTC |= (1 << RS);
01396 set_data(byte);
01397
01398 delay();
01399
01400
01401 if (side == 1) PORTC &= ~((1 << EN) | (1 << R_W) | (1 << CS1));
01402 else if (side == 2) PORTC &= ~((1 << EN) | (1 << R_W) | (1 << CS2));
01403 delay();
01404 PORTC |= (1 << EN);
01405 delay();
01406 PORTC &= ~(1 << EN);
01407 delay();
01408 PORTC |= ((1 << EN) | (1 << R_W) | (1 << CS1) | (1 << CS2));
01409
01410
01411 }
01412
01413
01414
01415 void display_on(void)
01416 {
01417 set_data(0x3F);
01418 PORTC &= ~((1 << EN) | (1 << R_W) | (1 << RS));
01419 delay();
01420 PORTC |= (1 << EN);
01421 delay();
01422 PORTC &= ~(1 << EN);
01423 PORTC |= ((1 << EN) | (1 << R_W) | (1 << RS));
01424
01425 }
01426
01427
01428
01429
01430
01431 void pixel(char S_R, char x, char y)
01432 {
01433 static char temp_page, temp_side, temp_x = 0, temp_data1 = 0, temp_data2 = 0;
01434 short address = 0;
01435 char byte = 0;
01436
01437
01438 if (x > (127 + display*32)) return;
01439 if (y > (63 + display*64)) return;
01440
01441 if (reverse == 1) S_R ^= 1;
01442
01443 if (display == 0)
01444 {
01445 if (x >= 64) temp_side = 2, temp_x = x - 64;
01446 else temp_side = 1, temp_x = x;
01447
01448 temp_page = 7 - (y >> 3);
01449
01450
01451 temp_data1 = (1 << (7 - (y - ((7 - temp_page) * 8))));
01452
01453 set_page(temp_page);
01454 set_x(temp_x);
01455
01456
01457
01458 temp_data2 = read_byte(temp_x, temp_side);
01459
01460 if (S_R == 0)
01461 {
01462 temp_data1 = ~temp_data1;
01463 temp_data1 &= temp_data2;
01464 }
01465
01466 else temp_data1 |= temp_data2;
01467
01468 set_x(temp_x);
01469
01470 write_byte(temp_data1, temp_side);
01471 }
01472
01473 else if (display == 1)
01474 {
01475 address = ((127-y) * 20) + (x / 8);
01476
01477
01478 while(!(read(0) & 3));
01479 byte = (char)(address & 0xFF);
01480
01481 write(1, byte);
01482
01483 while(!(read(0) & 3));
01484 byte = (char)((address & 0xFF00) >> 8);
01485
01486 write(1, byte);
01487
01488 while(!(read(0) & 3));
01489 write(0, 0x24);
01490
01491 byte = ~(x % 8);
01492
01493 byte |= 0xF8;
01494 if (S_R == 0) byte &= 0xF7;
01495
01496
01497 while(!(read(0) & 3));
01498 write(0, byte);
01499 }
01500
01501 }
01502
01503
01504
01505 void line(char S_R, char x1, char y1, char x2, char y2)
01506 {
01507 float m, q;
01508 int x_dif, y_dif;
01509 int a, b, c;
01510
01511 if ((x1 > (127 + display*32)) | (x2 > (127 + display*32))) return;
01512 if ((y1 > (63 + display*64)) | (y2 > (63 + display*64))) return;
01513
01514 x_dif = x2 - x1;
01515 y_dif = y2 - y1;
01516 if (y_dif < 0) y_dif *= (-1);
01517
01518
01519 m = (float)(y2 - y1) / (float)(x2 - x1);
01520
01521 b = y1-(m*x1);
01522
01523 if(x_dif >= y_dif)
01524 {
01525 for (a = x1; a <= x2; a++)
01526 {
01527 pixel(S_R, (char)a, (char)((m*a)+b));
01528
01529 }
01530 }
01531
01532 else
01533 {
01534 if (y2 > y1)
01535 {
01536 for (a = y1; a <= y2; a++)
01537 {
01538 if (x_dif == 0) c = x1;
01539 else
01540 {
01541 q = (((float)(a-b))/m);
01542 c = rnd(q);
01543 }
01544
01545 pixel(S_R, (char)c, (char)a);
01546
01547 }
01548 }
01549
01550 else if (y1 > y2)
01551 {
01552 for (a = y1; a >= y2; a--)
01553 {
01554 if (x_dif == 0) c = x1;
01555 else
01556 {
01557 q = (((float)(a-b))/m);
01558 c = rnd(q);
01559 }
01560
01561 pixel(S_R, (char)c, (char)a);
01562
01563 }
01564 }
01565 }
01566
01567 if (display == 0) pixel(0,0,0);
01568 }
01569
01570
01571
01572 char read_byte(char byte, char side)
01573 {
01574 char data1 = 0, data2 = 0;
01575
01576 if (byte == 0) byte = 63;
01577 else byte--;
01578
01579 set_x(byte);
01580
01581 PORTC |= ((1 << RESET) | (1 << EN) | (1 << R_W) | (1 << CS1) | (1 << CS2) | (1 << RS));
01582
01583 DDRB &= 0xFC;
01584 DDRD = 0;
01585
01586
01587
01588
01589
01590
01591 delay();
01592 delay();
01593
01594 if (side == 1) PORTC &= ~((1 << EN) | (1 << CS1));
01595 else if (side == 2) PORTC &= ~((1 << EN) | (1 << CS2));
01596
01597
01598
01599
01600 delay();
01601 delay();
01602 PORTC |= (1 << EN);
01603
01604
01605 delay();
01606 delay();
01607
01608
01609
01610
01611
01612
01613
01614
01615
01616
01617
01618 PORTC &= ~(1 << EN);
01619
01620
01621
01622 delay();
01623 delay();
01624
01625 PORTC |= ((1 << RESET) | (1 << EN) | (1 << R_W) | (1 << CS1) | (1 << CS2) | (1 << RS));
01626
01627
01628
01629
01630
01631
01632 delay();
01633 delay();
01634
01635
01636 if (side == 1) PORTC &= ~((1 << EN) | (1 << CS1));
01637 else if (side == 2) PORTC &= ~((1 << EN) | (1 << CS2));
01638
01639
01640
01641 delay();
01642 delay();
01643 PORTC |= (1 << EN);
01644
01645
01646
01647 delay();
01648 delay();
01649 data1 = PINB;
01650 data1 &= 0x03;
01651
01652 data2 = PIND;
01653 data2 &= 0xFC;
01654
01655 data1 |= data2;
01656
01657
01658 PORTC &= ~(1 << EN);
01659
01660
01661
01662
01663 PORTC |= ((1 << RESET) | (1 << EN) | (1 << R_W) | (1 << CS1) | (1 << CS2) | (1 << RS));
01664
01665 DDRB |= 0x03;
01666 DDRD |= 0xFC;
01667
01668 delay();
01669
01670 return data1;
01671
01672 }
01673
01674
01675 int rnd(float number)
01676 {
01677 int a;
01678 float b;
01679
01680 a = number / 1;
01681 b = number - a;
01682
01683 if (b >= 0.5) a++;
01684
01685 return a;
01686
01687 }
01688
01689
01690 void circle(char S_R, int x, int y, int r)
01691 {
01692 int x1 = 0, x2 = 0;
01693 int x_line = 0, y_line = 0;
01694 int temp_y;
01695 int temp_x;
01696
01697 x1 = x - r;
01698 x2 = x + r;
01699
01700 for (temp_x = x1; temp_x <= x2; temp_x++)
01701 {
01702 temp_y = ((sqrt((r*r) - ((temp_x - x)*(temp_x - x)))) - y);
01703
01704 temp_y *= (-1);
01705
01706 if (temp_x > x1)
01707 {
01708 line(S_R, (char)x_line, (char)y_line, (char)temp_x, (char)temp_y);
01709 line(S_R, (char)x_line, (char)(2*y - y_line), (char)temp_x, (char)(2*y - temp_y));
01710 }
01711
01712 else
01713 {
01714 pixel(S_R, (char)temp_x, (char)temp_y);
01715 pixel(S_R, (char)temp_x, (char)(y + y - temp_y));
01716 }
01717
01718 x_line = temp_x;
01719 y_line = temp_y;
01720
01721 }
01722
01723 if (display == 0) pixel(0,0,0);
01724
01725 }
01726
01727 void thick_circle(char S_R, int x, int y, int r,int thickness)
01728 {
01729 int i;
01730 if(thickness > r)
01731 thickness = r;
01732 for(i = 0 ; i < thickness ; i++)
01733 circle(S_R,x,y,r-i);
01734 }
01735
01736
01737 void EEPROM_write(unsigned int uiAddress, unsigned char ucData)
01738 {
01739
01740 while(EECR & (1<<EEPE))
01741 ;
01742
01743 EEAR = uiAddress;
01744 EEDR = ucData;
01745
01746 EECR |= (1<<EEMPE);
01747
01748 EECR |= (1<<EEPE);
01749 }
01750
01751 unsigned char EEPROM_read(unsigned int uiAddress)
01752 {
01753
01754 while(EECR & (1<<EEPE))
01755 ;
01756
01757 EEAR = uiAddress;
01758
01759 EECR |= (1<<EERE);
01760
01761 return EEDR;
01762 }
01763
01764 void set_backlight(unsigned char dutycycle)
01765 {
01766
01767 TCCR0A = 0x02;
01768
01769
01770
01771
01772
01773
01774
01775
01776
01777
01778 if(BL_dutycycle >= 100)
01779 {
01780 TCCR0B = 0;
01781 TIMSK0 = 0;
01782
01783
01784 PORTB &= (~(1<<BL_EN));
01785 }
01786 else if (BL_dutycycle == 0)
01787 {
01788 TCCR0B = 0;
01789 TIMSK0 = 0;
01790
01791
01792 PORTB |= (1<<BL_EN);
01793 }
01794
01795
01796 else
01797 {
01798 TCCR0B = 0;
01799 TIMSK0 = 0;
01800
01801 OCR0A = 100 - BL_dutycycle;
01802
01803 TIMSK0 = 0x02;
01804 TCCR0B = 0x02;
01805
01806 SREG |= 0x80;
01807
01808 }
01809
01810 }
01811
01812
01813
01814
01815 void del_char(char endpoint)
01816 {
01817 char a, y;
01818
01819 if (endpoint == 0)
01820 {
01821 if (x_offset <= 5)
01822 {
01823 x_offset += (120 + display*36);
01824 y_offset += 8;
01825
01826 if (y_offset > (63 + display*64)) y_offset -= (64 + display*64);
01827 }
01828
01829 else x_offset -= 6;
01830 }
01831
01832 for (a = x_offset; a < x_offset + 6; a++)
01833 {
01834 for (y = y_offset - 7; y <= y_offset; y++)
01835 {
01836 pixel(0, a, y);
01837
01838 }
01839 }
01840
01841 if (display == 0) pixel(0,0,0);
01842 }
01843
01844
01845
01846 void demo(void)
01847 {
01848 char x, y, temp;
01849 unsigned char x_endpoint, y_endpoint;
01850 int q = 0;
01851
01852 x_endpoint = 127 + display*32;
01853 y_endpoint = 63 + display*64;
01854
01855 while(1)
01856 {
01857
01858 ilab_logo();
01859 ilab_logo();
01860 ilab_logo();
01861 ilab_logo();
01862 clear_screen();
01863 x_offset = 0;
01864 y_offset = y_endpoint;
01865
01866
01867
01868 for (y = 0; y < 5; y++)
01869 {
01870 for (x = 32; x < 123; x++)
01871 {
01872 del_char(1);
01873 print_char(1, x);
01874 if (RX_in > 0) return;
01875 }
01876 }
01877
01878 clear_screen();
01879
01880 for (y = 0; y < 5; y++)
01881 {
01882 for (x = 32; x < 123; x++)
01883 {
01884
01885 y_offset -= 6;
01886 if (y_offset <= 8) y_offset = y_endpoint;
01887 del_char(1);
01888 print_char(1, x);
01889 if (RX_in > 0) return;
01890 }
01891 }
01892
01893 clear_screen();
01894
01895
01896 for (x = 5; x < (64 + display*56); x += 5)
01897 {
01898 circle(1,(64+display*16),(32 + display*32),x);
01899 if (RX_in > 0) return;
01900 }
01901
01902
01903
01904 y = y_endpoint;
01905
01906 for (x = 0; x < (x_endpoint); x += (16 + display*4))
01907 {
01908 line(1,0,y,x,0);
01909 y -= (8 + display*8);
01910 }
01911
01912 y = 0;
01913
01914 for (x = 0; x < x_endpoint; x += (16 + display*4))
01915 {
01916 line(1,x,0,x_endpoint,y);
01917 y += (8 + display*8);
01918 }
01919
01920 y = y_endpoint;
01921
01922 for (x = 0; x < x_endpoint; x += (16 + display*4))
01923 {
01924 line(1,x,y_endpoint,x_endpoint,y);
01925 y -= (8 + display*8);
01926 }
01927
01928 y = 0;
01929
01930 for (x = 0; x < x_endpoint; x += (16 + display*4))
01931 {
01932 line(1,0,y,x,y_endpoint);
01933 y += (8 + display*8);
01934 }
01935
01936
01937
01938
01939 for (x = 5; x < (64 + display*56); x += 5)
01940 {
01941 circle(0,(64+display*16),(32 + display*32),x);
01942 if (RX_in > 0) return;
01943 }
01944
01945
01946 y = y_endpoint;
01947
01948 for (x = 0; x < x_endpoint; x += (16 + display*4))
01949 {
01950 line(0,0,y,x,0);
01951 y -= (8 + display*8);
01952 }
01953
01954 y = 0;
01955
01956 for (x = 0; x < x_endpoint; x += (16 + display*4))
01957 {
01958 line(0,x,0,x_endpoint,y);
01959 y += (8 + display*8);
01960 }
01961
01962 y = y_endpoint;
01963
01964 for (x = 0; x < x_endpoint; x += (16 + display*4))
01965 {
01966 line(0,x,y_endpoint,x_endpoint,y);
01967 y -= (8 + display*8);
01968 }
01969
01970 y = 0;
01971
01972 for (x = 0; x < x_endpoint; x += (16 + display*4))
01973 {
01974 line(0,0,y,x,y_endpoint);
01975 y += (8 + display*8);
01976 }
01977
01978 if (RX_in > 0) return;
01979
01980
01981 y = 47 + display*64;
01982 for (x = 0; x <= (100 + display*40); x += 10)
01983 {
01984 erase_block(x, y, x+16, y+16);
01985 box(x, y, x+16, y+16);
01986 y -= (4 + display*3);
01987 }
01988
01989
01990
01991 y = (22 + display*6);
01992
01993 q = 0;
01994 while(q < 30)
01995 {
01996 temp = logo[q];
01997 for (x = (100 + display*40); x < (108 + display*40); x++)
01998 {
01999 if (temp & 0x80) pixel(1,x,y);
02000
02001 temp <<= 1;
02002 }
02003 q++;
02004 temp = logo[q];
02005 for (x = (108 + display*40); x < (116 + display*40); x++)
02006 {
02007 if (temp & 0x80) pixel(1,x,y);
02008
02009 temp <<= 1;
02010 }
02011 y--;
02012 q++;
02013 }
02014
02015 if (display == 0) pixel(0,0,0);
02016
02017 delay_ms(1000);
02018 reverse ^= 1;
02019 clear_screen();
02020
02021 }
02022
02023
02024 }
02025
02026
02027
02028
02029 void erase_block(char x1, char y1, char x2, char y2)
02030 {
02031 static char temp_x = 0, temp_y = 0;
02032
02033 for (temp_y = y2; temp_y >= y1; temp_y--)
02034 {
02035 for (temp_x = x1; temp_x <= x2; temp_x++)
02036 {
02037 pixel(0, temp_x, temp_y);
02038
02039 }
02040 }
02041
02042
02043
02044 }
02045
02046
02047
02048 void box(char x1, char y1, char x2, char y2)
02049 {
02050
02051 line(1, x2, y2, x2, y1);
02052 line(1, x1, y2, x2, y2);
02053 line(1, x1, y2, x1, y1);
02054 line(1, x1, y1, x2, y1);
02055 }
02056 void solid_box(char x1, char y1, char x2, char y2)
02057 {
02058 int i;
02059 if(y1<y2)
02060 for(i=y1;i<y2;i++)
02061 line(1, x1, i, x2, i);
02062 else
02063 for(i=y2;i<y1;i++)
02064 line(1, x1, i, x2, i);
02065
02066 }
02067
02068
02069
02070 void bar(char x1, char y1, char width, char length,char value,char v_h)
02071 {
02072 int value_point;
02073 box(x1,y1,x1+width,y1+length);
02074 if(v_h == 1)
02075 {
02076 value_point = x1 + width*value/100;
02077 solid_box(x1,y1,value_point,y1+length);
02078 erase_block(value_point+1,y1+1,x1+width-1,y1+length-1);
02079
02080 }else{
02081 value_point = y1 + length*value/100;
02082 solid_box(x1,y1,x1+width,value_point);
02083 erase_block(x1+1,value_point+1,x1+width-1,y1+length-1);
02084 }
02085
02086
02087 }
02088
02089
02090
02091 void set_baud(char b)
02092 {
02093 if (b == 1) USART_Init( 1000000/2400-1);
02094 else if (b == 2) USART_Init( 1000000/4800-1);
02095 else if (b == 3) USART_Init( 1000000/9600-1);
02096 else if (b == 4) USART_Init( 1000000/19200-1);
02097 else if (b == 5) USART_Init( 1000000/28800-1);
02098 else if (b == 6) USART_Init( 1000000/57600-1);
02099
02100 }
02101
02102
02103
02104
02105
02106 char read(char D_S)
02107 {
02108 char data1 = 0, data2 = 0;
02109
02110 DDRB &= 0xFC;
02111 DDRD &= 0x02;
02112
02113 PORTC &= ~((1 << RD) | (1 << CE));
02114 if (D_S == 1) PORTC &= ~(1 << CD);
02115
02116 delay_us(2);
02117
02118 data1 = PINB;
02119 data1 &= 0x03;
02120
02121 data2 = PIND;
02122 data2 &= 0xFC;
02123
02124 data1 |= data2;
02125
02126 PORTC |= ((1 << CD) | (1 << RD) | (1 << CE));
02127
02128 delay_us(2);
02129
02130 return data1;
02131
02132 }
02133
02134
02135
02136 void write(char D_C, char byte)
02137 {
02138 DDRB |= 0x03;
02139 DDRD |= 0xFC;
02140
02141 set_data(byte);
02142
02143 if (D_C == 1) PORTC &= ~((1 << WR) | (1 << CE) | (1 << CD));
02144 else PORTC &= ~((1 << WR) | (1 << CE));
02145
02146 delay_us(2);
02147 PORTC |= ((1 << CD) | (1 << WR) | (1 << CE));
02148 delay_us(2);
02149 DDRB &= 0xFC;
02150 DDRD &= 0x02;
02151
02152 delay_us(2);
02153
02154 }
02155
02156
02157
02158 void display_init(void)
02159 {
02160
02161 while(!(read(0) & 3));
02162 write(1, 0);
02163 while(!(read(0) & 3));
02164 write(1, 0);
02165 while(!(read(0) & 3));
02166 write(0, 0x42);
02167
02168
02169 while(!(read(0) & 3));
02170 write(1, 20);
02171 while(!(read(0) & 3));
02172 write(1, 0);
02173 while(!(read(0) & 3));
02174 write(0, 0x43);
02175
02176
02177 while(!(read(0) & 3));
02178 write(0, 0x80);
02179
02180
02181 while(!(read(0) & 3));
02182 write(0, 0x98);
02183
02184 }
02185
02186
02187