秋·风

  博客园 :: 首页 :: 新随笔 :: 联系 :: 订阅 :: 管理 ::
昨天在tb买了1个st7789 240X240的1.3寸显示屏,今天终于调通:
先看显示效果:


注意:
拿到显示屏后测试一直不显示,检查了很久,发现要用spi1才能正常显示,还有,根据显示屏SPI的接法修改到相应的脚:

BL = 13
DC = 8
RST = 12
MOSI = 11
SCK = 10
CS = 9

 

program spi_st7789;
{$MODE OBJFPC}
{$H+}
{$MEMORY 20000,20000}
uses
  pico_spi_c,
  st7789_spi_c,
  CustomDisplay,
  pico_gpio_c,
  pico_timer_c,
  pico_c,
  pico_adc_c,

  Images.Paw,
  Fonts.BitstreamVeraSansMono13x24;

var
  spi  : TSPI_Registers absolute SPI1_BASE;
  st7789 : Tst7789_SPI;
  milliVolts,milliCelsius : longWord;
  strValue : string;

begin
  gpio_init(TPicoPin.LED);
  gpio_set_dir(TPicoPin.LED,TGPIODirection.GPIO_OUT);

  adc_init;
  adc_gpio_init(TPicoPin.ADC0);
  adc_set_temp_sensor_enabled(true);
  strValue := '';

  spi_init(spi,20000000);
  gpio_set_function(TPicoPin.GP9,  TGPIOFunction.GPIO_FUNC_SPI);
  gpio_set_function(TPicoPin.GP10, TGPIOFunction.GPIO_FUNC_SPI);
  gpio_set_function(TPicoPin.GP11,  TGPIOFunction.GPIO_FUNC_SPI);
  //gpio_set_function(TPicoPin.SPI_CS,  TGPIOFunction.GPIO_FUNC_SPI);
  //gpio_set_function(TPicoPin.SPI_SCK, TGPIOFunction.GPIO_FUNC_SPI);
  //gpio_set_function(TPicoPin.SPI_TX,  TGPIOFunction.GPIO_FUNC_SPI);

  st7789.Initialize(spi,TPicoPin.GP8,TPicoPin.GP12,st7789.ScreenSize240x240x16);
  st7789.setFontInfo(BitstreamVeraSansMono13x24);

  repeat
    gpio_put(TPicoPin.LED,true);

    //adc_select_input(0);
    // Avoiding floating point math as it currently seems to be in no good shape (on Cortex-M0, not only pico)
    //milliVolts := (adc_read * 3300) div 4096;

     //Select internal temperature sensor
    adc_select_input(4);
    milliVolts := (adc_read * 3300) div 4096;
    str(milliVolts,strValue);

    st7789.ForegroundColor := clWhite;
    st7789.BackgroundColor := clRed;
    st7789.SetRotation(TDisplayRotation.None);
    st7789.ClearScreen;
    st7789.drawText('temperature:'+strValue,2,2);
    //st7789.drawText('Red',2,2);
    st7789.drawRect(0,0,st7789.ScreenWidth,st7789.ScreenHeight);
    st7789.drawCircle(st7789.ScreenWidth div 2,st7789.ScreenHeight div 2,25);
    busy_wait_us_32(1500000);

    gpio_put(TPicoPin.LED,false);
    st7789.ForegroundColor := clWhite;
    st7789.BackgroundColor := clLime;
    st7789.SetRotation(TDisplayRotation.Right);
    st7789.ClearScreen;
    st7789.drawText('Lime',2,2);
    st7789.drawRect(0,0,st7789.ScreenWidth,st7789.ScreenHeight);
    st7789.FillCircle(st7789.ScreenWidth div 2,st7789.ScreenHeight div 2,25);
    busy_wait_us_32(1500000);

    gpio_put(TPicoPin.LED,true);
    st7789.ForegroundColor := clWhite;
    st7789.BackgroundColor := clBlue;
    st7789.SetRotation(TDisplayRotation.UpsideDown);
    st7789.ClearScreen;
    st7789.drawText('Blue',5,5);
    st7789.drawRoundRect(0,0,st7789.ScreenWidth,st7789.ScreenHeight,15);
    st7789.drawLine(25,25,st7789.ScreenWidth-25,st7789.ScreenHeight-25);
    st7789.drawLine(25,st7789.ScreenHeight-25,st7789.ScreenWidth-25,25);
    busy_wait_us_32(1500000);

    gpio_put(TPicoPin.LED,false);
    st7789.ForegroundColor := clBlack;
    st7789.BackgroundColor := clWhite;
    st7789.SetRotation(TDisplayRotation.Left);
    st7789.ClearScreen;
    st7789.drawText('Hello',2,2,clBlack);
    st7789.drawText('FreePascal',2,st7789.ScreenHeight-2-st7789.FontInfo.Height,clBlack);
    st7789.drawImage(st7789.ScreenWidth div 2 - 32, st7789.ScreenHeight div 2 - 32,paw64x64x4);
    busy_wait_us_32(1500000);
  until 1=0;
end.

 

posted on 2025-07-18 16:16  秋·风  阅读(158)  评论(1)    收藏  举报