00001 /* 00002 graphic LCD backpack test code 00003 00004 10/7/08, text and lines work, need to set up UART and circle functions 00005 00006 */ 00007 00008 #include <avr/io.h> 00009 #include "rprintf.h" 00010 00011 00012 #define FOSC 16000000// Clock Speed 00013 #define BAUD 9600 00014 #define MYUBRR FOSC/16/BAUD-1 00015 00016 #define EN 0 //PC0 00017 #define RS 1 //PC1, D_I? 00018 #define R_W 2 //PC2 00019 #define RESET 3 //PC3 00020 #define CS1 4 //PC4 00021 #define CS2 5 //PC5 00022 00023 00024 //Define functions 00025 //====================== 00026 void ioinit(void); //Initializes IO 00027 void delay_ms(uint16_t x); //General purpose delay 00028 void delay(void); 00029 void USART_Init( unsigned int ubrr); 00030 void put_char(char byte); 00031 00032 void set_data(char data); 00033 void set_x(char x_spot); 00034 void set_page(char page); 00035 void clear_screen(void); 00036 void write_byte(char byte, char side); 00037 char read_byte(char byte, char side); 00038 void display_on(void); 00039 00040 unsigned char print_char(char txt); 00041 void pixel(char x, char y); 00042 void line(char x1, char y1, char x2, char y2); 00043 00044 //====================== 00045 00046 00047 char x_offset = 0; 00048 //char y_offset = 0; 00049 char side_mark = 1;//left side default 00050 char page_mark = 0; 00051 00052 //Jacked from Sinister 7 code 00053 static char text_array[475] = {0x00,0x00,0x00,0x00,0x00,/*space*/ 00054 0x00,0xF6,0xF6,0x00,0x00,/*!*/ 00055 0x00,0xE0,0x00,0xE0,0x00,/*"*/ 00056 0x28,0xFE,0x28,0xFE,0x28,/*#*/ 00057 0x00,0x64,0xD6,0x54,0x08,/*$*/ 00058 0xC2,0xCC,0x10,0x26,0xC6,/*%*/ 00059 0x4C,0xB2,0x92,0x6C,0x0A,/*&*/ 00060 0x00,0x00,0xE0,0x00,0x00,/*'*/ 00061 0x00,0x38,0x44,0x82,0x00,/*(*/ 00062 0x00,0x82,0x44,0x38,0x00,/*)*/ 00063 0x88,0x50,0xF8,0x50,0x88,/***/ 00064 0x08,0x08,0x3E,0x08,0x08,/*+*/ 00065 0x00,0x00,0x05,0x06,0x00,/*,*/ 00066 0x08,0x08,0x08,0x08,0x08,/*-*/ 00067 0x00,0x00,0x06,0x06,0x00,/*.*/ 00068 0x02,0x0C,0x10,0x60,0x80,/*/*/ 00069 0x7C,0x8A,0x92,0xA2,0x7C,/*0*/ 00070 0x00,0x42,0xFE,0x02,0x00,/*1*/ 00071 0x42,0x86,0x8A,0x92,0x62,/*2*/ 00072 0x44,0x82,0x92,0x92,0x6C,/*3*/ 00073 0x10,0x30,0x50,0xFE,0x10,/*4*/ 00074 0xE4,0xA2,0xA2,0xA2,0x9C,/*5*/ 00075 0x3C,0x52,0x92,0x92,0x0C,/*6*/ 00076 0x80,0x86,0x98,0xE0,0x80,/*7*/ 00077 0x6C,0x92,0x92,0x92,0x6C,/*8*/ 00078 0x60,0x92,0x92,0x94,0x78,/*9*/ 00079 0x00,0x00,0x36,0x36,0x00,/*:*/ 00080 0x00,0x00,0x35,0x36,0x00,/*;*/ 00081 0x10,0x28,0x44,0x82,0x00,/*<*/ 00082 0x28,0x28,0x28,0x28,0x28,/*=*/ 00083 0x00,0x82,0x44,0x28,0x10,/*>*/ 00084 0x40,0x80,0x8A,0x90,0x60,/*?*/ 00085 0x7C,0x82,0xBA,0xBA,0x62,/*@*/ 00086 0x3E,0x48,0x88,0x48,0x3E,/*A*/ 00087 0xFE,0x92,0x92,0x92,0x6C,/*B*/ 00088 0x7C,0x82,0x82,0x82,0x44,/*C*/ 00089 0xFE,0x82,0x82,0x82,0x7C,/*D*/ 00090 0xFE,0x92,0x92,0x92,0x82,/*E*/ 00091 0xFE,0x90,0x90,0x90,0x80,/*F*/ 00092 0x7C,0x82,0x82,0x8A,0x4E,/*G*/ 00093 0xFE,0x10,0x10,0x10,0xFE,/*H*/ 00094 0x82,0x82,0xFE,0x82,0x82,/*I*/ 00095 0x84,0x82,0xFC,0x80,0x80,/*J*/ 00096 0xFE,0x10,0x28,0x44,0x82,/*K*/ 00097 0xFE,0x02,0x02,0x02,0x02,/*L*/ 00098 0xFE,0x40,0x20,0x40,0xFE,/*M*/ 00099 0xFE,0x60,0x10,0x0C,0xFE,/*N*/ 00100 0x7C,0x82,0x82,0x82,0x7C,/*O*/ 00101 0xFE,0x90,0x90,0x90,0x60,/*P*/ 00102 0x7C,0x82,0x82,0x86,0x7E,/*Q*/ 00103 0xFE,0x90,0x98,0x94,0x62,/*R*/ 00104 0x64,0x92,0x92,0x92,0x4C,/*S*/ 00105 0x80,0x80,0xFE,0x80,0x80,/*T*/ 00106 0xFC,0x02,0x02,0x02,0xFC,/*U*/ 00107 0xF8,0x04,0x02,0x04,0xF8,/*V*/ 00108 0xFC,0x02,0x0C,0x02,0xFC,/*W*/ 00109 0xC6,0x28,0x10,0x28,0xC6,/*X*/ 00110 0xC0,0x20,0x1E,0x20,0xC0,/*Y*/ 00111 0x86,0x8A,0x92,0xA2,0xC2,/*Z*/ 00112 0x00,0x00,0xFE,0x82,0x00,/*[*/ 00113 0x00,0x00,0x00,0x00,0x00,/*this should be / */ 00114 0x80,0x60,0x10,0x0C,0x02,/*]*/ 00115 0x20,0x40,0x80,0x40,0x20,/*^*/ 00116 0x01,0x01,0x01,0x01,0x01,/*_*/ 00117 0x80,0x40,0x20,0x00,0x00,/*`*/ 00118 0x04,0x2A,0x2A,0x2A,0x1E,/*a*/ 00119 0xFE,0x12,0x22,0x22,0x1C,/*b*/ 00120 0x1C,0x22,0x22,0x22,0x14,/*c*/ 00121 0x1C,0x22,0x22,0x12,0xFE,/*d*/ 00122 0x1C,0x2A,0x2A,0x2A,0x18,/*e*/ 00123 0x10,0x7E,0x90,0x80,0x40,/*f*/ 00124 0x18,0x25,0x25,0x25,0x1E,/*g*/ 00125 0xFE,0x10,0x10,0x10,0x0E,/*h*/ 00126 0x00,0x12,0x5E,0x02,0x00,/*i*/ 00127 0x02,0x01,0x01,0x11,0x5E,/*j*/ 00128 0xFE,0x08,0x08,0x14,0x22,/*k*/ 00129 0x00,0x82,0xFE,0x02,0x00,/*l*/ 00130 0x3E,0x20,0x1C,0x20,0x1E,/*m*/ 00131 0x3E,0x20,0x20,0x20,0x1E,/*n*/ 00132 0x1C,0x22,0x22,0x22,0x1C,/*o*/ 00133 0x3F,0x24,0x24,0x24,0x18,/*p*/ 00134 0x18,0x24,0x24,0x3F,0x01,/*q*/ 00135 0x3E,0x10,0x20,0x20,0x10,/*r*/ 00136 0x12,0x2A,0x2A,0x2A,0x04,/*s*/ 00137 0x00,0x10,0x3C,0x12,0x04,/*t*/ 00138 0x3C,0x02,0x02,0x02,0x3E,/*u*/ 00139 0x30,0x0C,0x02,0x0C,0x30,/*v*/ 00140 0x38,0x06,0x18,0x06,0x38,/*w*/ 00141 0x22,0x14,0x08,0x14,0x22,/*x*/ 00142 0x38,0x05,0x05,0x05,0x3E,/*y*/ 00143 0x22,0x26,0x2A,0x32,0x22,/*z*/ 00144 0x00,0x10,0x6C,0x82,0x82,/*{*/ 00145 //0x00,0x00,0xFF,0x00,0x00,/*|*/ 00146 0x04,0x02,0xFF,0x02,0x04,/*|, arrow*/ 00147 0x82,0x82,0x6C,0x10,0x00,/*}*/ 00148 0x08,0x10,0x18,0x08,0x10};/*~*/ 00149 00150 00151 00152 00153 int main (void) 00154 { 00155 char x, y; 00156 //char a = 0; 00157 ioinit(); //Setup IO pins and defaults 00158 USART_Init( MYUBRR); 00159 rprintf_devopen(put_char); /* init rrprintf */ 00160 00161 //set_data(0x55); 00162 00163 //PORTC |= ((1 << RESET) | (1 << EN) | (1 << R_W) | (1 << CS1) | (1 << CS2) | (1 << RS));//all high 00164 00165 //while(1); 00166 00167 /* 00168 while(1) 00169 { 00170 PORTC &= ~((1 << EN) | (1 << R_W) | (1 << CS1) | (1 << CS2));//down 00171 delay_ms(500); 00172 //PORTC |= ((1 << EN) | (1 << R_W) | (1 << CS1) | (1 << CS2));//all high 00173 PORTC |= ((1 << RESET) | (1 << EN) | (1 << R_W) | (1 << CS1) | (1 << CS2) | (1 << RS));//all high 00174 delay_ms(500); 00175 } 00176 */ 00177 /* 00178 DDRC = 0b00000001; 00179 00180 while(1) 00181 { 00182 PORTC |= 0b00000001; 00183 delay_1uS(); 00184 PORTC &= 0b11111110; 00185 delay_1uS(); 00186 00187 } 00188 */ 00189 00190 //Reset the display 00191 //PORTC = 0b11110111; 00192 PORTC &= ~(1 << RESET); 00193 delay_ms(50); 00194 //PORTC = 0b11111111; 00195 PORTC |= (1 << RESET); 00196 delay_ms(500); 00197 00198 clear_screen(); 00199 00200 set_page(0); 00201 set_x(0); 00202 00203 display_on(); 00204 00205 //set display start line to 0 00206 //set control lines 00207 PORTC &= ~((1 << EN) | (1 << R_W) | (1 << RS));//down 00208 00209 set_data(0xC0); 00210 //set_data(0xFF); 00211 delay(); 00212 PORTC |= (1 << EN);//up 00213 delay(); 00214 PORTC &= ~(1 << EN);//down 00215 delay(); 00216 PORTC |= ((1 << EN) | (1 << R_W) | (1 << RS));//all high 00217 00218 delay(); 00219 00220 x_offset = 0; 00221 00222 set_page(0); 00223 00224 /* 00225 set_x(0); 00226 write_byte(0X55, 1); 00227 00228 set_x(1); 00229 write_byte(0X55, 1); 00230 00231 //set_x(0); 00232 x = read_byte(1,1); 00233 00234 set_x(2); 00235 write_byte(x, 1); 00236 set_x(3); 00237 write_byte(x, 1); 00238 */ 00239 00240 00241 //set_x(63);//??? 00242 00243 //x = read_byte(1); 00244 00245 //set_x(3); 00246 00247 //rite_byte(x, 1); 00248 00249 //set_x(0); 00250 00251 //write_byte(x, 1); 00252 00253 //while(1); 00254 00255 while(1) 00256 { 00257 line(0, 0, 63, 63); 00258 line(0, 10, 63, 52); 00259 line(0, 21, 63, 42); 00260 line(0, 32, 63, 32); 00261 line(0, 42, 63, 21); 00262 line(0, 52, 63, 10); 00263 line(0, 63, 63, 0); 00264 00265 00266 line(64, 0, 127, 63); 00267 line(64, 10, 127, 52); 00268 line(64, 21, 127, 42); 00269 line(64, 32, 127, 32); 00270 line(64, 42, 127, 21); 00271 line(64, 52, 127, 10); 00272 line(64, 63, 127, 0); 00273 00274 //set_x(20); 00275 x_offset = 20; 00276 set_page(0); 00277 00278 print_char('C'); 00279 print_char('O'); 00280 print_char('C'); 00281 print_char('K'); 00282 00283 x_offset = 82; 00284 print_char('B'); 00285 print_char('L'); 00286 print_char('O'); 00287 print_char('C'); 00288 print_char('K'); 00289 00290 x_offset = 14; 00291 set_page(7); 00292 00293 print_char('M'); 00294 print_char('O'); 00295 print_char('T'); 00296 print_char('H'); 00297 print_char('E'); 00298 print_char('R'); 00299 00300 x_offset = 79; 00301 print_char('F'); 00302 print_char('U'); 00303 print_char('C'); 00304 print_char('K'); 00305 print_char('E'); 00306 print_char('R'); 00307 00308 delay_ms(1000); 00309 clear_screen(); 00310 } 00311 00312 //line(0, 20, 127, 63); 00313 00314 //line(20, 0, 127, 63); 00315 00316 //line(0, 63, 127, 0); 00317 00318 //pixel(127,63); 00319 //pixel(0,0); 00320 while(1); 00321 00322 while(1) 00323 { 00324 for (y = 0; y < 64; y++) 00325 { 00326 //set_x(0); 00327 00328 //pixel(0,y); 00329 //display_on(); 00330 //delay_ms(500); 00331 00332 for(x = 0; x < 128; x++) 00333 { 00334 pixel(x,y); 00335 //delay_ms(10); 00336 display_on(); 00337 } 00338 00339 } 00340 00341 delay_ms(1000); 00342 clear_screen(); 00343 00344 } 00345 00346 00347 /* 00348 00349 00350 while(1); 00351 */ 00352 00353 /* 00354 for (a = 0; a < 64; a++) 00355 { 00356 set_x(a); 00357 write_byte(a,2); 00358 delay_ms(500); 00359 } 00360 */ 00361 00362 /* 00363 set_x(63); 00364 write_byte(0xFF,1); 00365 00366 set_x(0); 00367 write_byte(0x55,1); 00368 00369 while(1); 00370 */ 00371 00372 /* 00373 while(1) 00374 { 00375 for (a = 32; a < 128; a++) 00376 { 00377 print_char(a); 00378 00379 display_on(); 00380 delay_ms(50); 00381 } 00382 } 00383 */ 00384 00385 00386 } 00387 00388 void ioinit (void) 00389 { 00390 00391 //1 = output, 0 = input 00392 00393 DDRB = 0b00000011; //PB0 and PB1 are outs 00394 DDRC = ((1<<EN) | (1<<RS) | (1<<R_W) | (1<<RESET) | (1<<CS1) | (1<<CS2)); 00395 PORTC = ((1<<EN) | (1<<RS) | (1<<R_W) | (1<<RESET) | (1<<CS1) | (1<<CS2)); 00396 DDRD = 0b11111100; //PD2-PD7 are also outs. Ports B and D are the data bus. 00397 00398 } 00399 00400 //General short delays 00401 void delay_ms(uint16_t x) 00402 { 00403 uint8_t y, z; 00404 for ( ; x > 0 ; x--){ 00405 for ( y = 0 ; y < 165 ; y++){ 00406 for ( z = 0 ; z < 18 ; z++){ 00407 asm volatile ("nop"); 00408 } 00409 } 00410 } 00411 } 00412 00413 void USART_Init( unsigned int ubrr) 00414 { 00415 /* Set baud rate */ 00416 UBRRH = (unsigned char)(ubrr>>8); 00417 UBRRL = (unsigned char)ubrr; 00418 /* Enable receiver and transmitter */ 00419 UCSRB = (1<<RXEN)|(1<<TXEN); 00420 /* Set frame format: 8data, 2stop bit */ 00421 UCSRC = (1<<URSEL)|(1<<USBS)|(3<<UCSZ0); 00422 } 00423 00424 void put_char(char byte) 00425 { 00426 /* Wait for empty transmit buffer */ 00427 while ( !( UCSRA & (1<<UDRE)) ); 00428 /* Put data into buffer, sends the data */ 00429 UDR = byte; 00430 } 00431 00432 //delay for display timing 00433 void delay(void) 00434 { 00435 char y; 00436 00437 for(y = 0; y < 20; y++) 00438 { 00439 asm volatile ("nop"); 00440 00441 } 00442 00443 /* 00444 asm volatile ("nop"); 00445 asm volatile ("nop"); 00446 asm volatile ("nop"); 00447 asm volatile ("nop"); 00448 asm volatile ("nop"); 00449 */ 00450 00451 } 00452 00453 //set data port 00454 void set_data(char data) 00455 { 00456 //PORTB 00457 //DB0 = PB0 00458 //DB1 = PB1 00459 00460 PORTB &= 0xFC; 00461 00462 //PORTD 00463 //DB2 = PD2 00464 //DB3 = PD3 00465 //DB4 = PD4 00466 //DB5 = PD5 00467 //DB6 = PD6 00468 //DB7 = PD7 00469 00470 PORTD &= 0x03; 00471 00472 PORTB |= (data & 0x03); 00473 PORTD |= (data & 0xFC); 00474 00475 } 00476 00477 void clear_screen(void) 00478 { 00479 char x, y; 00480 00481 delay(); 00482 00483 for (x = 0; x < 8; x++) 00484 { 00485 //set x address 00486 //set control lines 00487 PORTC &= ~((1 << EN) | (1 << R_W) | (1 << RS));//down 00488 00489 set_data(0xB8 | x); 00490 delay(); 00491 PORTC |= (1 << EN);//up 00492 delay(); 00493 PORTC &= ~(1 << EN);//down 00494 delay(); 00495 PORTC |= ((1 << EN) | (1 << R_W) |(1 << RS));//all high 00496 00497 delay(); 00498 00499 //Set y address to zero 00500 //set control lines 00501 PORTC &= ~((1 << EN) | (1 << R_W) | (1 << RS));//down 00502 00503 set_data(0x40); 00504 delay(); 00505 PORTC |= (1 << EN);//up 00506 delay(); 00507 PORTC &= ~(1 << EN);//down 00508 delay(); 00509 PORTC |= ((1 << EN) | (1 << R_W) | (1 << RS));//all high 00510 00511 set_data(0); 00512 00513 for (y = 0; y < 64; y++) 00514 { 00515 delay(); 00516 //y address increments after every write 00517 //write data, CS1, left half of screen 00518 PORTC &= ~((1 << EN) | (1 << R_W) | (1 << CS1));//down 00519 delay(); 00520 PORTC |= (1 << EN);//up 00521 delay(); 00522 PORTC &= ~(1 << EN);//down 00523 delay(); 00524 PORTC |= ((1 << EN) | (1 << R_W) | (1 << CS1));//all high 00525 00526 delay(); 00527 00528 //write data, CS2, right half of screen 00529 PORTC &= ~((1 << EN) | (1 << R_W) | (1 << CS2));//down 00530 delay(); 00531 PORTC |= (1 << EN);//up 00532 delay(); 00533 PORTC &= ~(1 << EN);//down 00534 delay(); 00535 PORTC |= ((1 << EN) | (1 << R_W) | (1 << CS2));//all high 00536 } 00537 00538 } 00539 00540 } 00541 00542 //sets horizontal position (data sheet calls this "y". Man, I just wanna punch these guys in the mouth...) 00543 void set_x(char x_spot) 00544 { 00545 //char a; 00546 00547 //a = x_spot; 00548 //if (a == 0) a = 63; 00549 //else a--; 00550 00551 if (x_spot == 0) x_spot = 63; 00552 else x_spot--; 00553 00554 PORTC &= ~((1 << EN) | (1 << R_W) | (1 << RS));//down 00555 00556 set_data(0x40 | x_spot); 00557 delay(); 00558 PORTC |= (1 << EN);//up 00559 delay(); 00560 PORTC &= ~(1 << EN);//down 00561 delay(); 00562 PORTC |= ((1 << EN) | (1 << R_W) | (1 << RS));//all high 00563 delay(); 00564 00565 } 00566 00567 00568 unsigned char print_char(char txt) 00569 { 00570 short text_array_offset = (txt - 32)*5, j; 00571 char k, temp; 00572 00573 /* 00574 if (txt == 10) 00575 { 00576 y_offset += 8; 00577 return(0); 00578 } 00579 00580 else if (txt == 13) 00581 { 00582 x_offset = 0; 00583 return(0); 00584 } 00585 */ 00586 00587 00588 for (j = text_array_offset; j < text_array_offset+6; j++) 00589 { 00590 if (x_offset >= 128) 00591 { 00592 x_offset = 0; 00593 page_mark++; 00594 set_page(page_mark); 00595 } 00596 00597 if (x_offset >= 64) 00598 { 00599 side_mark = 2; 00600 set_x(x_offset - 64); 00601 } 00602 else 00603 { 00604 side_mark = 1; 00605 set_x(x_offset); 00606 } 00607 00608 k = text_array[j]; 00609 //The bit patern is reversed in the GDM12864H display (the lookup table was made for the Nokia display) 00610 //Rather than rewrite the table, we cheat... 00611 temp = (((k & 1) << 7) | ((k & 2) << 5) | ((k & 4) << 3) | ((k & 8) << 1) | ((k & 16) >> 1) | ((k & 32) >> 3) | ((k & 64) >> 5) | ((k & 128) >> 7)); 00612 //temp = k; 00613 if (j == text_array_offset + 5) temp = 0;//blank byte for letter spacing 00614 write_byte(temp, side_mark); 00615 00616 x_offset++; 00617 00618 } 00619 00620 if ((x_offset + 6) > 128) 00621 { 00622 x_offset = 0; 00623 side_mark = 1; 00624 page_mark++; 00625 00626 if (page_mark >= 8) page_mark = 0; 00627 00628 set_page(page_mark); 00629 } 00630 00631 //else x_offset++; 00632 00633 /* 00634 if ((y_offset + 8) > 132) 00635 { 00636 //clear_screen(); 00637 return 1; 00638 } 00639 else return 0; 00640 */ 00641 00642 return 0; 00643 00644 } 00645 00646 00647 void set_page(char page) 00648 { 00649 //set control lines 00650 PORTC &= ~((1 << EN) | (1 << R_W) | (1 << RS));//down 00651 00652 set_data(0xB8 | page); 00653 delay(); 00654 PORTC |= (1 << EN);//up 00655 delay(); 00656 PORTC &= ~(1 << EN);//down 00657 delay(); 00658 PORTC |= ((1 << EN) | (1 << R_W) |(1 << RS));//all high 00659 00660 delay(); 00661 } 00662 00663 00664 void write_byte(char byte, char side) 00665 { 00666 PORTC |= (1 << RS);//make sure this thing is high 00667 set_data(byte); 00668 00669 delay(); 00670 //y address increments after every write 00671 //write data, CS1, left half of screen 00672 if (side == 1) PORTC &= ~((1 << EN) | (1 << R_W) | (1 << CS1));//down 00673 else if (side == 2) PORTC &= ~((1 << EN) | (1 << R_W) | (1 << CS2));//down 00674 delay(); 00675 PORTC |= (1 << EN);//up 00676 delay(); 00677 PORTC &= ~(1 << EN);//down 00678 delay(); 00679 PORTC |= ((1 << EN) | (1 << R_W) | (1 << CS1) | (1 << CS2));//all high 00680 00681 00682 } 00683 00684 00685 //display on 00686 void display_on(void) 00687 { 00688 set_data(0x3F); 00689 PORTC &= ~((1 << EN) | (1 << R_W) | (1 << RS));//down 00690 delay(); 00691 PORTC |= (1 << EN);//up 00692 delay(); 00693 PORTC &= ~(1 << EN);//down 00694 PORTC |= ((1 << EN) | (1 << R_W) | (1 << RS));//all high 00695 00696 } 00697 00698 //mapping to cartesian coordinates, (0,0) is in the lower left corner, (127,63) is in the upper right 00699 void pixel(char x, char y) 00700 { 00701 static char temp_page, temp_side, temp_x = 0, temp_data1 = 0, temp_data2 = 0; 00702 00703 if (x >= 64) temp_side = 2, temp_x = x - 64; 00704 else temp_side = 1, temp_x = x; 00705 00706 temp_page = 7 - (y >> 3); 00707 00708 //data = (1 << (y - ((7 - temp_page) * 8))); 00709 temp_data1 = (1 << (7 - (y - ((7 - temp_page) * 8)))); 00710 00711 set_page(temp_page); 00712 set_x(temp_x); 00713 //set_x(0); 00714 00715 //need to read the existing byte here, then or it with the new byte 00716 temp_data2 = read_byte(temp_x, temp_side); 00717 00718 temp_data1 |= temp_data2; 00719 00720 set_x(temp_x);//reset this... 00721 00722 write_byte(temp_data1, temp_side); 00723 00724 } 00725 00726 //y = mx + b 00727 void line(char x1, char y1, char x2, char y2) 00728 { 00729 float m; 00730 char a, b; 00731 00732 m = (float)(y2 - y1) / (float)(x2 - x1); 00733 00734 b = y1-(m*x1); 00735 00736 for (a = x1; a <= x2; a++) 00737 { 00738 pixel(a, (char)((m*a)+b)); 00739 //delay_ms(25); 00740 } 00741 00742 } 00743 00744 00745 char read_byte(char byte, char side) 00746 { 00747 char data1 = 0, data2 = 0; 00748 00749 if (byte == 0) byte = 63; 00750 else byte--; 00751 00752 set_x(byte); 00753 00754 PORTC |= ((1 << RESET) | (1 << EN) | (1 << R_W) | (1 << CS1) | (1 << CS2) | (1 << RS));//all high, just to make sure 00755 00756 DDRB = 0;//all inputs 00757 DDRD = 0; 00758 00759 //PORTB |= 0x03;//pullups...? 00760 //PORTD |= 0XFC; 00761 //PORTB = 0; 00762 //PORTD = 0; 00763 00764 delay(); 00765 delay(); 00766 00767 if (side == 1) PORTC &= ~((1 << EN) | (1 << CS1));//down 00768 else if (side == 2) PORTC &= ~((1 << EN) | (1 << CS2));//down 00769 //PORTC &= ~((1 << EN) | (1 << CS1));//down 00770 00771 00772 00773 delay(); 00774 delay(); 00775 PORTC |= (1 << EN);//up 00776 00777 00778 delay(); 00779 delay(); 00780 00781 /* 00782 data1 = PINB; 00783 data1 &= 0x03; 00784 00785 data2 = PIND; 00786 data2 &= 0xFC; 00787 00788 data1 |= data2; 00789 */ 00790 00791 PORTC &= ~(1 << EN);//down 00792 00793 00794 00795 delay(); 00796 delay(); 00797 00798 PORTC |= ((1 << RESET) | (1 << EN) | (1 << R_W) | (1 << CS1) | (1 << CS2) | (1 << RS));//all high 00799 00800 //DDRB = 0b00000011; //PB0 and PB1 are outs 00801 //DDRD = 0b11111100; //PD2-PD7 are also outs. Ports B and D are the data bus. 00802 00803 00804 00805 delay(); 00806 delay(); 00807 00808 //PORTC &= ~((1 << EN) | (1 << CS1));//down 00809 if (side == 1) PORTC &= ~((1 << EN) | (1 << CS1));//down 00810 else if (side == 2) PORTC &= ~((1 << EN) | (1 << CS2));//down 00811 00812 00813 00814 delay(); 00815 delay(); 00816 PORTC |= (1 << EN);//up 00817 00818 //we can read here... 00819 00820 delay(); 00821 delay(); 00822 data1 = PINB; 00823 data1 &= 0x03; 00824 00825 data2 = PIND; 00826 data2 &= 0xFC; 00827 00828 data1 |= data2; 00829 //while(1); 00830 00831 PORTC &= ~(1 << EN);//down 00832 00833 //cannot read here... 00834 //while(1); 00835 00836 PORTC |= ((1 << RESET) | (1 << EN) | (1 << R_W) | (1 << CS1) | (1 << CS2) | (1 << RS));//all high 00837 00838 DDRB = 0b00000011; //PB0 and PB1 are outs 00839 DDRD = 0b11111100; //PD2-PD7 are also outs. Ports B and D are the data bus. 00840 00841 delay(); 00842 00843 return data1; 00844 00845 } 00846 00847 00848 00849