2

我正在尝试将 stm32f103c8t6与 ILI9325 LCD显示器连接。我在 Atollic TrueStudio 中为它创建了一个驱动程序并成功运行它。现在,我正在尝试将驱动程序传输到 Arduino IDE,因为在这里将我的代码与该项目的其他代码集成起来会更容易。但是,该驱动程序在 Arduino IDE 中不起作用。LCD只是空白。

我已经在 Arduino IDE 中为 stm32f1 测试了基本的 GPIO 操作,它工作正常。我检查了 LCD 上的引脚。他们似乎收到了董事会的命令。所有接线都是正确的,因为屏幕使用 Atollic 的代码工作,无需任何接线更改。

这是我在 Arduino IDE 中使用的驱动程序代码。它与 Atollic 中的基本相同。我改变的只是初始化和设置GPIO的功能。

#define LCD_RESET_Pin     9
#define LCD_CS_Pin        8
#define LCD_RS_Pin        7                  
#define LCD_WR_Pin        6              
#define LCD_RD_Pin        5 

#define TFT_W    320                    
#define TFT_H    240                    

#define WHITE           0xFFFF
#define BLACK           0x0000
#define BLUE            0x001F
#define RED             0xF800
#define MAGENTA         0xF81F
#define GREEN           0x07E0
#define CYAN            0x7FFF
#define YELLOW          0xFFE0
#define BROWN           0xBC40
#define BRRED           0xFC07                  // brownish red
#define GRAY            0x8430                  // gray
#define DARKBLUE        0x01CF                  // dark blue
#define LIGHTBLUE       0x7D7C                  // blue
#define GRAYBLUE        0x5458                  // gray-blue
#define LIGHTGREEN      0x841F                  // light green
#define LIGHTGRAY       0xC618                  // light gray

void write_cmd_tft(uint16_t command)
{
  gpio_write_bit(GPIOA, LCD_RS_Pin, LOW);           
  gpio_write_bit(GPIOA, LCD_CS_Pin, LOW);
  GPIOB->regs->ODR = command;               
  gpio_write_bit(GPIOA, LCD_WR_Pin, LOW);           
  delayMicroseconds(10);
  gpio_write_bit(GPIOA, LCD_WR_Pin, HIGH);
  gpio_write_bit(GPIOA, LCD_CS_Pin, HIGH);
}

void write_data16_tft(uint16_t data)
{
  gpio_write_bit(GPIOA, LCD_RS_Pin, HIGH);        
  gpio_write_bit(GPIOA, LCD_CS_Pin, LOW);
  GPIOB->regs->ODR = data;                        
  gpio_write_bit(GPIOA, LCD_WR_Pin, LOW);         
  delayMicroseconds(10);
  gpio_write_bit(GPIOA, LCD_WR_Pin, HIGH);
  gpio_write_bit(GPIOA, LCD_CS_Pin, HIGH);
}


#define cmd_write_ROM()     write_cmd_tft(0x22)       
#define cmd_write_pixel(color)  write_data16_tft(color)     

void write_reg_tft(uint16_t registerTFT, uint16_t dataTFT)
{
  write_cmd_tft(registerTFT);               
  write_data16_tft(dataTFT);                
}



void set_frame( uint16_t w1, uint16_t h1,                           
        uint16_t w2, uint16_t h2)                                   
{
  if ((w1 >= TFT_W)||(h1 >= TFT_H)||(w2 >= TFT_W)||(h2 >= TFT_H));  
  write_reg_tft(0x50,h1);                                           
  write_reg_tft(0x51,h2);                                           
  write_reg_tft(0x52,w1);                                           
  write_reg_tft(0x53,w2);                                           
  write_reg_tft(0x20,h1);                                           
  write_reg_tft(0x21,w1);
}


void draw_pixel(uint16_t w, uint16_t h, uint16_t color)
{
  write_reg_tft(0x20,h);                    
  write_reg_tft(0x21,w);                    
  write_reg_tft(0x22,color);                
}

void draw_point(uint16_t w, uint16_t h,           
        uint8_t size,                             
        uint16_t color)                           
{
  uint16_t i = (uint16_t)size*size;
  set_frame(w, h, w+size-1, h+size-1);          
  write_cmd_tft(0x22);                          
  while(i--)  write_data16_tft(color);          
}


void fill_color (uint16_t color)
{
  uint32_t i = (uint32_t)(TFT_W)*(TFT_H);         
  Serial2.print("Число пикселей: ");
  Serial2.println(i);
  set_frame(0, 0, TFT_W-1, TFT_H-1);              
  write_cmd_tft(0x22);                            
  while(i--) write_data16_tft(color);             
}

