打印
[STM32U5]

【NUCLEO-U575ZI-Q测评】HT1621

[复制链接]
554|1
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
今天搞了一下HT1621模块。
DA接PC10,WR接PD9,CS接PF7。
代码:
#include "main.h"

/* Private includes ----------------------------------------------------------*/
/* USER CODE BEGIN Includes */
#define DA_PIN                                GPIO_PIN_10
#define DA_GPIO_PORT                          GPIOC
#define DA_GPIO_CLK_ENABLE()                  __HAL_RCC_GPIOC_CLK_ENABLE()
#define DA_GPIO_CLK_DISABLE()                 __HAL_RCC_GPIOC_CLK_DISABLE()

#define WR_PIN                                GPIO_PIN_9
#define WR_GPIO_PORT                          GPIOD
#define WR_GPIO_CLK_ENABLE()                  __HAL_RCC_GPIOD_CLK_ENABLE()
#define WR_GPIO_CLK_DISABLE()                 __HAL_RCC_GPIOD_CLK_DISABLE()

#define CS_PIN                                GPIO_PIN_7
#define CS_GPIO_PORT                          GPIOF
#define CS_GPIO_CLK_ENABLE()                  __HAL_RCC_GPIOF_CLK_ENABLE()
#define CS_GPIO_CLK_DISABLE()                 __HAL_RCC_GPIOF_CLK_DISABLE()


#define CS_0           HAL_GPIO_WritePin(CS_GPIO_PORT,CS_PIN,GPIO_PIN_RESET)
#define CS_1           HAL_GPIO_WritePin(CS_GPIO_PORT,CS_PIN,GPIO_PIN_SET)
#define WR_0           HAL_GPIO_WritePin(WR_GPIO_PORT,WR_PIN,GPIO_PIN_RESET)
#define WR_1           HAL_GPIO_WritePin(WR_GPIO_PORT,WR_PIN,GPIO_PIN_SET)
#define DA_0           HAL_GPIO_WritePin(DA_GPIO_PORT,DA_PIN,GPIO_PIN_RESET)
#define DA_1           HAL_GPIO_WritePin(DA_GPIO_PORT,DA_PIN,GPIO_PIN_SET)


#define BIAS  0x52   //0b1000 0101 0010  1/3duty 4com

#define SYSDIS  0X00    //0b1000 0000 0000  ???????LCD?????

#define SYSEN 0X02 //0b1000 0000 0010 ???????

#define LCDOFF  0X04 //0b1000 0000 0100  ?LCD??

#define LCDON  0X06 //0b1000 0000 0110  ??LCD??

#define XTAL 0x28  //0b1000 0010 1000 ?????

#define RC256    0X30  //0b1000 0011 0000  ????

#define WDTDIS1   0X0A    //0b1000 0000 1010  ?????

/* USER CODE END Includes */
#define uchar unsigned char

#define uint unsigned int


/* USER CODE BEGIN PV */
static GPIO_InitTypeDef  GPIO_InitStruct;

/* USER CODE END PV */

/* Private function prototypes -----------------------------------------------*/
void SystemClock_Config(void);
static void SystemPower_Config(void);
static void MX_ICACHE_Init(void);
/* USER CODE BEGIN PFP */



unsigned int tmp;

unsigned int n1, n2, n3, n4;

unsigned char Ht1621Tab[]={0x00,0x00,0x00,0x00};

//unsigned char DispTab[]={0x7B,0x12,0x67,0x57,0x1E,0x5D,0x7D,0x13,0x7F,0x5F,0x69,0x45,0x3f, 0x7a, 0x3e};

//          0    1    2    3    4    5    6    7    8    9    C    ?   A     V     H

unsigned char DispTab[]={0x7B,0x12,0x67,0x57,0x1E,0x5D,0x7D,0x13,0x7F,0x5F,0x3F,0x7C,0x69,0x76,0x6D, 0x2D};

