stm3212864液晶的使用的程序输出欢迎使用
时间: 2024-03-31 16:33:45 浏览: 45
以下是在液晶屏上输出欢迎使用的示例代码,你可以根据自己的实际情况进行修改:
```c
#include "stm32f1xx.h"
#define LCD_RS_SET GPIOB->BSRR = GPIO_BSRR_BS5
#define LCD_RS_CLR GPIOB->BSRR = GPIO_BSRR_BR5
#define LCD_RW_SET GPIOB->BSRR = GPIO_BSRR_BS6
#define LCD_RW_CLR GPIOB->BSRR = GPIO_BSRR_BR6
#define LCD_EN_SET GPIOB->BSRR = GPIO_BSRR_BS7
#define LCD_EN_CLR GPIOB->BSRR = GPIO_BSRR_BR7
void LCD_Write_Cmd(uint8_t cmd)
{
LCD_RS_CLR;
LCD_RW_CLR;
GPIOA->ODR = cmd;
LCD_EN_SET;
LCD_EN_CLR;
}
void LCD_Write_Data(uint8_t data)
{
LCD_RS_SET;
LCD_RW_CLR;
GPIOA->ODR = data;
LCD_EN_SET;
LCD_EN_CLR;
}
void LCD_Init()
{
RCC->APB2ENR |= RCC_APB2ENR_IOPAEN | RCC_APB2ENR_IOPBEN;
GPIOA->CRL |= GPIO_CRL_MODE0 | GPIO_CRL_MODE1 | GPIO_CRL_MODE2 | GPIO_CRL_MODE3 | GPIO_CRL_MODE4 | GPIO_CRL_MODE5 | GPIO_CRL_MODE6 | GPIO_CRL_MODE7;
GPIOA->CRL &= ~(GPIO_CRL_CNF0 | GPIO_CRL_CNF1 | GPIO_CRL_CNF2 | GPIO_CRL_CNF3 | GPIO_CRL_CNF4 | GPIO_CRL_CNF5 | GPIO_CRL_CNF6 | GPIO_CRL_CNF7);
GPIOB->CRL |= GPIO_CRL_MODE5 | GPIO_CRL_MODE6 | GPIO_CRL_MODE7;
GPIOB->CRL &= ~(GPIO_CRL_CNF5 | GPIO_CRL_CNF6 | GPIO_CRL_CNF7);
LCD_Write_Cmd(0x38);
LCD_Write_Cmd(0x08);
LCD_Write_Cmd(0x01);
LCD_Write_Cmd(0x06);
LCD_Write_Cmd(0x0C);
}
int main()
{
LCD_Init();
LCD_Write_Data('H');
LCD_Write_Data('e');
LCD_Write_Data('l');
LCD_Write_Data('l');
LCD_Write_Data('o');
LCD_Write_Cmd(0xC0); // 设置光标位置为第2行第1列
LCD_Write_Data('W');
LCD_Write_Data('e');
LCD_Write_Data('l');
LCD_Write_Data('c');
LCD_Write_Data('o');
LCD_Write_Data('m');
LCD_Write_Data('e');
LCD_Write_Data('!');
while(1);
}
```
该程序会在液晶屏上输出"Hello"和"Welcome!",并将光标位置设置到第2行第1列。
阅读全文