void init_tft (void)
{
  gpio_write_bit(GPIOA, LCD_RD_Pin, HIGH);        
  gpio_write_bit(GPIOA, LCD_RESET_Pin, LOW);
  delay(100);
  gpio_write_bit(GPIOA, LCD_RESET_Pin, HIGH);
  delay(100);

  write_reg_tft(0x01,0x0000);               
  write_reg_tft(0x02,0x0700);
  write_reg_tft(0x03,0x1038);               
  write_reg_tft(0x04,0x0000);
  write_reg_tft(0x07,0x0000);
  write_reg_tft(0x08,0x0302);
  write_reg_tft(0x09,0x0000);
  write_reg_tft(0x0A,0x0000);
  write_reg_tft(0x0C,0x0000);
  write_reg_tft(0x0D,0x0000);
  write_reg_tft(0x0F,0x0000);
  write_reg_tft(0x10,0x1290);
  write_reg_tft(0x11,0x0007);
  delay(100);
  write_reg_tft(0x12,0x0092);
  delay(100);
  write_reg_tft(0x13,0x0E00);
  delay(100);
  write_reg_tft(0x29,0x0005);
  write_reg_tft(0x2B,0x000E);

  write_reg_tft(0x30,0x0004);
  write_reg_tft(0x31,0x0307);
  write_reg_tft(0x32,0x0002);
  write_reg_tft(0x35,0x0206);
  write_reg_tft(0x36,0x0A00);
  write_reg_tft(0x37,0x0507);
  write_reg_tft(0x38,0x0204);
  write_reg_tft(0x39,0x0707);
  write_reg_tft(0x3C,0x0405);
  write_reg_tft(0x3D,0x0000);

  write_reg_tft(0x50,0x0000);
  write_reg_tft(0x51,0x00EF);
  write_reg_tft(0x52,0x0000);
  write_reg_tft(0x53,0x013F);

  write_reg_tft(0x60,0xA700);               
  write_reg_tft(0x61,0x0001);
  write_reg_tft(0x6A,0x0000);

  write_reg_tft(0x80,0x0000);
  write_reg_tft(0x81,0x0000);
  write_reg_tft(0x82,0x0000);
  write_reg_tft(0x83,0x0000);
  write_reg_tft(0x84,0x0000);
  write_reg_tft(0x85,0x0000);

  write_reg_tft(0x90,0x0029);
  write_reg_tft(0x92,0x0600);
  write_reg_tft(0x93,0x0003);
  write_reg_tft(0x95,0x0110);
  write_reg_tft(0x97,0x0000);
  write_reg_tft(0x98,0x0000);
  write_reg_tft(0x07,0x0133);

  fill_color(BLUE);                   
}

// the setup function runs once when you press reset or power the board
void setup() {
  // initialize GPIO pins  
  pinMode(PA9, OUTPUT);                             //LCD_RESET_Pin
  pinMode(PA8, OUTPUT);                             //LCD_CS_Pin
  pinMode(PA7, OUTPUT);                             //LCD_RS_Pin
  pinMode(PA6, OUTPUT);                             //LCD_WR_Pin
  pinMode(PA5, OUTPUT);                             //LCD_RD_Pin

  gpio_write_bit(GPIOA, LCD_RESET_Pin, HIGH);
  gpio_write_bit(GPIOA, LCD_CS_Pin, HIGH);
  gpio_write_bit(GPIOA, LCD_RS_Pin, HIGH);
  gpio_write_bit(GPIOA, LCD_WR_Pin, HIGH);
  gpio_write_bit(GPIOA, LCD_RD_Pin, HIGH);

  pinMode(PB15, OUTPUT);                             
  pinMode(PB14, OUTPUT);                             
  pinMode(PB13, OUTPUT);                             
  pinMode(PB12, OUTPUT);                             
  pinMode(PB11, OUTPUT);      
  pinMode(PB10, OUTPUT);                             
  pinMode(PB9, OUTPUT);                             
  pinMode(PB8, OUTPUT);
  pinMode(PB7, OUTPUT);                             
  pinMode(PB6, OUTPUT);                             
  pinMode(PB5, OUTPUT);                             
  pinMode(PB4, OUTPUT);                             
  pinMode(PB3, OUTPUT);      
  pinMode(PB2, OUTPUT);                             
  pinMode(PB1, OUTPUT);                             
  pinMode(PB0, OUTPUT);                          

  init_tft();                                  
}

// the loop function runs over and over again forever
void loop() {
}

它应该做的是初始化 LCD 并将其填充为蓝色。相反,它只是一个空白屏幕。

4

0 回答 0