//          0    1    2    3    4    5    6    7    8    9    A    b   C     d     E      F






void Ht1621_CS_0() { CS_0;}   // define P2.2 ---> CS

void Ht1621_CS_1() { CS_1;}



void Ht1621_WR_0() { WR_0;} // define P2.1 ---> WR

void Ht1621_WR_1() { WR_1;}



void Ht1621_DO_0() { DA_0;} // define P2.0 ---> DAT

void Ht1621_DO_1() { DA_1;}







unsigned int counter;



//-----------------------------------------------------------------------------------------
//????:Delay()
//?    ?:?????
//-----------------------------------------------------------------------------------------
void Delay(uint  us)  //5,7,9
{
  while(--us);
}

//-----------------------------------------------------------------------------------------
//????:Delayms()
//-----------------------------------------------------------------------------------------
void Delayms(unsigned int ims)
{
  unsigned int i,j;
    for(i=0;i<ims;i++)
      for(j=0;j<65;j++) { Delay(1); }
}

//-----------------------------------------------------------------------------------------
//Ht1621Wr_Data()
//-----------------------------------------------------------------------------------------
void Ht1621Wr_Data(unsigned char Data,unsigned char cnt)
{
  unsigned char i;
  for (i=0;i<cnt;i++)
   {
     Ht1621_WR_0();
     HAL_Delay(1);
     if((Data & 0x80)==0x80) {Ht1621_DO_1();HAL_Delay(10);}
     else {Ht1621_DO_0();HAL_Delay(10);}
     Ht1621_WR_1();
     HAL_Delay(1);
     Data<<=1;
   }
}
//-----------------------------------------------------------------------------------------
//void Ht1621WrCmd(uchar Cmd)
//-----------------------------------------------------------------------------------------
void Ht1621WrCmd(unsigned char Cmd)
{
   Ht1621_CS_0();
   HAL_Delay(1);
   Ht1621Wr_Data(0x80,4);          //??????100
   Ht1621Wr_Data(Cmd,8);           //??????
   Ht1621_CS_1();
   HAL_Delay(1);
}
//-----------------------------------------------------------------------------------------
//void Ht1621WrOneData(uchar Addr,uchar Data)
//-----------------------------------------------------------------------------------------
void Ht1621WrOneData(unsigned char Addr,unsigned char Data)
{
  Ht1621_CS_0();
  Ht1621Wr_Data(0xa0,3);  //??????101
  Ht1621Wr_Data(Addr<<2,6); //??????
  Ht1621Wr_Data(Data,4); //???????? 7  6  5  4
  Ht1621_CS_1();
}
//-----------------------------------------------------------------------------------------
//void Ht1621WrAllData()
//-----------------------------------------------------------------------------------------
void Ht1621WrAllData(unsigned char Addr,unsigned char *p,unsigned char cnt)
{
  unsigned char i;
  Ht1621_CS_0();
  Ht1621Wr_Data(0xa0,3); //??????101
  Ht1621Wr_Data(Addr<<2,6); //??????
  for (i=0;i<cnt;i++)
   {
    Ht1621Wr_Data(*p,8); //????
    p++;
   }
  Ht1621_CS_1();
}

//-----------------------------------------------------------------------------------------
//void Ht1621_Init(void)
//-----------------------------------------------------------------------------------------
void Ht1621_Init(void)
{
   Ht1621WrCmd(BIAS);
   Ht1621WrCmd(RC256);             //???????
   //Ht1621WrCmd(XTAL);             //???????
   Ht1621WrCmd(SYSDIS);
   Ht1621WrCmd(WDTDIS1);
   Ht1621WrCmd(SYSEN);
   Ht1621WrCmd(LCDON);
}

