<?xml version="1.0" encoding="UTF-8"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="pl-pl">
<link rel="self" type="application/atom+xml" href="https://forum.atnel.pl/feed.php?f=24&amp;t=8226&amp;mode" />

<title>ATNEL tech-forum</title>
<link href="https://forum.atnel.pl/index.php" />
<updated>2014-08-22T21:54:36+01:00</updated>

<author><name><![CDATA[ATNEL tech-forum]]></name></author>
<id>https://forum.atnel.pl/feed.php?f=24&amp;t=8226&amp;mode</id>
<entry>
<author><name><![CDATA[chabov]]></name></author>
<updated>2014-08-22T21:54:36+01:00</updated>
<published>2014-08-22T21:54:36+01:00</published>
<id>https://forum.atnel.pl/viewtopic.php?t=8226&amp;p=92520#p92520</id>
<link href="https://forum.atnel.pl/viewtopic.php?t=8226&amp;p=92520#p92520"/>
<title type="html"><![CDATA[Re: Wyświetlacz ST7735 - problem]]></title>

<content type="html" xml:base="https://forum.atnel.pl/viewtopic.php?t=8226&amp;p=92520#p92520"><![CDATA[
Temat można zamknąć. <br />Podłączenie rozgryzione. <br />Współpracuje wraz z DHT11 i pięknie działa.<br /><br /><a href="http://forum.atnel.pl/_obrazki/o/3703/3221404139cfa8d5fd9446241847413b.jpg"  class="postlink"><img src="http://forum.atnel.pl/_obrazki/o/thumb/3703/3221404139cfa8d5fd9446241847413b.jpg" alt="Obrazek" /></a><p>Statystyki: Napisane przez <a href="https://forum.atnel.pl/memberlist.php?mode=viewprofile&amp;u=3703">chabov</a> — 22 sie 2014, o 21:54</p><hr />
]]></content>
</entry>
<entry>
<author><name><![CDATA[Krauser]]></name></author>
<updated>2014-08-22T21:44:29+01:00</updated>
<published>2014-08-22T21:44:29+01:00</published>
<id>https://forum.atnel.pl/viewtopic.php?t=8226&amp;p=92517#p92517</id>
<link href="https://forum.atnel.pl/viewtopic.php?t=8226&amp;p=92517#p92517"/>
<title type="html"><![CDATA[Re: Wyświetlacz ST7735 - problem]]></title>

<content type="html" xml:base="https://forum.atnel.pl/viewtopic.php?t=8226&amp;p=92517#p92517"><![CDATA[
Kolega PawelGaj udostępnił bibliotekę do tego TFT Zresztą widzę, że tam również pytałeś.<br />[syntax=c]// Podlaczenie LCD<br /><br />//RESET <br />#define ST7735_RES_PIN          3   <br />#define ST7735_RES_PORT         B<br /><br />//A0 <br />#define ST7735_RS_PIN           2  <br />#define ST7735_RS_PORT          B<br /><br />//CS <br />#define ST7735_CS_PIN           4  <br />#define ST7735_CS_PORT          B<br /><br />//SDA <br />#define ST7735_MOSI_PIN         5 <br />#define ST7735_MOSI_PORT        B<br /><br />//SCK <br />#define ST7735_SCK_PIN          7 <br />#define ST7735_SCK_PORT         B[/syntax]<br /><br />Należy jeszcze podłączyć VCC i GND. Tutaj parę uwag. Wyświetlacz może być zasilony z 5V jak zworka JP1 jest otwarta, ale interfejs i tak jest na 3,3V. Dlatego w takim przypadku jak mikrokontroler jest zasilony z 5V należy jeszcze wstawić układ 74LVC125 zasilony z 3,3V. Druga opcja to zasilić TFT z 3,3V ze zworką JP1 zwartą i mikrokontroler również z 3,3V, a wtedy 74LVC125 nie jest potrzebny.<br />Podświetlenie LED+ i LED- też należy zasilić jak diodę LED przez rezystor 220R.<p>Statystyki: Napisane przez <a href="https://forum.atnel.pl/memberlist.php?mode=viewprofile&amp;u=465">Krauser</a> — 22 sie 2014, o 21:44</p><hr />
]]></content>
</entry>
<entry>
<author><name><![CDATA[chabov]]></name></author>
<updated>2014-08-22T18:05:27+01:00</updated>
<published>2014-08-22T18:05:27+01:00</published>
<id>https://forum.atnel.pl/viewtopic.php?t=8226&amp;p=92469#p92469</id>
<link href="https://forum.atnel.pl/viewtopic.php?t=8226&amp;p=92469#p92469"/>
<title type="html"><![CDATA[Re: Wyświetlacz ST7735 - problem]]></title>

