📄 lcd.lst
字号:
304 =======================================================*/
305 void GUI_Image( IMAGE *pImage )
306 {
307 1 INT8U x, y;
308 1 INT16U datacount = 0;
309 1 LCDSetArea( pImage->xs, pImage->ys, pImage->xs + pImage->length - 1, pImage->ys + pImage->height - 1 )
-;
310 1
311 1 for( x = 0; x < pImage->length; x ++ )
312 1 {
313 2 for( y = 0; y < pImage->height; y ++ )
314 2 {
315 3 LCDWR( LCDDAT, *( pImage->pData + datacount++ ) );
316 3 LCDWR( LCDDAT, *( pImage->pData + datacount++ ) );
317 3 }
318 2 }
319 1 }
320
321
322
323
324 void GUI_DrawRectangle( RECT* pRect ) //矩形
325 {
326 1 LINE line;
327 1
328 1 line.xs = pRect->xs;
329 1 line.xe = pRect->xe;
330 1 line.ys = pRect->ys;
331 1 line.ye = pRect->ys;
332 1 line.Color = pRect->Color;
333 1 LCDDrawHRLine( &line );
334 1
335 1 line.xe = pRect->xs;
336 1 line.ye = pRect->ye;
337 1 LCDDrawHRLine( &line );
338 1
339 1 line.xs = pRect->xe;
340 1 line.ys = pRect->ye;
341 1 LCDDrawHRLine( &line );
342 1
343 1 line.xe = pRect->xe;
344 1 line.ye = pRect->ys;
345 1 LCDDrawHRLine( &line );
346 1 }
347
348 /*================================================================================
349 画直线
350 ================================================================================*/
351 void GUI_DrawLine( LINE* pLine )
352 {
353 1 INT32S dx; // 直线x轴差值变量
354 1 INT32S dy; // 直线y轴差值变量
355 1 INT32S dx_sym; // x轴增长方向,为-1时减值方向,为1时增值方向
356 1 INT32S dy_sym; // y轴增长方向,为-1时减值方向,为1时增值方向
357 1 INT32S dx_x2; // dx*2值变量,用于加快运算速度
358 1 INT32S dy_x2; // dy*2值变量,用于加快运算速度
359 1 INT32S di; // 决策变量
360 1
C51 COMPILER V9.00 LCD 08/26/2012 13:41:40 PAGE 7
361 1 POINT point;
362 1 LINE line;
363 1
364 1 line.xs = pLine->xs;
365 1 line.ys = pLine->ys;
366 1 line.xe = pLine->xe;
367 1 line.ye = pLine->ye;
368 1 line.Color = pLine->Color;
369 1
370 1 point.Color = pLine->Color;
371 1
372 1 dx = line.xe - line.xs;
373 1 dy = line.ye - line.ys;
374 1
375 1 /* 判断增长方向,或是否为水平线、垂直线、点 */
376 1 if( dx > 0 ) // 判断x轴方向
377 1 {
378 2 dx_sym = 1; // dx>0,设置dx_sym=1
379 2 }
380 1 else
381 1 {
382 2 if( dx < 0 )
383 2 {
384 3 dx_sym = -1; // dx<0,设置dx_sym=-1
385 3 }
386 2 else
387 2 {
388 3 LCDDrawHRLine( &line );
389 3 return;
390 3 }
391 2 }
392 1
393 1 if( dy > 0 ) // 判断y轴方向
394 1 {
395 2 dy_sym = 1; // dy>0,设置dy_sym=1
396 2 }
397 1 else
398 1 {
399 2 if( dy < 0 )
400 2 {
401 3 dy_sym = -1; // dy<0,设置dy_sym=-1
402 3 }
403 2 else
404 2 { // dy==0,画水平线,或一点
405 3 LCDDrawHRLine( &line );
406 3 return;
407 3 }
408 2 }
409 1
410 1 /* 将dx、dy取绝对值 */
411 1 dx = dx_sym * dx;
412 1 dy = dy_sym * dy;
413 1
414 1 /* 计算2倍的dx及dy值 */
415 1 dx_x2 = dx*2;
416 1 dy_x2 = dy*2;
417 1
418 1 /* 使用Bresenham法进行画直线 */
419 1 if( dx >= dy ) // 对于dx>=dy,则使用x轴为基准
420 1 {
421 2 di = dy_x2 - dx;
422 2 while( line.xs != line.xe )
C51 COMPILER V9.00 LCD 08/26/2012 13:41:40 PAGE 8
423 2 {
424 3 point.x = line.xs;
425 3 point.y = line.ys;
426 3 LCDDrawPoint( &point );
427 3 line.xs += dx_sym;
428 3 if( di < 0 )
429 3 {
430 4 di += dy_x2; // 计算出下一步的决策值
431 4 }
432 3 else
433 3 {
434 4 di += dy_x2 - dx_x2;
435 4 line.ys += dy_sym;
436 4 }
437 3 }
438 2 LCDDrawPoint( &point ); // 显示最后一点
439 2 }
440 1 else // 对于dx<dy,则使用y轴为基准
441 1 {
442 2 di = dx_x2 - dy;
443 2 while( line.ys != line.ye )
444 2 {
445 3 point.x = line.xs;
446 3 point.y = line.ys;
447 3 LCDDrawPoint( &point );
448 3 line.ys += dy_sym;
449 3 if(di<0)
450 3 {
451 4 di += dx_x2;
452 4 }
453 3 else
454 3 {
455 4 di += dx_x2 - dy_x2;
456 4 line.xs += dx_sym;
457 4 }
458 3 }
459 2 LCDDrawPoint( &point ); // 显示最后一点
460 2 }
461 1 }
462
463 /*================================================================================
464 填充显示的子函数
465 ================================================================================*/
466 void GUI_DisplayFont( INT8U Xs, INT8U Ys, FONT* pFont, char Character )
467 {
468 1 BitBlock Block;
469 1 INT32U Bytes;
470 1 INT8U DataBuffer[64];
471 1 INT8U i;
472 1 const unsigned char *offset;
473 1
474 1 Block.Height = pFont->Height;
475 1 Block.Width = pFont->Width;
476 1 Block.Color = pFont->Color;
477 1 Block.BackColor = pFont->BackColor;
478 1 Block.xs = Xs;
479 1 Block.ys = Ys;
480 1
481 1 Bytes = pFont->Width >> 3;
482 1 if( pFont->Width & 0x07 )
483 1 {
484 2 Bytes ++;
C51 COMPILER V9.00 LCD 08/26/2012 13:41:40 PAGE 9
485 2 }
486 1 Bytes *= pFont->Height;
487 1 Bytes *= Character - ' ';
488 1 //offset = (const unsigned char*)&FontLib_14;
489 1 /*
490 1 if( pFont->Height == 18 )
491 1 {
492 1 offset = (const unsigned char*)&FontLib_18;
493 1 }
494 1 else if( pFont->Height == 14 )
495 1 {
496 1 offset = (const unsigned char*)&FontLib_14;
497 1 }
498 1 else
499 1 {
500 1 return;
501 1 }
502 1 */
503 1 offset += Bytes;
504 1 for( i = 0; i < 36; i ++ )
505 1 {
506 2 DataBuffer[i] = *( offset + i );
507 2 }
508 1
509 1
510 1 Block.pData = DataBuffer;
511 1
512 1 PrintBitBlock( &Block );
513 1 }
514 /*
515 ========================================================================================================
516 Name: DisplayStr
517 Function: Display a character at a special area
518 Input:
519 1.Xs : Start position X
520 2.Ys : Start position Y
521 3.pFont : A pointer of a font structure
522 4.Str : The start address of a string
523 Output: None
524 Note: The start position is inputted as a parameter, And the end position is calculated by the FONT
525 structure.
526 Author: LiYong
527 Date : 2008.08.09
528 ========================================================================================================
529 */
530 /*================================================================================
531 填充显示
532 ================================================================================*/
533 void GUI_DisplayStr( INT8U xs, INT8U ys, FONT* pFont, char* Str )
534 {
535 1 while( *Str )
536 1 {
537 2 GUI_DisplayFont( xs, ys, pFont, *Str );
538 2 Str ++;
539 2 xs += pFont->Width;
540 2 }
541 1 }
542
543 /*================================================================================
544 画空心的圆
545 ================================================================================*/
546 /*void GUI_DrawCircle( CIRCLE* pCircle )
C51 COMPILER V9.00 LCD 08/26/2012 13:41:40 PAGE 10
547 {
548 INT8S draw_x0, draw_y0; // 刽图点坐标变量
549 INT8S draw_x1, draw_y1;
550 INT8S draw_x2, draw_y2;
551 INT8S draw_x3, draw_y3;
552 INT8S draw_x4, draw_y4;
553 INT8S draw_x5, draw_y5;
554 INT8S draw_x6, draw_y6;
555 INT8S draw_x7, draw_y7;
556 INT8S xx, yy; // 画圆控制变量
557
558 INT8S di; // 决策变量
559 POINT point;
560
561 point.Color = pCircle->Color;
562
563 // 参数过滤
564 if(0 == pCircle->r ) return;
565
566 // 计算出8个特殊点(0、45、90、135、180、225、270度),进行显示
567 point.x = draw_x0 = draw_x1 = pCircle->x;
568 point.y = draw_y0 = draw_y1 = pCircle->y + pCircle->r;
569
570 if( draw_y0 < GUI_LCM_YMAX ) LCDDrawPoint( &point ); // 90度
571
572 point.x = draw_x2 = draw_x3 = pCircle->x;
573 point.y = draw_y2 = draw_y3 = pCircle->y - pCircle->r;
574 if( draw_y2 >= 0 ) LCDDrawPoint( &point ); // 270度
575
576
577 point.x = draw_x4 = draw_x6 = pCircle->x + pCircle->r;
578 point.y = draw_y4 = draw_y6 = pCircle->y;
579 if(draw_x4<GUI_LCM_XMAX) LCDDrawPoint( &point ); // 0度
580
581 point.x = draw_x5 = draw_x7 = pCircle->x - pCircle->r;
582 point.y = draw_y5 = draw_y7 = pCircle->y;
583 if(draw_x5>=0) LCDDrawPoint( &point ); // 180度
584 if(1==pCircle->r) return; // 若半径为1,则已圆画完
585
586
587 //使用Bresenham法进行画圆
588 di = 3 - 2*pCircle->r; // 初始化决策变量
589
590 xx = 0;
591 yy = pCircle->r;
592 while(xx<yy)
593 { if(di<0)
594 { di += 4*xx + 6;
595 }
596 else
597 { di += 4*(xx - yy) + 10;
598
599 yy--;
600 draw_y0--;
601 draw_y1--;
602 draw_y2++;
603 draw_y3++;
604 draw_x4--;
605 draw_x5++;
606 draw_x6--;
607 draw_x7++;
608 }
C51 COMPILER V9.00 LCD 08/26/2012 13:41:40 PAGE 11
609
610 xx++;
611 draw_x0++;
612 draw_x1--;
613 draw_x2++;
614 draw_x3--;
615 draw_y4++;
616 draw_y5++;
617 draw_y6--;
618 draw_y7--;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -