OLED

Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 11

#define tft_Write_8(C) {SPDR=(C); while (!

(SPSR&_BV(SPIF)));}
#define tft_Write_16(C) tft_Write_8((uint8_t)((C)>>8));tft_Write_8((uint8_t)
((C)>>0))

#define tft_Write_32C(C,D) \
tft_Write_16((uint16_t) (C)); \
tft_Write_16((uint16_t) (D))

#define TFT_BLACK 0x0000 /* 0, 0, 0 */


#define TFT_NAVY 0x000F /* 0, 0, 128 */
#define TFT_DARKGREEN 0x03E0 /* 0, 128, 0 */
#define TFT_DARKCYAN 0x03EF /* 0, 128, 128 */
#define TFT_MAROON 0x7800 /* 128, 0, 0 */
#define TFT_PURPLE 0x780F /* 128, 0, 128 */
#define TFT_OLIVE 0x7BE0 /* 128, 128, 0 */
#define TFT_LIGHTGREY 0xD69A /* 211, 211, 211 */
#define TFT_DARKGREY 0x7BEF /* 128, 128, 128 */
#define TFT_BLUE 0x001F /* 0, 0, 255 */
#define TFT_GREEN 0x07E0 /* 0, 255, 0 */
#define TFT_CYAN 0x07FF /* 0, 255, 255 */
#define TFT_RED 0xF800 /* 255, 0, 0 */
#define TFT_MAGENTA 0xF81F /* 255, 0, 255 */
#define TFT_YELLOW 0xFFE0 /* 255, 255, 0 */
#define TFT_WHITE 0xFFFF /* 255, 255, 255 */
#define TFT_ORANGE 0xFDA0 /* 255, 180, 0 */
#define TFT_GREENYELLOW 0xB7E0 /* 180, 255, 0 */
#define TFT_PINK 0xFE19 /* 255, 192, 203 */ //Lighter pink, was 0xFC9F

#define TFT_BROWN 0x9A60 /* 150, 75, 0 */


#define TFT_GOLD 0xFEA0 /* 255, 215, 0 */
#define TFT_SILVER 0xC618 /* 192, 192, 192 */
#define TFT_SKYBLUE 0x867D /* 135, 206, 235 */
#define TFT_VIOLET 0x915C

Komut modu D/C=0; 0x2A yolla. //Column


Data modu D/C=1; 0>>8 yolla 0>>0 yolla.239>>8 yolla.239>>0 yolla.(Sayilari
kontrol et.Niye 8?)

Komut modu D/C=0; 0x2B yolla. //Row


Data modu D/C=1; 0>>8 yolla 0>>0 yolla.239>>8 yolla.239>>0 yolla.(Sayilari
kontrol et.Niye 8?)

len=240*240;
while ( len-- ) {tft_Write_16(color);} //Renk kodlari.
**********************
/*
if(input(ust_sinir)) //yukarı sınır. e6 yukarı e5 asagi e7 ortak.
{

if(asa==0)
{
output_low(kavrama);
output_low(ust_dc_sinir); //Yukari.
output_low(pin_e4);
output_low(ortak_dc);

}
if(asa==1)
{
output_high(kavrama);
output_high(ortak_dc);
output_high(pin_e4);

if(input(alt_sinir)) //Asagi sinir.


{

if(yuk==0)
{
output_low(kavrama);

output_low(alt_dc_sinir);//Asagi.
output_low(ortak_dc);
output_low(pin_e4);

}
if(yuk==1)
{
output_high(kavrama);
output_high(ortak_dc);
output_high(pin_e4);

*/

