程序代码
main.c
unsigned char str[]={"hello123"};/** * [url=home.php?mod=space&uid=247401]@brief[/url] The application entry point. * @retval int */int main(void){ /* 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(); /* USER CODE BEGIN SysInit */ /* USER CODE END SysInit */ /* Initialize all configured peripherals */ MX_GPIO_Init(); MX_ADC1_Init(); // MX_USART1_UART_Init(); MX_TIM1_Init(); /* USER CODE BEGIN 2 */ /* USER CODE END 2 */ /* Infinite loop */ /* USER CODE BEGIN WHILE */ LCD_INIT(); LCD_WRITE_StrDATA(str,1,0); while(1) { /* USER CODE BEGIN 3 */ } /* USER CODE END 3 */}
LCD1602.c
void LCD_INIT(void){ //初始化// HAL_GPIO_Write(GPIOC,0x00ff); //GPIO_WRITE_u8_data(GPIOC,0x00); delay_us(500); LCD_WRITE_CMD( 0x38 ); LCD_WRITE_CMD( 0x0c ); //开启光标和闪烁 LCD_WRITE_CMD( 0x06 ); LCD_WRITE_CMD( 0x01 ); //清屏}void LCD_WRITE_StrDATA(volatile unsigned char *StrData,volatile unsigned char row,volatile unsigned char col ){//写入字符串 unsigned char baseAddr = 0x00; //定义8位地址 if (row){ baseAddr = 0xc0; }else{ baseAddr = 0x80; } //row为1用户选择第二行 //row为0用户选择第一行 baseAddr += col; while ( *StrData != '\0' ){ LCD_WRITE_CMD( baseAddr ); LCD_WRITE_ByteDATA( *StrData ); baseAddr++; //每次循环地址加一,数据指针加一 StrData++; }}
|