//-----------------------------------------------------------------------------------------
//DISPLAY
//-----------------------------------------------------------------------------------------
void Display(void)
{
   unsigned char com;
   com = 0;
   if((DispTab[n1]&0x01) == 0x01){ com = com + 0x10;}
   if((DispTab[n2]&0x01) == 0x01){ com = com + 0x20;}
   if((DispTab[n3]&0x01) == 0x01){ com = com + 0x40;}
   if((DispTab[n4]&0x01) == 0x01){ com = com + 0x80;}
   Ht1621WrOneData(0 , com);
   com = 0;
   if((DispTab[n1]&0x02) == 0x02){ com = com + 0x10;}
   if((DispTab[n2]&0x02) == 0x02){ com = com + 0x20;}
   if((DispTab[n3]&0x02) == 0x02){ com = com + 0x40;}
   if((DispTab[n4]&0x02) == 0x02){ com = com + 0x80;}
   Ht1621WrOneData(1 , com);
   com = 0;
   if((DispTab[n1]&0x10) == 0x10){ com = com + 0x10;}
   if((DispTab[n2]&0x10) == 0x10){ com = com + 0x20;}
   if((DispTab[n3]&0x10) == 0x10){ com = com + 0x40;}
   if((DispTab[n4]&0x10) == 0x10){ com = com + 0x80;}
   Ht1621WrOneData(2 , com);
   com = 0;
   if((DispTab[n1]&0x40) == 0x40){ com = com + 0x10;}
   if((DispTab[n2]&0x40) == 0x40){ com = com + 0x20;}
   if((DispTab[n3]&0x40) == 0x40){ com = com + 0x40;}
   if((DispTab[n4]&0x40) == 0x40){ com = com + 0x80;}
   Ht1621WrOneData(3 , com);
   com = 0;
   if((DispTab[n1]&0x20) == 0x20){ com = com + 0x10;}
   if((DispTab[n2]&0x20) == 0x20){ com = com + 0x20;}
   if((DispTab[n3]&0x20) == 0x20){ com = com + 0x40;}
   if((DispTab[n4]&0x20) == 0x20){ com = com + 0x80;}
   Ht1621WrOneData(4 , com);
   com = 0;
   if((DispTab[n1]&0x08) == 0x08){ com = com + 0x10;}
   if((DispTab[n2]&0x08) == 0x08){ com = com + 0x20;}
   if((DispTab[n3]&0x08) == 0x08){ com = com + 0x40;}
   if((DispTab[n4]&0x08) == 0x08){ com = com + 0x80;}
   Ht1621WrOneData(5 , com);
   com = 0;
   if((DispTab[n1]&0x04) == 0x04){ com = com + 0x10;}
   if((DispTab[n2]&0x04) == 0x04){ com = com + 0x20;}
   if((DispTab[n3]&0x04) == 0x04){ com = com + 0x40;}
   if((DispTab[n4]&0x04) == 0x04){ com = com + 0x80;}
   Ht1621WrOneData(6 , com);
}

//-----------------------------------------------------------------------------------------
//Display_lcd_dot
//-----------------------------------------------------------------------------------------
void Display_lcd_dot(void)
{
   Ht1621WrOneData(7 , 0x50);

}

//-----------------------------------------------------------------------------------------
//convertor()
//-----------------------------------------------------------------------------------------

void data_convertor(unsigned long adc_value)
{
    tmp=adc_value;         //adc

    n4=tmp/1000;

    n3=tmp%1000/100;

    n2=tmp%100/10;
                 // 4
    n1=tmp%10;       //display "C"

}



/* Private typedef -----------------------------------------------------------*/
/* USER CODE BEGIN PTD */

/* USER CODE END PTD */

/* Private define ------------------------------------------------------------*/
/* USER CODE BEGIN PD */

/* USER CODE END PD */

/* Private macro -------------------------------------------------------------*/
/* USER CODE BEGIN PM */

/* USER CODE END PM */

/* Private variables ---------------------------------------------------------*/




/* USER CODE END PFP */

/* Private user code ---------------------------------------------------------*/
/* USER CODE BEGIN 0 */

/* USER CODE END 0 */

