stm3212864液晶的使用的程序
时间: 2024-03-31 14:33:42 浏览: 52
液晶的使用需要涉及到很多方面,包括硬件驱动、软件编程等。下面是一个简单的液晶使用程序示例,以供参考:
```c
#include "stm32f1xx.h"
#include "stdio.h"
#include "stdlib.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');
while(1);
}
```
这是一个使用STM32F1的GPIO驱动液晶屏的示例代码。需要注意的是,不同型号的液晶有不同的接口和驱动方式,具体实现可能会有所不同。
阅读全文