frederic blanc
/
sp5gfx1
Lascar Electronics SP 5-GFX1 DISPLAY, LCD GRAPHIC, 128 X 64 DOTS
graphic.c@0:2052f61477b1, 2011-07-06 (annotated)
- Committer:
- fblanc
- Date:
- Wed Jul 06 12:06:40 2011 +0000
- Revision:
- 0:2052f61477b1
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
fblanc | 0:2052f61477b1 | 1 | // Wy�wietlacz graficzny ze sterownikiem S6B0724 |
fblanc | 0:2052f61477b1 | 2 | // sterowanie w jezyku C od podstaw |
fblanc | 0:2052f61477b1 | 3 | // Plik : graphic.c |
fblanc | 0:2052f61477b1 | 4 | // Autor : Rados�aw Kwiecie� |
fblanc | 0:2052f61477b1 | 5 | |
fblanc | 0:2052f61477b1 | 6 | #include "SPLC501C.h" |
fblanc | 0:2052f61477b1 | 7 | |
fblanc | 0:2052f61477b1 | 8 | void GLCD_Rectangle(unsigned char x, unsigned char y, unsigned char b, unsigned char a , char color) { |
fblanc | 0:2052f61477b1 | 9 | unsigned char j; // zmienna pomocnicza |
fblanc | 0:2052f61477b1 | 10 | // rysowanie linii pionowych (boki) |
fblanc | 0:2052f61477b1 | 11 | for (j = 0; j < a; j++) { |
fblanc | 0:2052f61477b1 | 12 | GLCD_SetPixel(x, y + j, color); |
fblanc | 0:2052f61477b1 | 13 | GLCD_SetPixel(x + b - 1, y + j, color); |
fblanc | 0:2052f61477b1 | 14 | } |
fblanc | 0:2052f61477b1 | 15 | // rysowanie linii poziomych (podstawy) |
fblanc | 0:2052f61477b1 | 16 | for (j = 0; j < b; j++) { |
fblanc | 0:2052f61477b1 | 17 | GLCD_SetPixel(x + j, y, color); |
fblanc | 0:2052f61477b1 | 18 | GLCD_SetPixel(x + j, y + a - 1, color); |
fblanc | 0:2052f61477b1 | 19 | } |
fblanc | 0:2052f61477b1 | 20 | } |
fblanc | 0:2052f61477b1 | 21 | |
fblanc | 0:2052f61477b1 | 22 | |
fblanc | 0:2052f61477b1 | 23 | void GLCD_Circle(unsigned char cx, unsigned char cy ,unsigned char radius , char color) { |
fblanc | 0:2052f61477b1 | 24 | int x, y, xchange, ychange, radiusError; |
fblanc | 0:2052f61477b1 | 25 | x = radius; |
fblanc | 0:2052f61477b1 | 26 | y = 0; |
fblanc | 0:2052f61477b1 | 27 | xchange = 1 - 2 * radius; |
fblanc | 0:2052f61477b1 | 28 | ychange = 1; |
fblanc | 0:2052f61477b1 | 29 | radiusError = 0; |
fblanc | 0:2052f61477b1 | 30 | while (x >= y) { |
fblanc | 0:2052f61477b1 | 31 | GLCD_SetPixel(cx+x, cy+y, color); |
fblanc | 0:2052f61477b1 | 32 | GLCD_SetPixel(cx-x, cy+y, color); |
fblanc | 0:2052f61477b1 | 33 | GLCD_SetPixel(cx-x, cy-y, color); |
fblanc | 0:2052f61477b1 | 34 | GLCD_SetPixel(cx+x, cy-y, color); |
fblanc | 0:2052f61477b1 | 35 | GLCD_SetPixel(cx+y, cy+x, color); |
fblanc | 0:2052f61477b1 | 36 | GLCD_SetPixel(cx-y, cy+x, color); |
fblanc | 0:2052f61477b1 | 37 | GLCD_SetPixel(cx-y, cy-x, color); |
fblanc | 0:2052f61477b1 | 38 | GLCD_SetPixel(cx+y, cy-x, color); |
fblanc | 0:2052f61477b1 | 39 | y++; |
fblanc | 0:2052f61477b1 | 40 | radiusError += ychange; |
fblanc | 0:2052f61477b1 | 41 | ychange += 2; |
fblanc | 0:2052f61477b1 | 42 | if ( 2*radiusError + xchange > 0 ) { |
fblanc | 0:2052f61477b1 | 43 | x--; |
fblanc | 0:2052f61477b1 | 44 | radiusError += xchange; |
fblanc | 0:2052f61477b1 | 45 | xchange += 2; |
fblanc | 0:2052f61477b1 | 46 | } |
fblanc | 0:2052f61477b1 | 47 | } |
fblanc | 0:2052f61477b1 | 48 | } |
fblanc | 0:2052f61477b1 | 49 | |
fblanc | 0:2052f61477b1 | 50 | |
fblanc | 0:2052f61477b1 | 51 | void GLCD_Line(int X1, int Y1,int X2,int Y2 , char color) { |
fblanc | 0:2052f61477b1 | 52 | int CurrentX, CurrentY, Xinc, Yinc, |
fblanc | 0:2052f61477b1 | 53 | Dx, Dy, TwoDx, TwoDy, |
fblanc | 0:2052f61477b1 | 54 | TwoDxAccumulatedError, TwoDyAccumulatedError; |
fblanc | 0:2052f61477b1 | 55 | |
fblanc | 0:2052f61477b1 | 56 | Dx = (X2-X1); // obliczenie sk�adowej poziomej |
fblanc | 0:2052f61477b1 | 57 | Dy = (Y2-Y1); // obliczenie sk�adowej pionowej |
fblanc | 0:2052f61477b1 | 58 | |
fblanc | 0:2052f61477b1 | 59 | TwoDx = Dx + Dx; // podwojona sk�adowa pozioma |
fblanc | 0:2052f61477b1 | 60 | TwoDy = Dy + Dy; // podwojona sk�adowa pionowa |
fblanc | 0:2052f61477b1 | 61 | |
fblanc | 0:2052f61477b1 | 62 | CurrentX = X1; // zaczynamy od X1 |
fblanc | 0:2052f61477b1 | 63 | CurrentY = Y1; // oraz Y1 |
fblanc | 0:2052f61477b1 | 64 | |
fblanc | 0:2052f61477b1 | 65 | Xinc = 1; // ustalamy krok zwi�kszania pozycji w poziomie |
fblanc | 0:2052f61477b1 | 66 | Yinc = 1; // ustalamy krok zwi�kszania pozycji w pionie |
fblanc | 0:2052f61477b1 | 67 | |
fblanc | 0:2052f61477b1 | 68 | if (Dx < 0) { // jesli sk�adowa pozioma jest ujemna |
fblanc | 0:2052f61477b1 | 69 | Xinc = -1; // to b�dziemy si� "cofa�" (krok ujemny) |
fblanc | 0:2052f61477b1 | 70 | Dx = -Dx; // zmieniamy znak sk�adowej na dodatni |
fblanc | 0:2052f61477b1 | 71 | TwoDx = -TwoDx; // jak r�wnie� podwojonej sk�adowej |
fblanc | 0:2052f61477b1 | 72 | } |
fblanc | 0:2052f61477b1 | 73 | |
fblanc | 0:2052f61477b1 | 74 | if (Dy < 0) { // je�li sk�adowa pionowa jest ujemna |
fblanc | 0:2052f61477b1 | 75 | Yinc = -1; // to b�dziemy si� "cofa�" (krok ujemny) |
fblanc | 0:2052f61477b1 | 76 | Dy = -Dy; // zmieniamy znak sk�adowej na dodatki |
fblanc | 0:2052f61477b1 | 77 | TwoDy = -TwoDy; // jak r�wniez podwojonej sk�adowej |
fblanc | 0:2052f61477b1 | 78 | } |
fblanc | 0:2052f61477b1 | 79 | |
fblanc | 0:2052f61477b1 | 80 | GLCD_SetPixel(X1,Y1, color); // stawiamy pierwszy krok (zapalamy pierwszy piksel) |
fblanc | 0:2052f61477b1 | 81 | |
fblanc | 0:2052f61477b1 | 82 | if ((Dx != 0) || (Dy != 0)) { // sprawdzamy czy linia sk�ada si� z wi�cej ni� jednego punktu ;) |
fblanc | 0:2052f61477b1 | 83 | // sprawdzamy czy sk�adowa pionowa jest mniejsza lub r�wna sk�adowej poziomej |
fblanc | 0:2052f61477b1 | 84 | if (Dy <= Dx) { // je�li tak, to idziemy "po iksach" |
fblanc | 0:2052f61477b1 | 85 | TwoDxAccumulatedError = 0; // zerujemy zmienn� |
fblanc | 0:2052f61477b1 | 86 | do { // ruszamy w drog� |
fblanc | 0:2052f61477b1 | 87 | CurrentX += Xinc; // do aktualnej pozycji dodajemy krok |
fblanc | 0:2052f61477b1 | 88 | TwoDxAccumulatedError += TwoDy; // a tu dodajemy podwojon� sk�adow� pionow� |
fblanc | 0:2052f61477b1 | 89 | if (TwoDxAccumulatedError > Dx) { // je�li TwoDxAccumulatedError jest wi�kszy od Dx |
fblanc | 0:2052f61477b1 | 90 | CurrentY += Yinc; // zwi�kszamy aktualn� pozycj� w pionie |
fblanc | 0:2052f61477b1 | 91 | TwoDxAccumulatedError -= TwoDx; // i odejmujemy TwoDx |
fblanc | 0:2052f61477b1 | 92 | } |
fblanc | 0:2052f61477b1 | 93 | GLCD_SetPixel(CurrentX,CurrentY, color);// stawiamy nast�pny krok (zapalamy piksel) |
fblanc | 0:2052f61477b1 | 94 | } while (CurrentX != X2); // idziemy tak d�ugo, a� osi�gniemy punkt docelowy |
fblanc | 0:2052f61477b1 | 95 | } else { // w przeciwnym razie idziemy "po igrekach" |
fblanc | 0:2052f61477b1 | 96 | TwoDyAccumulatedError = 0; |
fblanc | 0:2052f61477b1 | 97 | do { |
fblanc | 0:2052f61477b1 | 98 | CurrentY += Yinc; |
fblanc | 0:2052f61477b1 | 99 | TwoDyAccumulatedError += TwoDx; |
fblanc | 0:2052f61477b1 | 100 | if (TwoDyAccumulatedError>Dy) { |
fblanc | 0:2052f61477b1 | 101 | CurrentX += Xinc; |
fblanc | 0:2052f61477b1 | 102 | TwoDyAccumulatedError -= TwoDy; |
fblanc | 0:2052f61477b1 | 103 | } |
fblanc | 0:2052f61477b1 | 104 | GLCD_SetPixel(CurrentX,CurrentY, color); |
fblanc | 0:2052f61477b1 | 105 | } while (CurrentY != Y2); |
fblanc | 0:2052f61477b1 | 106 | } |
fblanc | 0:2052f61477b1 | 107 | } |
fblanc | 0:2052f61477b1 | 108 | } |