/**
  * [url=home.php?mod=space&uid=247401]@brief[/url]  The application entry point.
  * @retval int
  */
int main(void)
{
  /* USER CODE BEGIN 1 */
  /* STM32U5xx HAL library initialization:
       - Configure the Flash prefetch
       - Configure the Systick to generate an interrupt each 1 msec
       - Set NVIC Group Priority to 3
       - Low Level Initialization
     */
  /* USER CODE END 1 */

  /* MCU Configuration--------------------------------------------------------*/

  /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
  HAL_Init();

  /* USER CODE BEGIN Init */

  /* USER CODE END Init */

  /* Configure the system clock */
  SystemClock_Config();

  /* Configure the System Power */
  SystemPower_Config();

  /* USER CODE BEGIN SysInit */

  /* USER CODE END SysInit */

  /* Initialize all configured peripherals */
  MX_ICACHE_Init();
  /* USER CODE BEGIN 2 */

   /* -1- Enable GPIO Clock (to be able to program the configuration registers) */
  LED1_GPIO_CLK_ENABLE();
  LED2_GPIO_CLK_ENABLE();
        DA_GPIO_CLK_ENABLE();
        WR_GPIO_CLK_ENABLE();
        CS_GPIO_CLK_ENABLE();
  /* -2- Configure IO in output push-pull mode to drive external LEDs */
  GPIO_InitStruct.Mode  = GPIO_MODE_OUTPUT_PP;
  GPIO_InitStruct.Pull  = GPIO_NOPULL;
  GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
       
        GPIO_InitStruct.Pin = LED1_PIN;
  HAL_GPIO_Init(LED1_GPIO_PORT, &GPIO_InitStruct);
  GPIO_InitStruct.Pin = LED2_PIN;
  HAL_GPIO_Init(LED2_GPIO_PORT, &GPIO_InitStruct);

  /* USER CODE END 2 */
        GPIO_InitStruct.Pin = CS_PIN;
  HAL_GPIO_Init(CS_GPIO_PORT, &GPIO_InitStruct);
  GPIO_InitStruct.Pin = WR_PIN;
  HAL_GPIO_Init(WR_GPIO_PORT, &GPIO_InitStruct);
        GPIO_InitStruct.Pin = DA_PIN;
  HAL_GPIO_Init(DA_GPIO_PORT, &GPIO_InitStruct);
       
       
  /* Infinite loop */
        counter = 235;
        Ht1621_Init();        //?????LCD
        HAL_Delay(1000);           //??????
        Ht1621WrAllData(0,Ht1621Tab,16);// Clear LCD display
        Ht1621_Init();   
        data_convertor(counter);
        Display();
  /* USER CODE BEGIN WHILE */
  while (1)
  {
    /* USER CODE END WHILE */
//                counter = 235;
//                Ht1621_Init();        //?????LCD
//                Delay(1000);           //??????
//                Ht1621WrAllData(0,Ht1621Tab,16);// Clear LCD display
//                Ht1621_Init();   
//                data_convertor(counter);
//                Display();
    /* USER CODE BEGIN 3 */
//    HAL_GPIO_TogglePin(DA_GPIO_PORT,GPIO_PIN_10);
//                Delay(1000);
    /* Insert delay 100 ms */
//    HAL_GPIO_TogglePin(WR_GPIO_PORT,WR_PIN);
//                HAL_Delay(1000);
               
  }
  /* USER CODE END 3 */
}

/**
  * @brief System Clock Configuration
  * @retval None
  */