**************************************************
/*
//RESET PIN 0 SONRA 1 OLACAK ,BLK :3.3 ,DC :0 KOMUT DC :1 DATA

//a7 mosi ,a5 sck

#define RGB565(r, g, b) (((r & 0xF8) << 8) | ((g & 0xFC) << 3) | ((b &
0xF8) >> 3))
#define ST7789_ColorMode_65K 0x50
//#define ST7789_ColorMode_262K 0x60
//#define ST7789_ColorMode_12bit 0x03
#define ST7789_ColorMode_16bit 0x55 //0x05
//#define ST7789_ColorMode_18bit 0x06
//#define ST7789_ColorMode_16M 0x07

#define ST7789_Cmd_SWRESET 0x01


//#define ST7789_Cmd_SLPIN 0x10
#define ST7789_Cmd_SLPOUT 0x11
#define ST7789_Cmd_COLMOD 0x3A
//#define ST7789_Cmd_PTLON 0x12
//#define ST7789_Cmd_NORON 0x13
#define ST7789_Cmd_INVOFF 0x20
#define ST7789_Cmd_INVON 0x21
//#define ST7789_Cmd_GAMSET 0x26
//#define ST7789_Cmd_DISPOFF 0x28
#define ST7789_Cmd_DISPON 0x29
#define ST7789_Cmd_CASET 0x2A
#define ST7789_Cmd_RASET 0x2B
#define ST7789_Cmd_RAMWR 0x2C
//#define ST7789_Cmd_PTLAR 0x30
#define ST7789_Cmd_MADCTL 0x36
//#define ST7789_Cmd_MADCTL_MY 0x80
//#define ST7789_Cmd_MADCTL_MX 0x40
//#define ST7789_Cmd_MADCTL_MV 0x20
//#define ST7789_Cmd_MADCTL_ML 0x10
//#define ST7789_Cmd_MADCTL_RGB 0x00
//#define ST7789_Cmd_RDID1 0xDA
//#define ST7789_Cmd_RDID2 0xDB
//#define ST7789_Cmd_RDID3 0xDC
//#define ST7789_Cmd_RDID4 0xDD
#define ST7789_MADCTL_MY 0x80
#define ST7789_MADCTL_MX 0x40
#define ST7789_MADCTL_MV 0x20
#define ST7789_MADCTL_ML 0x10
#define ST7789_MADCTL_BGR 0x08
#define ST7789_MADCTL_MH 0x04

#define BLACK 0x0000


#define BLUE 0x001F
#define RED 0xF800
#define GREEN 0x07E0
#define CYAN 0x07FF
#define MAGENTA 0xF81F
#define YELLOW 0xFFE0
#define WHITE 0xFFFF

#define ST7789_X_Start 0
#define ST7789_Y_Start 0

static const char font[] = {


0x00, 0x00, 0x00, 0x00, 0x00 , // 0x20 space
0x00, 0x00, 0x5f, 0x00, 0x00 , // 0x21 !
0x00, 0x07, 0x00, 0x07, 0x00 , // 0x22 "
0x14, 0x7f, 0x14, 0x7f, 0x14 , // 0x23 #
0x24, 0x2a, 0x7f, 0x2a, 0x12 , // 0x24 $
0x23, 0x13, 0x08, 0x64, 0x62 , // 0x25 %
0x36, 0x49, 0x55, 0x22, 0x50 , // 0x26 &
0x00, 0x05, 0x03, 0x00, 0x00 , // 0x27 '
0x00, 0x1c, 0x22, 0x41, 0x00 , // 0x28 (
0x00, 0x41, 0x22, 0x1c, 0x00 , // 0x29 )
0x14, 0x08, 0x3e, 0x08, 0x14 , // 0x2a *
0x08, 0x08, 0x3e, 0x08, 0x08 , // 0x2b +
0x00, 0x50, 0x30, 0x00, 0x00 , // 0x2c ,
0x08, 0x08, 0x08, 0x08, 0x08 , // 0x2d -
0x00, 0x60, 0x60, 0x00, 0x00 , // 0x2e .
0x20, 0x10, 0x08, 0x04, 0x02 , // 0x2f /
0x3e, 0x51, 0x49, 0x45, 0x3e , // 0x30 0
0x00, 0x42, 0x7f, 0x40, 0x00 , // 0x31 1
0x42, 0x61, 0x51, 0x49, 0x46 , // 0x32 2
0x21, 0x41, 0x45, 0x4b, 0x31 , // 0x33 3
0x18, 0x14, 0x12, 0x7f, 0x10 , // 0x34 4
0x27, 0x45, 0x45, 0x45, 0x39 , // 0x35 5
0x3c, 0x4a, 0x49, 0x49, 0x30 , // 0x36 6
0x01, 0x71, 0x09, 0x05, 0x03 , // 0x37 7
0x36, 0x49, 0x49, 0x49, 0x36 , // 0x38 8
0x06, 0x49, 0x49, 0x29, 0x1e , // 0x39 9
0x00, 0x36, 0x36, 0x00, 0x00 , // 0x3a :
0x00, 0x56, 0x36, 0x00, 0x00 , // 0x3b ;
0x08, 0x14, 0x22, 0x41, 0x00 , // 0x3c <
0x14, 0x14, 0x14, 0x14, 0x14 , // 0x3d =
0x00, 0x41, 0x22, 0x14, 0x08 , // 0x3e >
0x02, 0x01, 0x51, 0x09, 0x06 , // 0x3f ?
0x32, 0x49, 0x79, 0x41, 0x3e , // 0x40 @
0x7e, 0x11, 0x11, 0x11, 0x7e , // 0x41 A
0x7f, 0x49, 0x49, 0x49, 0x36 , // 0x42 B
0x3e, 0x41, 0x41, 0x41, 0x22 , // 0x43 C
0x7f, 0x41, 0x41, 0x22, 0x1c , // 0x44 D
0x7f, 0x49, 0x49, 0x49, 0x41 , // 0x45 E
0x7f, 0x09, 0x09, 0x09, 0x01 , // 0x46 F
0x3e, 0x41, 0x49, 0x49, 0x7a , // 0x47 G
0x7f, 0x08, 0x08, 0x08, 0x7f , // 0x48 H
0x00, 0x41, 0x7f, 0x41, 0x00 , // 0x49 I
0x20, 0x40, 0x41, 0x3f, 0x01 , // 0x4a J
0x7f, 0x08, 0x14, 0x22, 0x41 , // 0x4b K
0x7f, 0x40, 0x40, 0x40, 0x40 , // 0x4c L
0x7f, 0x02, 0x0c, 0x02, 0x7f , // 0x4d M
0x7f, 0x04, 0x08, 0x10, 0x7f , // 0x4e N
0x3e, 0x41, 0x41, 0x41, 0x3e , // 0x4f O
0x7f, 0x09, 0x09, 0x09, 0x06 , // 0x50 P
0x3e, 0x41, 0x51, 0x21, 0x5e , // 0x51 Q
0x7f, 0x09, 0x19, 0x29, 0x46 , // 0x52 R
0x46, 0x49, 0x49, 0x49, 0x31 , // 0x53 S
0x01, 0x01, 0x7f, 0x01, 0x01 , // 0x54 T
0x3f, 0x40, 0x40, 0x40, 0x3f , // 0x55 U
0x1f, 0x20, 0x40, 0x20, 0x1f , // 0x56 V
0x3f, 0x40, 0x38, 0x40, 0x3f , // 0x57 W
0x63, 0x14, 0x08, 0x14, 0x63 , // 0x58 X
0x07, 0x08, 0x70, 0x08, 0x07 , // 0x59 Y
0x61, 0x51, 0x49, 0x45, 0x43 , // 0x5a Z
0x00, 0x7f, 0x41, 0x41, 0x00 , // 0x5b [
0x02, 0x04, 0x08, 0x10, 0x20 , // 0x5c backslash
0x00, 0x41, 0x41, 0x7f, 0x00 , // 0x5d ]
0x04, 0x02, 0x01, 0x02, 0x04 , // 0x5e ^
0x40, 0x40, 0x40, 0x40, 0x40 , // 0x5f _
0x00, 0x01, 0x02, 0x04, 0x00 , // 0x60 `
0x20, 0x54, 0x54, 0x54, 0x78 , // 0x61 a
0x7f, 0x48, 0x44, 0x44, 0x38 , // 0x62 b
0x38, 0x44, 0x44, 0x44, 0x20 , // 0x63 c
0x38, 0x44, 0x44, 0x48, 0x7f , // 0x64 d
0x38, 0x54, 0x54, 0x54, 0x18 , // 0x65 e
0x08, 0x7e, 0x09, 0x01, 0x02 , // 0x66 f
0x0c, 0x52, 0x52, 0x52, 0x3e , // 0x67 g
0x7f, 0x08, 0x04, 0x04, 0x78 , // 0x68 h
0x00, 0x44, 0x7d, 0x40, 0x00 , // 0x69 i
0x20, 0x40, 0x44, 0x3d, 0x00 , // 0x6a j
0x7f, 0x10, 0x28, 0x44, 0x00 , // 0x6b k
0x00, 0x41, 0x7f, 0x40, 0x00 , // 0x6c l
0x7c, 0x04, 0x18, 0x04, 0x78 , // 0x6d m
0x7c, 0x08, 0x04, 0x04, 0x78 , // 0x6e n
0x38, 0x44, 0x44, 0x44, 0x38 , // 0x6f o
0x7c, 0x14, 0x14, 0x14, 0x08 , // 0x70 p
0x08, 0x14, 0x14, 0x18, 0x7c , // 0x71 q
0x7c, 0x08, 0x04, 0x04, 0x08 , // 0x72 r
0x48, 0x54, 0x54, 0x54, 0x20 , // 0x73 s
0x04, 0x3f, 0x44, 0x40, 0x20 , // 0x74 t
0x3c, 0x40, 0x40, 0x20, 0x7c , // 0x75 u
0x1c, 0x20, 0x40, 0x20, 0x1c , // 0x76 v
0x3c, 0x40, 0x30, 0x40, 0x3c , // 0x77 w
0x44, 0x28, 0x10, 0x28, 0x44 , // 0x78 x
0x0c, 0x50, 0x50, 0x50, 0x3c , // 0x79 y
0x44, 0x64, 0x54, 0x4c, 0x44 , // 0x7a z
0x00, 0x08, 0x36, 0x41, 0x00 , // 0x7b {
0x00, 0x00, 0x7f, 0x00, 0x00 , // 0x7c |
0x00, 0x41, 0x36, 0x08, 0x00 , // 0x7d }
0x10, 0x08, 0x08, 0x10, 0x08 , // 0x7e ~
0x00, 0x00, 0x00, 0x00, 0x00 , // 0x7f
0x7e, 0x11, 0x11, 0x11, 0x7e , // 0x80 A // ??????? ???????
0x7f, 0x49, 0x49, 0x49, 0x33 , // 0x81 ?
0x7f, 0x49, 0x49, 0x49, 0x36 , // 0x82 ?
0x7f, 0x01, 0x01, 0x01, 0x03 , // 0x83 ?
0xe0, 0x51, 0x4f, 0x41, 0xff , // 0x84 ?
0x7f, 0x49, 0x49, 0x49, 0x41 , // 0x85 E
0x77, 0x08, 0x7f, 0x08, 0x77 , // 0x86 ?
0x41, 0x49, 0x49, 0x49, 0x36 , // 0x87 ?
0x7f, 0x10, 0x08, 0x04, 0x7f , // 0x88 ?
0x7c, 0x21, 0x12, 0x09, 0x7c , // 0x89 ?
0x7f, 0x08, 0x14, 0x22, 0x41 , // 0x8A K
0x20, 0x41, 0x3f, 0x01, 0x7f , // 0x8B ?
0x7f, 0x02, 0x0c, 0x02, 0x7f , // 0x8C M
0x7f, 0x08, 0x08, 0x08, 0x7f , // 0x8D H
0x3e, 0x41, 0x41, 0x41, 0x3e , // 0x8E O
0x7f, 0x01, 0x01, 0x01, 0x7f , // 0x8F ?
0x7f, 0x09, 0x09, 0x09, 0x06 , // 0x90 P
0x3e, 0x41, 0x41, 0x41, 0x22 , // 0x91 C
0x01, 0x01, 0x7f, 0x01, 0x01 , // 0x92 T
0x47, 0x28, 0x10, 0x08, 0x07 , // 0x93 ?
0x1c, 0x22, 0x7f, 0x22, 0x1c , // 0x94 ?
0x63, 0x14, 0x08, 0x14, 0x63 , // 0x95 X
0x7f, 0x40, 0x40, 0x40, 0xff , // 0x96 ?
0x07, 0x08, 0x08, 0x08, 0x7f , // 0x97 ?
0x7f, 0x40, 0x7f, 0x40, 0x7f , // 0x98 ?
0x7f, 0x40, 0x7f, 0x40, 0xff , // 0x99 ?
0x01, 0x7f, 0x48, 0x48, 0x30 , // 0x9A ?
0x7f, 0x48, 0x30, 0x00, 0x7f , // 0x9B ?
0x00, 0x7f, 0x48, 0x48, 0x30 , // 0x9C ?
0x22, 0x41, 0x49, 0x49, 0x3e , // 0x9D ?
0x7f, 0x08, 0x3e, 0x41, 0x3e , // 0x9E ?
0x46, 0x29, 0x19, 0x09, 0x7f , // 0x9F ?
0x20, 0x54, 0x54, 0x54, 0x78 , // 0xA0 a
0x3c, 0x4a, 0x4a, 0x49, 0x31 , // 0xA1 ?
0x7c, 0x54, 0x54, 0x54, 0x28 , // 0xA2 ?
0x7c, 0x04, 0x04, 0x04, 0x0c , // 0xA3 ?
0xe0, 0x54, 0x4c, 0x44, 0xfc , // 0xA4 ?
0x38, 0x54, 0x54, 0x54, 0x18 , // 0xA5 e
0x6c, 0x10, 0x7c, 0x10, 0x6c , // 0xA6 ?
0x44, 0x44, 0x54, 0x54, 0x28 , // 0xA7 ?
0x7c, 0x20, 0x10, 0x08, 0x7c , // 0xA8 ?
0x7c, 0x41, 0x22, 0x11, 0x7c , // 0xA9 ?
0x7c, 0x10, 0x10, 0x28, 0x44 , // 0xAA ?
0x20, 0x44, 0x3c, 0x04, 0x7c , // 0xAB ?
0x7c, 0x08, 0x10, 0x08, 0x7c , // 0xAC ?
0x7c, 0x10, 0x10, 0x10, 0x7c , // 0xAD ?
0x38, 0x44, 0x44, 0x44, 0x38 , // 0xAE o
0x7c, 0x04, 0x04, 0x04, 0x7c , // 0xAF ?
0x7C, 0x14, 0x14, 0x14, 0x08 , // 0xB0 p
0x38, 0x44, 0x44, 0x44, 0x20 , // 0xB1 c
0x04, 0x04, 0x7c, 0x04, 0x04 , // 0xB2 ?
0x0C, 0x50, 0x50, 0x50, 0x3C , // 0xB3 ?
0x30, 0x48, 0xfc, 0x48, 0x30 , // 0xB4 ?
0x44, 0x28, 0x10, 0x28, 0x44 , // 0xB5 x
0x7c, 0x40, 0x40, 0x40, 0xfc , // 0xB6 ?
0x0c, 0x10, 0x10, 0x10, 0x7c , // 0xB7 ?
0x7c, 0x40, 0x7c, 0x40, 0x7c , // 0xB8 ?
0x7c, 0x40, 0x7c, 0x40, 0xfc , // 0xB9 ?
0x04, 0x7c, 0x50, 0x50, 0x20 , // 0xBA ?
0x7c, 0x50, 0x50, 0x20, 0x7c , // 0xBB ?
0x7c, 0x50, 0x50, 0x20, 0x00 , // 0xBC ?
0x28, 0x44, 0x54, 0x54, 0x38 , // 0xBD ?
0x7c, 0x10, 0x38, 0x44, 0x38 , // 0xBE ?
0x08, 0x54, 0x34, 0x14, 0x7c , // 0xBF ?
};

void ST7789_DrawChar_5x8(uint16_t x, uint16_t y, uint16_t TextColor, uint16_t


BgColor, uint8_t TransparentBg, unsigned char c);
void ST7789_DrawPixel(int16_t x, int16_t y, uint16_t color);
void ST7789_SetWindow(uint8_t x0, uint8_t y0, uint8_t x1, uint8_t y1);
void ST7789_RamWrite(uint16_t *pBuff, uint16_t Len);
static void ST7789_ColumnSet(uint16_t ColumnStart, uint16_t ColumnEnd);
static void ST7789_RowSet(uint16_t RowStart, uint16_t RowEnd);
void ST7789_FillScreen(uint16_t color);
void ST7789_FillRect(int16_t x, int16_t y, int16_t w, int16_t h, uint16_t color);
void ST7789_SendCmd(uint8_t cmd);
void ST7789_SendData(uint8_t data);
void ST7789_Init(void);

void ST7789_HardReset(void);
void ST7789_SoftReset(void);
void ST7789_InversionMode(uint8_t Mode);
void ST7789_ColorModeSet(uint8_t ColorMode);
void ST7789_SleepModeExit( void );

void ST7789_MemAccessModeSet(uint8_t Rotation, uint8_t VertMirror, uint8_t


HorizMirror, uint8_t IsBGR);
void bekle(uint32_t sure);

int oldu=0;

void bekle(uint32_t sure)


{
while(sure--);
}
void ST7789_Init()
{

ST7789_HardReset();
ST7789_SoftReset();
ST7789_SleepModeExit();

ST7789_ColorModeSet(ST7789_ColorMode_65K | ST7789_ColorMode_16bit);
bekle(420000);

ST7789_MemAccessModeSet(4, 1, 1, 0);
bekle(420000);
ST7789_InversionMode(1);
bekle(420000);
ST7789_FillScreen(0);

ST7789_SendCmd(ST7789_Cmd_DISPON);
bekle(4200000);
}

void ST7789_HardReset(void)
{
// GPIOA->ODR &=~(1<<1);
GPIOA->BSRR |=1<<17;

bekle(420000);
GPIOA->BSRR |=1<<1;
//GPIOA->ODR |=(1<<1);
bekle(8400000);
}

void ST7789_SoftReset(void)
{
ST7789_SendCmd(ST7789_Cmd_SWRESET);
bekle(8400000);
}
void ST7789_InversionMode(uint8_t Mode)
{
if (Mode)
ST7789_SendCmd(ST7789_Cmd_INVON);
else
ST7789_SendCmd(ST7789_Cmd_INVOFF);
}

void ST7789_SleepModeExit( void )


{
ST7789_SendCmd(ST7789_Cmd_SLPOUT);
bekle(21000000);
}

void ST7789_ColorModeSet(uint8_t ColorMode)


{
ST7789_SendCmd(ST7789_Cmd_COLMOD);
ST7789_SendData(ColorMode & 0x77);
}
void ST7789_MemAccessModeSet(uint8_t Rotation, uint8_t VertMirror, uint8_t
HorizMirror, uint8_t IsBGR)
{
uint8_t Value;
Rotation &= 7;

ST7789_SendCmd(ST7789_Cmd_MADCTL);

switch (Rotation)
{
case 0:
Value = 0;
break;
case 1:
Value = ST7789_MADCTL_MX;
break;
case 2:
Value = ST7789_MADCTL_MY;
break;
case 3:
Value = ST7789_MADCTL_MX | ST7789_MADCTL_MY;
break;
case 4:
Value = ST7789_MADCTL_MV;
break;
case 5:
Value = ST7789_MADCTL_MV | ST7789_MADCTL_MX;
break;
case 6:
Value = ST7789_MADCTL_MV | ST7789_MADCTL_MY;
break;
case 7:
Value = ST7789_MADCTL_MV | ST7789_MADCTL_MX | ST7789_MADCTL_MY;
break;
}

if (VertMirror)
Value = ST7789_MADCTL_ML;
if (HorizMirror)
Value = ST7789_MADCTL_MH;

if (IsBGR)
Value |= ST7789_MADCTL_BGR;

ST7789_SendData(Value);
}

void ST7789_DrawChar_5x8(uint16_t x, uint16_t y, uint16_t TextColor, uint16_t


BgColor, uint8_t TransparentBg, unsigned char c)
{
if((x >= 240) || (y >= 240) || ((x + 4) < 0) || ((y + 7) < 0)) return;
if(c<128) c = c-32;
if(c>=144 && c<=175) c = c-48;
if(c>=128 && c<=143) c = c+16;
if(c>=176 && c<=191) c = c-48;
if(c>191) return;
for (uint8_t i=0; i<6; i++ )
{
uint8_t line;
if (i == 5) line = 0x00;
else line = font[(c*5)+i];
for (uint8_t j = 0; j<8; j++)
{
if (line & 0x01) ST7789_DrawPixel(x + i, y + j, TextColor);
else if (!TransparentBg) ST7789_DrawPixel(x + i, y + j, BgColor);
line >>= 1;
}
}
}
void ST7789_DrawPixel(int16_t x, int16_t y, uint16_t color)
{
if ((x < 0) ||(x >= 240) || (y < 0) || (y >= 240))
return;

ST7789_SetWindow(x, y, x, y);
ST7789_RamWrite(&color, 1);
}

void ST7789_SetWindow(uint8_t x0, uint8_t y0, uint8_t x1, uint8_t y1)


{
ST7789_ColumnSet(x0, x1);
ST7789_RowSet(y0, y1);
ST7789_SendCmd(ST7789_Cmd_RAMWR);
}

void ST7789_RamWrite(uint16_t *pBuff, uint16_t Len)


{
while (Len--)
{
ST7789_SendData(*pBuff >> 8);
ST7789_SendData(*pBuff & 0xFF);
}
}

static void ST7789_ColumnSet(uint16_t ColumnStart, uint16_t ColumnEnd)


{
if (ColumnStart > ColumnEnd)
return;
if (ColumnEnd > 240)
return;

ColumnStart += ST7789_X_Start;
ColumnEnd += ST7789_X_Start;

ST7789_SendCmd(ST7789_Cmd_CASET);
ST7789_SendData(ColumnStart >> 8);
ST7789_SendData(ColumnStart & 0xFF);
ST7789_SendData(ColumnEnd >> 8);
ST7789_SendData(ColumnEnd & 0xFF);
}

static void ST7789_RowSet(uint16_t RowStart, uint16_t RowEnd)


{
if (RowStart > RowEnd)
return;
if (RowEnd > 240)
return;

RowStart += ST7789_Y_Start;
RowEnd += ST7789_Y_Start;

ST7789_SendCmd(ST7789_Cmd_RASET);
ST7789_SendData(RowStart >> 8);
ST7789_SendData(RowStart & 0xFF);
ST7789_SendData(RowEnd >> 8);
ST7789_SendData(RowEnd & 0xFF);
}

void ST7789_FillScreen(uint16_t color)


{
ST7789_FillRect(0, 0, 240, 240, color);
}

void ST7789_FillRect(int16_t x, int16_t y, int16_t w, int16_t h, uint16_t color)


{
if ((x >= 240) || (y >= 240)) return;
if ((x + w) > 240) w = 240 - x;
if ((y + h) > 240) h = 240 - y;
ST7789_SetWindow(x, y, x + w - 1, y + h - 1);
for (uint32_t i = 0; i < (h * w); i++) ST7789_RamWrite(&color, 1);
}
*/

*************************************

dr ye yaz.877.satırda
bsy biti.
dr ve sr registerini oku.

RCC BENDEKİ

PLLCFGR 04402A04 00402A04

APB1ENR 10000000 ===>PWR ENABLE ETMİŞ.

SPI
CR 00000344

GPIOA
MODER A8008905
OTYPER 00000000
ODR 000000013
AFRL 505000000

You might also like