<content type="html" xml:base="https://forum.atnel.pl/viewtopic.php?t=8226&amp;p=92469#p92469"><![CDATA[
Poprawione...<p>Statystyki: Napisane przez <a href="https://forum.atnel.pl/memberlist.php?mode=viewprofile&amp;u=3703">chabov</a> — 22 sie 2014, o 18:05</p><hr />
]]></content>
</entry>
<entry>
<author><name><![CDATA[chabov]]></name></author>
<updated>2014-08-22T17:55:22+01:00</updated>
<published>2014-08-21T22:15:44+01:00</published>
<id>https://forum.atnel.pl/viewtopic.php?t=8226&amp;p=92382#p92382</id>
<link href="https://forum.atnel.pl/viewtopic.php?t=8226&amp;p=92382#p92382"/>
<title type="html"><![CDATA[Wyświetlacz ST7735 - problem]]></title>

<content type="html" xml:base="https://forum.atnel.pl/viewtopic.php?t=8226&amp;p=92382#p92382"><![CDATA[
Witajcie!<br /><br />Mam problem z uruchomieniem wyświetlacza TFT na bazie sterownika ST7735.<br />Fota wyświetlacza poniżej:<br /><br /><a href="http://forum.atnel.pl/_obrazki/o/3703/da2f1cc2dbe9ebbce578e7beec89faa7.jpg"  class="postlink"><img src="http://forum.atnel.pl/_obrazki/o/thumb/3703/da2f1cc2dbe9ebbce578e7beec89faa7.jpg" alt="Obrazek" /></a><br /><br />Opieram się na instrukcji spod adresu: <!-- m --><a class="postlink" href="http://w8bh.net/avr/AvrTFT.pdf" >http://w8bh.net/avr/AvrTFT.pdf</a><!-- m --><br /><br />[syntax=c]/*<br />-----------------------------------------------------------------------------<br />//<br />TFT: Experiments interfacing ATmega328 to an ST7735 1.8&quot;<br />LCD TFT display<br />//<br />// Author : Bruce E. Hall &lt;bhall66@gmail.com&gt;<br />//Website : w8bh.net<br />// Version : 1.0<br />// Date : 04 May 2014<br />// Target : ATmega328P microcontroller<br />// Language : C, using AVR studio 6<br />// Size: 3622 bytes<br />//<br />//Fuse settings: 8 MHz osc with 65 ms Delay, SPI enable; *NO* clock/8<br />//<br />// Connections from LCD to DC Boarduino:<br />//<br />// TFT pin 1 (backlight) +5V<br />// TFT pin 2 (MISO) n/c<br />// TFT pin 3 (SCK) digital13, PB5(SCK)<br />// TFT pin 4(MOSI) digital11, PB3(MOSI)<br />// TFT pin 5 (TFT_Select) gnd<br />// TFT pin 7 (DC) digital9, PB1<br />// TFT pin 8 (Reset) digital8, PB0<br />// TFT pin 9 (Vcc) +5V<br />// TFT pin 10 (gnd) gnd<br />//<br />//<br />------<br />---------------------------------------------------------------------<br />//<br />GLOBAL DEFINES*/<br />//#define F_CPU 16000000L // run CPU at 16 MHz<br />#define LED 5<br />#define ClearBit(x,y) x &amp;= ~_BV(y)// equivalent to cbi(x,y)<br />#define SetBit(x,y) x|=_BV(y)<br /><br />#include &lt;avr/io.h&gt;// deal with port registers<br />#include &lt;avr/interrupt.h&gt;// deal with interrupt calls<br />#include &lt;avr/pgmspace.h&gt;// put character data into progmem<br />#include &lt;util/delay.h&gt;// used for _delay_ms function<br />#include &lt;string.h&gt;//string manipulation routines<br />#include &lt;avr/sleep.h&gt;// used for sleep functions<br />#include &lt;stdlib.h&gt;<br /><br />typedef uint8_t byte;// I just like byte &amp; sbyte better<br />typedef int8_t sbyte;<br /><br />const byte FONT_CHARS&#91;96&#93;&#91;5&#93; PROGMEM =<br />{<br />{0x00,0x00,0x00,0x00,0x00},<br />{0x00,0x00,0x5F,0x00,0x00},<br />{0x00,0x07,0x00,0x07,0x00},<br />{0x14,0x7F,0x14,0x7F,0x14},// #<br />{0x24,0x2A,0x7F,0x2A,0x12},// $<br />{0x23,0x13,0x08,0x64,0x62},// %<br />{0x36,0x49,0x55,0x22,0x50},// &amp;<br />{0x00,0x05,0x03,0x00,0x00},// '<br />{0x00,0x1C,0x22,0x41,0x00},// (<br />{0x00,0x41,0x22,0x1C,0x00},// )<br />{0x08,0x2A,0x1C,0x2A,0x08},// *<br />{0x08,0x08,0x3E,0x08,0x08},// +<br />{0x00,0x50,0x30,0x00,0x00},// ,<br />{0x08,0x08,0x08,0x08,0x08},//-<br />{0x00,0x60,0x60,0x00,0x00},// .<br />{0x20,0x10,0x08,0x04,0x02},// /<br />{0x3E,0x51,0x49,0x45,0x3E},// 0<br />{0x00,0x42,0x7F,0x40,0x00},// 1<br />{0x42,0x61,0x51,0x49,0x46},// 2<br />{0x21,0x41,0x45,0x4B,0x31},// 3<br />{0x18,0x14,0x12,0x7F,0x10},// 4<br />{0x27,0x45,0x45,0x45,0x39},// 5<br />{0x3C,0x4A,0x49,0x49,0x30},// 6<br />{0x01,0x71,0x09,0x05,0x03},// 7<br />{0x36,0x49,0x49,0x49,0x36},// 8<br />{0x06,0x49,0x49,0x29,0x1E},// 9<br />{0x00,0x36,0x36,0x00,0x00},// :<br />{0x00,0x56,0x36,0x00,0x00},// ;<br />{0x00,0x08,0x14,0x22,0x41},// &lt;<br />{0x14,0x14,0x14,0x14,0x14},// =<br />{0x41,0x22,0x14,0x08,0x00},//&gt;<br />{0x02,0x01,0x51,0x09,0x06},// ?<br />{0x32,0x49,0x79,0x41,0x3E},// @<br />{0x7E,0x11,0x11,0x11,0x7E},// A<br />{0x7F,0x49,0x49,0x49,0x36},// B<br />{0x3E,0x41,0x41,0x41,0x22},// C<br />{0x7F,0x41,0x41,0x22,0x1C},// D<br />{0x7F,0x49,0x49,0x49,0x41},// E<br />{0x7F,0x09,0x09,0x01,0x01},// F<br />{0x3E,0x41,0x41,0x51,0x32},// G<br />{0x7F,0x08,0x08,0x08,0x7F},// H<br />{0x00,0x41,0x7F,0x41,0x00},// I<br />{0x20,0x40,0x41,0x3F,0x01},// J<br />{0x7F,0x08,0x14,0x22,0x41},// K<br />{0x7F,0x40,0x40,0x40,0x40},// L<br />{0x7F,0x02,0x04,0x02,0x7F},// M<br />{0x7F,0x04,0x08,0x10,0x7F},// N<br />{0x3E,0x41,0x41,0x41,0x3E},// O<br />{0x7F,0x09,0x09,0x09,0x06},// P<br />{0x3E,0x41,0x51,0x21,0x5E},// Q<br />{0x7F,0x09,0x19,0x29,0x46},// R<br />{0x46,0x49,0x49,0x49,0x31},// S<br />{0x01,0x01,0x7F,0x01,0x01},// T<br />{0x3F,0x40,0x40,0x40,0x3F},// U<br />{0x1F,0x20,0x40,0x20,0x1F},// V<br />{0x7F,0x20,0x18,0x20,0x7F},// W<br />{0x63,0x14,0x08,0x14,0x63},// X<br />{0x03,0x04,0x78,0x04,0x03},// Y<br />{0x61,0x51,0x49,0x45,0x43},// Z<br />{0x00,0x00,0x7F,0x41,0x41},// &#91;<br />{0x02,0x04,0x08,0x10,0x20},// &quot;\&quot;<br />{0x41,0x41,0x7F,0x00,0x00},// &#93;<br />{0x04,0x02,0x01,0x02,0x04},// ^<br />{0x40,0x40,0x40,0x40,0x40},// _<br />{0x00,0x01,0x02,0x04,0x00},// `<br />{0x20,0x54,0x54,0x54,0x78},// a<br />{0x7F,0x48,0x44,0x44,0x38},// b<br />{0x38,0x44,0x44,0x44,0x20},// c<br />{0x38,0x44,0x44,0x48,0x7F},// d<br />{0x38,0x54,0x54,0x54,0x18},// e<br />{0x08,0x7E,0x09,0x01,0x02},// f<br />{0x08,0x14,0x54,0x54,0x3C},// g<br />{0x7F,0x08,0x04,0x04,0x78},// h<br />{0x00,0x44,0x7D,0x40,0x00},// i<br />{0x20,0x40,0x44,0x3D,0x00},// j<br />{0x00,0x7F,0x10,0x28,0x44},// k<br />{0x00,0x41,0x7F,0x40,0x00},// l<br />{0x7C,0x04,0x18,0x04,0x78},// m<br />{0x7C,0x08,0x04,0x04,0x78},// n<br />{0x38,0x44,0x44,0x44,0x38},// o<br />{0x7C,0x14,0x14,0x14,0x08},// p<br />{0x08,0x14,0x14,0x18,0x7C},// q<br />{0x7C,0x08,0x04,0x04,0x08},// r<br />{0x48,0x54,0x54,0x54,0x20},// s<br />{0x04,0x3F,0x44,0x40,0x20},// t<br />{0x3C,0x40,0x40,0x20,0x7C},// u<br />{0x1C,0x20,0x40,0x20,0x1C},// v<br />{0x3C,0x40,0x30,0x40,0x3C},// w<br />{0x44,0x28,0x10,0x28,0x44},// x<br />{0x0C,0x50,0x50,0x50,0x3C},// y<br />{0x44,0x64,0x54,0x4C,0x44},// z<br />{0x00,0x08,0x36,0x41,0x00},// {<br />{0x00,0x00,0x7F,0x00,0x00},// |<br />{0x00,0x41,0x36,0x08,0x00},//}<br />{0x08,0x08,0x2A,0x1C,0x08},//-&gt;<br />{0x08,0x1C,0x2A,0x08,0x08}//&lt;-<br />};<br /><br />void SetupPorts()<br />{DDRB=0x2F;// 0010.1111; set B0-B3, B5 as outputs<br />DDRC=0x00;// 0000.0000;set PORTC as inputs<br />SetBit(PORTB,0);// start with TFT reset line inactive high<br />}<br />void msDelay( int delay)// put into a routine<br />{<br />for(int i=0;i&lt;delay;i++)// at cost of timing accuracy<br />return _delay_ms(1);<br /><br />}<br /><br />void FlashLED(byte count)<br />{<br />for(;count&gt;0;count--)<br />{<br />SetBit(PORTB,LED);// turn LED on<br />msDelay(150);// wait<br />ClearBit(PORTB,LED);// turn LED off<br />msDelay(150);// wait<br />}<br />}<br />unsigned long intsqrt(unsigned long val)// calculate integer value of square root<br />{<br />unsigned long mulMask=0x0008000;<br />unsigned long retVal=0;<br />if(val&gt;0)<br />{<br />while(mulMask!=0)<br />{<br />retVal|=mulMask;<br />if((retVal*retVal)&gt;val)<br />retVal&amp;=~mulMask;<br />mulMask&gt;&gt;=1;<br />}<br />}<br />return retVal;<br />}<br />/*<br />char* itoa(int i, char b&#91;&#93;){<br />char const digit&#91;&#93; = &quot;0123456789&quot;;<br />char* p = b;<br />if(i&lt;0){<br />*p++ = '<br />-<br />';<br />i *=<br />-<br />1;<br />}<br />int shifter = i;<br />do{ //Move to where representation ends<br />++p;<br />shifter = shifter/10;<br />}while(shifter);<br />*p = '<br />\<br />0';<br />do{ //Move back, inserting digits as u go<br />*<br />--<br />p = digit&#91;i%10&#93;;<br />i = i/10;<br />}while(i);<br />return b;<br />}<br />*/<br /><br />// b7 b6 b5 b4 b3 b2 b1 b0<br />// SPCR: SPIE SPE DORD MSTR CPOL CPHA SPR1 SPR0<br />// 0 1 0 1 . 0 0 0 1<br />//<br />// SPIE-enable SPI interrupt<br />// SPE-enable SPI<br />// DORD-0=MSB first, 1=LSB first<br />// MSTR-0=slave, 1=master<br />// CPOL-0=clock starts low, 1=clock starts high<br />// CPHA-0=read on rising-edge, 1=read on falling-edge<br />// SPRx-00=osc/4, 01=osc/16, 10=osc/64, 11=osc/128<br />//<br />// SPCR = 0x50: SPI enabled as Master, mode0, at 16/4 = 4 MHz<br />void OpenSPI()<br />{<br />SPCR=0x50;// SPI enabled as Master, Mode0 at 4 MHz<br />SetBit(SPSR,SPI2X);// double the SPI rate: 4--&gt;8 MHz<br />}<br />void CloseSPI()<br />{<br />SPCR=0x00;//clear SPI enable bit<br />}<br />byte Xfer(byte data)<br />{<br />SPDR=data;// initiate transfer<br />while (!(SPSR&amp;0x80));// wait for transfer to complete<br />return SPDR;<br />}<br /><br /><br />#define SWRESET 0x01// software reset<br />#define SLPOUT 0x11// sleep out<br />#define DISPOFF 0x28 // display off<br />#define DISPON 0x29 // display on<br />#define CASET 0x2A // column address set<br />#define RASET 0x2B // row address set<br />#define RAMWR 0x2C // RAM write<br />#define MADCTL 0x36 // axis control<br />#define COLMOD 0x3A<br />// color mode<br />// 1.8&quot; TFT display constants<br />#define XSIZE 128<br />#define YSIZE 160<br />#define XMAX XSIZE-1<br />#define YMAX YSIZE-1<br />// Color constants<br />#define BLACK 0x0000<br />#define BLUE 0x001F<br />#define RED 0xF800<br />#define GREEN 0x0400<br />#define LIME 0x07E0<br />#define CYAN 0x07FF<br />#define MAGENTA 0xF81F<br />#define YELLOW 0xFFE0<br />#define WHITE 0xFFFF<br />void WriteCmd(byte cmd)<br />{<br />ClearBit(PORTB,1);// B1=DC; 0=comm and, 1=data<br />Xfer(cmd);<br />SetBit(PORTB,1);// return DC high<br />}<br />void WriteByte (byte b)<br />{<br />Xfer(b);<br />}<br />void WriteWord (int w)<br />{<br />Xfer(w&gt;&gt;8);// write upper 8 bits<br />Xfer(w&amp;0xFF);// write lower 8 bits<br />}<br />void Write888 (long data, int count)<br />{<br />byte red=data&gt;&gt;16;// red = upper 8 bits<br />byte green=(data&gt;&gt;8)&amp;0xFF;// green = middle 8 bits<br />byte blue=data&amp;0xFF;// blue= lower 8 bits<br />for(;count&gt;0;count--)<br />{<br />WriteByte(red);<br />WriteByte(green);<br />WriteByte(blue);<br />}<br />}<br />void Write565(int data,unsigned int count)// send 16-bit pixel data to the controller<br />// note: inlined spi xfer for optimization<br />{<br />WriteCmd(RAMWR);<br />for(;count&gt;0;count--)<br />{<br />SPDR=(data&gt;&gt;8);// write hi byte<br />while(!(SPSR&amp;0x80));// wait for transfer to complete<br />SPDR=(data&amp;0xFF);// write lo byte<br />while(!(SPSR&amp;0x80));// wait for transfer to complete<br />}<br />}<br />void HardwareReset()<br />{<br />ClearBit(PORTB,0);// pull PB0 (digital 8) low<br />msDelay(1);// 1mS is enough<br />SetBit(PORTB,0);// return PB0 high<br />msDelay(150);// wait 150mS for reset to finish<br />}<br />void InitDisplay()<br />{<br />HardwareReset();// initialize display controller<br />WriteCmd(SLPOUT);// takedisplay out of sleep mode<br />msDelay(150);// wait 150mS for TFT driver circuits<br />WriteCmd(COLMOD);// select color mode:<br />WriteByte(0x05);// mode 5 = 16bit pixels (RGB565)<br />WriteCmd(DISPON);// turn display on!<br />}<br />void SetAddrWindow(byte x0,byte y0, byte x1, byte y1)<br />{<br />WriteCmd(CASET);// set column range (x0,x1)<br />WriteWord(x0);<br />WriteWord(x1);<br />WriteCmd(RASET);// set row range (y0,y1);<br />WriteWord(y0);<br />WriteWord(y1);<br />}<br />void ClearScreen()<br />{<br />SetAddrWindow(0,0,XMAX,YMAX);// set window to entire display<br />WriteCmd(RAMWR);<br />for(unsigned int i=40960;i&gt;0;--i)// byte count = 128*160*2<br />{<br />SPDR=0;<br />// initiate transfer of 0x00<br />while (!(SPSR&amp;0x80));// wait for xfer to finish<br />}<br />}<br />//---------------------------------------------------------------------------<br />//SIMPLE GRAPHICS ROUTINES<br />//<br />// note: many routines have byte parameters, to save space,<br />// but these can easily be changed to int params for larger displays.<br />void DrawPixel(byte x,byte y,int color)<br />{<br />SetAddrWindow(x,y,x,y);<br />Write565(color,1);<br />}<br />void HLine(byte x0,byte x1,byte y,int color)// draws a horizontal line in given color<br />{<br />byte width=x1-x0+1;<br />SetAddrWindow(x0,y,x1,y);<br />Write565(color,width);<br />}<br />void VLine(byte x,byte y0,byte y1,int color)// draws a vertical line in given color<br />{<br />byte height=y1-y0+1;<br />SetAddrWindow(x,y0,x,y1);<br />Write565(color,height);<br />}<br />void Line(int x0,int y0,int x1,int y1,int color)// an elegant implementation of the Bresenham algorithm<br />{<br />int dx=abs(x1-x0),sx=x0&lt;x1?1:-1;<br />int dy=abs(y1-y0),sy=y0&lt;y1?1:-1;<br />int err=(dx&gt;dy?dx:-dy)/2,e2;<br />for(;;)<br />{<br />DrawPixel(x0,y0,color);<br />if(x0==x1&amp;&amp;y0==y1)<br />break;<br />e2=err;<br />if(e2&gt;-dx)<br />{<br />err-=dy;<br />x0+=sx;<br />}<br />if(e2&lt;dy)<br />{<br />err+=dx;<br />y0+=sy;<br />}<br />}<br />}<br />void DrawRect(byte x0,byte y0,byte x1,byte y1,int color)<br />// draws a rectangle in given color<br />{<br />HLine(x0,x1,y0,color);<br />HLine(x0,x1,y1,color);<br />VLine(x0,y0,y1,color);<br />VLine(x1,y0,y1,color);<br />}<br />void FillRect(byte x0,byte y0,byte x1,byte y1,int color)<br />{<br />byte width=x1-x0+1;<br />byte height=y1-y0+1;<br />SetAddrWindow(x0,y0,x1,y1);<br />Write565(color,width*height);<br />}<br />void CircleQuadrant(byte xPos,byte yPos,byte radius,byte quad,int color)<br />// draws circle quadrant(s) centered at x,y with given radius &amp; color<br />// quad is a bit-encoded representation of which cartesian quadrant(s) to draw.<br />// Remember that the y axis on our display is 'upside down':<br />// bit 0: draw quadrant I (lower right)<br />// bit 1: draw quadrant IV (upper right)<br />// bit 2: draw quadrant II (lower left)<br />// bit 3: draw quadrant III (upper left)<br />{<br />int x,xEnd=(707*radius)/1000+1;<br />for(x=0;x&lt;xEnd;x++)<br />{<br />byte y=intsqrt(radius*radius-x*x);<br />if(quad&amp;0x01)<br />{<br />DrawPixel(xPos+x,yPos+y,color);// lower right<br />DrawPixel(xPos+y,yPos+x,color);<br />}<br />if(quad&amp;0x02)<br />{<br />DrawPixel(xPos+x,yPos-y,color);// upper right<br />DrawPixel(xPos+y,yPos-x,color);<br />}<br />if(quad&amp;0x04)<br />{<br />DrawPixel(xPos-x,yPos+y,color);// lower left<br />DrawPixel(xPos-y,yPos+x,color);<br />}<br />if(quad&amp;0x08)<br />{<br />DrawPixel(xPos-x,yPos-y,color);// upper left<br />DrawPixel(xPos-y,yPos-x,color);<br />}<br />}<br />}<br />void Circle(byte xPos,byte yPos,byte radius,int color)// draws circle at x,y with given radius &amp; color<br />{<br />CircleQuadrant(xPos,yPos,radius,0x0F,color);<br />// do all 4 quadrants<br />}<br />void RoundRect(byte x0,byte y0,byte x1,byte y1,byte r,int color)<br />// draws a rounded rectangle with corner radius r.<br />// coordinates: top left = x0,y0; bottom right = x1,y1<br />{<br />HLine(x0+r,x1-r,y0,color);// top side<br />HLine(x0+r,x1-r,y1,color);// bottom side<br />VLine(x0,y0+r,y1-r,color);// left side<br />VLine(x1,y0+r,y1-r,color);// right side<br />CircleQuadrant(x0+r,y0+r,r,8,color);// upper left corner<br />CircleQuadrant(x1-r,y0+r,r,2,color);// upper right corner<br />CircleQuadrant(x0+r,y1-r,r,4,color);// lower left corner<br />CircleQuadrant(x1-r,y1-r,r,1,color);// lower right corner<br />}<br />void FillCircle(byte xPos,byte yPos,byte radius,int color)// draws filled circle at x,y with given radius &amp; color<br />{<br />long r2=radius*radius;<br />for(int x=0;x&lt;=radius;x++)<br />{<br />byte y=intsqrt(r2-x*x);<br />byte y0=yPos-y;<br />byte y1=yPos+y;<br />VLine(xPos+x,y0,y1,color);<br />VLine(xPos-x,y0,y1,color);<br />}<br />}<br />void Ellipse(int x0,int y0,int width,int height,int color)<br />// draws an ellipse of given width &amp; height<br />// two-part Bresenham method<br />//note: slight discontinuity between parts on some (narrow) ellipses.<br />{<br />int a=width/2,b=height/2;<br />int x=0,y=b;<br />long a2=(long)a*a*2;<br />long b2=(long)b*b*2;<br />long error=(long)a*a*b;<br />long stopY=0,stopX=a2*b;<br />while(stopY&lt;=stopX)<br />{<br />DrawPixel(x0+x,y0+y,color);<br />DrawPixel(x0+x,y0-y,color);<br />DrawPixel(x0-x,y0+y,color);<br />DrawPixel(x0-x,y0-y,color);<br />x++;<br />error-=b2*(x-1);<br />stopY+=b2;<br />if(error&lt;0)<br />{<br />error+=a2*(y-1);<br />y--;<br />stopX-=a2;<br />}<br />}<br />x=a;<br />y=0;<br />error=b*b*a;<br />stopY=a*b2;<br />stopX=0;<br />while(stopY&gt;=stopX)<br />{<br />DrawPixel(x0+x,y0+y,color);<br />DrawPixel(x0+x,y0-y,color);<br />DrawPixel(x0-x,y0+y,color);<br />DrawPixel(x0-x,y0-y,color);<br />y++;<br />error-=a2*(y-1);<br />stopX+=a2;<br />if(error&lt;0)<br />{<br />error+=b2*(x-1);<br />x--;<br />stopY-=b2;<br />}<br />}<br />}<br />void FillEllipse(int xPos,int yPos,int width,int height,int color)// draws a filled ellipse of given width &amp; height<br />{<br />int a=width/2, b=height/2;// get x &amp; y radii<br />int x1,x0=a,y=1,dx=0;<br />long a2=a*a,b2=b*b;// need longs: big numbers!<br />long a2b2=a2*b2;<br />HLine(xPos-a,xPos+a,yPos,color);// draw centerline<br />while(y&lt;=b)// draw horizontal lines...<br />{for(x1=x0-(dx-1);x1&gt;0;x1--)<br />if(b2*x1*x1+a2*y*y&lt;=a2b2)<br />break;<br />dx=x0-x1;<br />x0=x1;<br />HLine(xPos-x0,xPos+x0,yPos+y,color);<br />HLine(xPos-x0,xPos+x0,yPos-y,color);<br />y+=1;<br />}<br />}<br /><br /><br />//<br />// Each ASCII character is 5x7, with one pixel space between characters<br />// So, character width = 6 pixels &amp; character height = 8 pixels.<br />//<br />// In portrait mode:<br />// Display width = 128 pixels, so there are 21 chars/row (21x6 = 126).<br />// Display height = 160 pixels, so there are 20 rows (20x8 = 160).<br />// Total number of characters in portait mode = 21 x 20 = 420.<br />//<br />// In landscape mode:<br />// Display width is 160, so there are 26 chars/row (26x6 = 156).<br />// Display height is 128, so there are 16 rows (16x8 = 128).<br />// Total number of characters in landscape mode = 26x16 = 416.<br />byte curX,curY;<br />// current x &amp; y cursor position<br />void GotoXY(byte x,byte y)// position cursor oncharacter x,y grid, where 0&lt;x&lt;20, 0&lt;y&lt;19.<br />{<br />curX=x;<br />curY=y;<br />}<br />void GotoLine(byte y)// position character cursor to start of line y, where 0&lt;y&lt;19.<br />{<br />curX=0;<br />curY=y;<br />}<br /><br />void AdvanceCursor()// moves character cursor to next position, assuming portrait orientation<br />{<br />curX++;// advance x position<br />if(curX&gt;20)// beyond right margin?<br />{<br />curY++;// go to next line<br />curX=0;// at left margin<br />}<br />if(curY&gt;19)// beyond bottom margin?<br />curY=0;// start at top again<br />}<br />void SetOrientation(int degrees)// Set the display orientation to 0,90,180,or270 degrees<br />{<br />byte arg;<br />switch (degrees)<br />{<br />case 90:<br />arg=0x60;<br />break;<br />case 180:<br />arg=0xC0;<br />break;<br />case 270:<br />arg = 0xA0;<br />break;<br />default:<br />arg=0x00;<br />break;<br />}<br />WriteCmd(MADCTL);<br />WriteByte(arg);<br />}<br />void PutCh(char ch, byte x, byte y, int color)// write ch to display X,Y coordinates using ASCII 5x7 font<br />{<br />int pixel;<br />byte row, col, bit, data, mask=0x01;<br />SetAddrWindow(x,y,x+4,y+6);<br />WriteCmd(RAMWR);<br />for(row=0;row&lt;7;row++)<br />{<br />for(col=0;col&lt;5;col++)<br />{<br />data=pgm_read_byte(&amp;(FONT_CHARS&#91;ch-32&#93;&#91;col&#93;));<br />bit=data&amp;mask;<br />if(bit==0)<br />pixel=BLACK;<br />else<br />pixel=color;<br />WriteWord(pixel);<br />}<br />mask&lt;&lt;=1;<br />}<br />}<br />void WriteChar(char ch,int color)// writes character to display at current cursor position.<br />{<br />PutCh(ch,curX*6,curY*8,color);<br />AdvanceCursor();<br />}<br />void WriteString(char *text,int color)// writes string to display atcurrent cursor position.<br />{<br />for(;*text;text++)// for all non-nul chars<br />WriteChar(*text,color);// write the char<br />}<br />void WriteInt(int i)// writes integer i at current cursor position<br />{<br />char str&#91;8&#93;;// buffer for string result<br />itoa(i,str,10);// convert to string, base 10<br />WriteString(str,WHITE);<br />}<br />void WriteHex(int i)// writes hexadecimal value of integer i at current cursor position<br />{<br />char str&#91;8&#93;;// buffer for string result<br />itoa(i,str,16);<br />// convert to base 16 (hex)<br />WriteString(str,WHITE);<br />}<br /><br />void PixelTest()<br />{<br />for<br />(int i=4000;i&gt;0;i--)// do a whole bunch:<br />{<br />int x=rand()%XMAX;// random x coordinate<br />int y=rand()%YMAX;// random y coordinate<br />DrawPixel(x,y,YELLOW);// draw pixel at x,y<br />}<br />}<br />void<br />LineTest()// sweeps Line routine through all four quadrants.<br />{<br />ClearScreen();<br />int x,y,x0=64,y0=80;<br />for(x=0;x&lt;XMAX;x+=2)<br />Line(x0,y0,x,0,YELLOW);<br />for(y=0;y&lt;YMAX;y+=2)<br />Line(x0,y0,XMAX,y,CYAN);<br />for(x=XMAX;x&gt;0;x-=2)<br />Line(x0,y0,x,YMAX,YELLOW);<br />for(y=YMAX;y&gt;0;y-=2)<br />Line(x0,y0,0,y,CYAN);<br />msDelay(2000);<br />}<br />void CircleTest()// draw series of concentric circles<br />{<br />for(int radius=6;radius&lt;60;radius+=2)<br />Circle(60,80,radius,YELLOW);<br />}<br />void<br />PortraitChars()// Writes 420 characters (5x7) to screen in portrait mode<br />{<br />ClearScreen();<br />for(int i=420;i&gt;0;i--)<br />{<br />byte x=i%21;<br />byte y=i/21;<br />char ascii=(i%96)+32;<br />PutCh(ascii,x*6,y*8,CYAN);<br />}<br />msDelay(2000);<br />}<br /><br />int main()<br />{<br />SetupPorts();// use PortB for LCD interface<br />FlashLED(1);// indicate program start<br />OpenSPI();// start communication to TFT<br />InitDisplay();// initialize TFT controller<br />PortraitChars();//show full screen of ASCII chars<br />LineTest();// paint background of lines<br />FillEllipse(60,75,100,50,BLACK);// erase an oval in center<br />Ellipse(60,75,100,50,LIME);// outline the oval in green<br />char *str=&quot;Hello, World!&quot;;// text to display<br />GotoXY(4,9);// position text cursor<br />WriteString(str,YELLOW);// display text inside oval<br />CloseSPI();// close communication with TFT<br />FlashLED(3);// indicate program end<br />}[/syntax]<br /><br />Z tym że mam problem.<br /><br />W instrukcji są inne wyprowadzenia niż w moim wyświetlaczu.<br /><br />Ma ktoś może pomysł jak przerobić ten kod do mojego wyświetlacza (jak połączyć wyświetlacz z ATmega)?<br />MOSI i MISO jest tylko do karty SD i nie za bardzo wiem jak sobie z tym poradzić...<br /><br />Pomóżcie proszę.<p>Statystyki: Napisane przez <a href="https://forum.atnel.pl/memberlist.php?mode=viewprofile&amp;u=3703">chabov</a> — 21 sie 2014, o 22:15</p><hr />
]]></content>
</entry>
</feed>