void SystemClock_Config(void)
{
  RCC_OscInitTypeDef RCC_OscInitStruct = {0};
  RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};

  /** Configure the main internal regulator output voltage
  */
  if (HAL_PWREx_ControlVoltageScaling(PWR_REGULATOR_VOLTAGE_SCALE1) != HAL_OK)
  {
    Error_Handler();
  }

  /** Initializes the CPU, AHB and APB busses clocks
  */
  RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_MSI;
  RCC_OscInitStruct.MSIState = RCC_MSI_ON;
  RCC_OscInitStruct.MSICalibrationValue = RCC_MSICALIBRATION_DEFAULT;
  RCC_OscInitStruct.MSIClockRange = RCC_MSIRANGE_4;
  RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
  RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_MSI;
  RCC_OscInitStruct.PLL.PLLMBOOST = RCC_PLLMBOOST_DIV1;
  RCC_OscInitStruct.PLL.PLLM = 1;
  RCC_OscInitStruct.PLL.PLLN = 80;
  RCC_OscInitStruct.PLL.PLLP = 2;
  RCC_OscInitStruct.PLL.PLLQ = 2;
  RCC_OscInitStruct.PLL.PLLR = 2;
  RCC_OscInitStruct.PLL.PLLRGE = RCC_PLLVCIRANGE_0;
  RCC_OscInitStruct.PLL.PLLFRACN = 0;
  if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
  {
    Error_Handler();
  }

  /** Initializes the CPU, AHB and APB busses clocks
  */
  RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
                              |RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2
                              |RCC_CLOCKTYPE_PCLK3;
  RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
  RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
  RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1;
  RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;
  RCC_ClkInitStruct.APB3CLKDivider = RCC_HCLK_DIV1;

  if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_4) != HAL_OK)
  {
    Error_Handler();
  }
}

/**
  * @brief Power Configuration
  * @retval None
  */
static void SystemPower_Config(void)
{

  /*
   * Disable the internal Pull-Up in Dead Battery pins of UCPD peripheral
   */
  HAL_PWREx_DisableUCPDDeadBattery();

  /*
   * Switch to SMPS regulator instead of LDO
   */
  if (HAL_PWREx_ConfigSupply(PWR_SMPS_SUPPLY) != HAL_OK)
  {
    Error_Handler();
  }
}

/**
  * @brief ICACHE Initialization Function
  * @param None
  * @retval None
  */
static void MX_ICACHE_Init(void)
{

  /* USER CODE BEGIN ICACHE_Init 0 */

  /* USER CODE END ICACHE_Init 0 */

  /* USER CODE BEGIN ICACHE_Init 1 */

  /* USER CODE END ICACHE_Init 1 */

  /** Enable instruction cache in 1-way (direct mapped cache)
  */
  if (HAL_ICACHE_ConfigAssociativityMode(ICACHE_1WAY) != HAL_OK)
  {
    Error_Handler();
  }
  if (HAL_ICACHE_Enable() != HAL_OK)
  {
    Error_Handler();
  }
  /* USER CODE BEGIN ICACHE_Init 2 */

  /* USER CODE END ICACHE_Init 2 */

}

/* USER CODE BEGIN 4 */
/* USER CODE END 4 */

/**
  * @brief  This function is executed in case of error occurrence.
  * @retval None
  */
void Error_Handler(void)
{
  /* USER CODE BEGIN Error_Handler_Debug */
  /* User can add his own implementation to report the HAL error return state */
  while(1)
  {
  }
  /* USER CODE END Error_Handler_Debug */
}

#ifdef  USE_FULL_ASSERT
/**
  * @brief  Reports the name of the source file and the source line number
  *         where the assert_param error has occurred.
  * @param  file: pointer to the source file name
  * @param  line: assert_param error line source number
  * @retval None
  */
void assert_failed(uint8_t *file, uint32_t line)
{
  /* USER CODE BEGIN 6 */
  /* User can add his own implementation to report the file name and line number,
    ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
  /* Infinite loop */
  while (1)
  {
  }

  /* USER CODE END 6 */
}
#endif /* USE_FULL_ASSERT */
效果图:

使用特权

评论回复
沙发
Henryko| | 2024-1-12 16:17 | 只看该作者
这个屏幕走的什么协议啊

使用特权

评论回复
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

467

主题

3517

帖子

7

粉丝