ソースコードはこちらから ダウンロード することも出来ます。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
#pragma config FEXTOSC = OFF // FEXTOSC External Oscillator mode Selection bits (Oscillator not enabled) #pragma config RSTOSC = HFINT1 // Power-up default value for COSC bits (HFINTOSC (1MHz)) #pragma config CLKOUTEN = OFF // Clock Out Enable bit (CLKOUT function is disabled; I/O or oscillator function on OSC2) #pragma config CSWEN = ON // Clock Switch Enable bit (Writing to NOSC and NDIV is allowed) #pragma config FCMEN = ON // Fail-Safe Clock Monitor Enable (Fail-Safe Clock Monitor is enabled) #pragma config MCLRE = ON // Master Clear Enable bit (MCLR/VPP pin function is MCLR; Weak pull-up enabled) #pragma config PWRTE = OFF // Power-up Timer Enable bit (PWRT disabled) #pragma config WDTE = OFF // Watchdog Timer Enable bits (WDT disabled; SWDTEN is ignored) #pragma config LPBOREN = OFF // Low-power BOR enable bit (ULPBOR disabled) #pragma config BOREN = ON // Brown-out Reset Enable bits (Brown-out Reset enabled, SBOREN bit ignored) #pragma config BORV = LOW // Brown-out Reset Voltage selection bit (Brown-out voltage (Vbor) set to 2.45V) #pragma config PPS1WAY = ON // PPSLOCK bit One-Way Set Enable bit (The PPSLOCK bit can be cleared and set only once; PPS registers remain locked after one clear/set cycle) #pragma config STVREN = ON // Stack Overflow/Underflow Reset Enable bit (Stack Overflow or Underflow will cause a Reset) #pragma config DEBUG = OFF // Debugger enable bit (Background debugger disabled) #pragma config WRT = OFF // User NVM self-write protection bits (Write protection off) #pragma config LVP = OFF // Low Voltage Programming Enable bit (High Voltage on MCLR/VPP must be used for programming.) #pragma config CP = OFF // User NVM Program Memory Code Protection bit (User NVM code protection disabled) #pragma config CPD = OFF // Data NVM Memory Code Protection bit (Data NVM code protection disabled) #include <xc.h> #include "spi.h" #include "st7789.h" #include "usart18857.h" #define _XTAL_FREQ 32000000 const int RGBW[] = {0xF800, 0x07E0, 0x001F, 0xFFFF}; void Init(); void Color(int c){ //16bit = 1px の色を送信 Write_Parameter(c >> 8); //上位8bit Write_Parameter(c); //下位8bit } void Clear(){ //全体に白を描画 for(char i=0; i<240; i++) for(char j=0; j<240; j++) Color(0xFFFF); address(); } void __interrupt isr(){ Write_Parameter(EUSART_Receive()); } void main(void) { Init(); SPI_Init(); EUSART_Init(); Initial_ST7789(); address(); Clear(); char c = 0; for(char k=0; k<240; k++) //サンプルパターン for (char j=0; j<4; j++) for(char i=0; i<60; i++) Color(RGBW[j]); while(1); } void Init(){ OSCCON1 = 0b00000000; //32MHz TRISA = 0b00100000; ANSELA = 0b00000000; TRISC = 0b00010000; ANSELC = 0b00000000; WPUC = 0b00000000; PEIE = 1; GIE = 1; } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
#include <xc.h> void SPI_Init(){ SSP1STAT = 0b00000000; //SMP: middle/ CKE: IdleToActive SSP1CON1 = 0b00110000; //SSPEN/ CKP: Idle High/ SPIMaster Fosc/4 SSP1DATPPS = 0x14; // SDI : RC4 RC3PPS = 0x18; // SCK : RC3 RC5PPS = 0x19; // SDO : RC5 } char SPI_Exchange(char data){ char dumy; dumy = SSP1BUF; //Clear buffer SSP1BUF = data; //Send while(!SSP1STATbits.BF); return SSP1BUF; //Receive } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 |
#include <xc.h> #include "spi.h" #define DC RC2 #define RESET RC1 #define _XTAL_FREQ 32000000 void Write_Register(char c){ DC = 0; SPI_Exchange(c); } void Write_Parameter(char c){ DC = 1; SPI_Exchange(c); } /*====================================================*/ void Initial_ST7789(void) { RESET = 0; __delay_ms(100); RESET = 1; __delay_ms(100); Write_Register(0x36); Write_Parameter(0x00); Write_Register(0x3A); Write_Parameter(0x05); Write_Register(0xB2); Write_Parameter(0x0C); Write_Parameter(0x0C); Write_Parameter(0x00); Write_Parameter(0x33); Write_Parameter(0x33); Write_Register(0xB7); Write_Parameter(0x35); Write_Register(0xBB); Write_Parameter(0x19); Write_Register(0xC0); Write_Parameter(0x2C); Write_Register(0xC2); Write_Parameter(0x01); Write_Register(0xC3); Write_Parameter(0x12); Write_Register(0xC4); Write_Parameter(0x20); Write_Register(0xC6); Write_Parameter(0x0F); Write_Register(0xD0); Write_Parameter(0xA4); Write_Parameter(0xA1); Write_Register(0xE0); Write_Parameter(0xD0); Write_Parameter(0x04); Write_Parameter(0x0D); Write_Parameter(0x11); Write_Parameter(0x13); Write_Parameter(0x2B); Write_Parameter(0x3F); Write_Parameter(0x54); Write_Parameter(0x4C); Write_Parameter(0x18); Write_Parameter(0x0D); Write_Parameter(0x0B); Write_Parameter(0x1F); Write_Parameter(0x23); Write_Register(0xE1); Write_Parameter(0xD0); Write_Parameter(0x04); Write_Parameter(0x0C); Write_Parameter(0x11); Write_Parameter(0x13); Write_Parameter(0x2C); Write_Parameter(0x3F); Write_Parameter(0x44); Write_Parameter(0x51); Write_Parameter(0x2F); Write_Parameter(0x1F); Write_Parameter(0x1F); Write_Parameter(0x20); Write_Parameter(0x23); Write_Register(0x21); Write_Register(0x11); __delay_ms(120); Write_Register(0x29); } /*====================================================*/ void address(void) { Write_Register(0x2A); Write_Parameter(0x00); Write_Parameter(0x00); Write_Parameter(0x00); Write_Parameter(0xEF); Write_Register(0x2B); Write_Parameter(0x00); Write_Parameter(0x00); Write_Parameter(0x00); Write_Parameter(0xEF); Write_Register(0x2C); } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
#include<xc.h> #define _XTAL_FREQ 32000000 #define BAUDRATE 115200 void EUSART_Init(){ TX1STA = 0x20; RC1STA = 0x90; BAUD1CON = 0x08; SP1BRG = (_XTAL_FREQ/BAUDRATE + 1)/16; RCIE = 1; RCIF = 0; RXPPS = 0x05; // RX input RA4PPS = 0x14; // TX output } void EUSART_Send(char c){ while(TRMT == 0); TX1REG = c; } char EUSART_Receive(){ if(RCIF == 1){ if((RC1STAbits.OERR)||(RC1STAbits.FERR)){ RC1STA = 0; RC1STA = 0x90; return 0xff; //ERROR } else return RC1REG; //NORMAL } else return 0; //NO DATA } |