STM32F103RC并口驱动TG12232
时间: 2023-09-03 12:12:08 浏览: 64
TG12232是一款128x32的点阵液晶屏,它采用ST7920控制芯片。在STM32F103RC上使用并口驱动TG12232可以参考以下步骤:
1. 确定并口引脚
TG12232使用的是并口通信,需要选择合适的引脚进行连接。在STM32F103RC上,可以使用GPIO口实现并口通信,需要选择8个连续的GPIO引脚,包括数据口(D0-D7)和控制口(RS,RW,E,PSB)。
2. 编写控制程序
在控制程序中,需要先对TG12232进行初始化,包括设置显示模式、光标位置等。然后根据需要进行屏幕显示、清屏、光标控制等操作。具体的控制命令可以参考TG12232的数据手册。
3. 连接TG12232
将STM32F103RC的并口引脚与TG12232相应的引脚连接起来,注意要按照对应关系连接。
4. 软件调试
将编写好的程序烧录到STM32F103RC上,通过串口调试工具进行调试,观察TG12232是否正常显示。如果出现问题可以通过调试工具进行查看,找出问题所在。
参考代码:
```c
#include "stm32f10x.h"
#define TG12232_PORT GPIOB //并口所在的GPIO端口
#define TG12232_RS GPIO_Pin_0 //控制口RS引脚
#define TG12232_RW GPIO_Pin_1 //控制口RW引脚
#define TG12232_E GPIO_Pin_2 //控制口E引脚
#define TG12232_PSB GPIO_Pin_3 //控制口PSB引脚
#define TG12232_D0 GPIO_Pin_4 //数据口D0引脚
#define TG12232_D1 GPIO_Pin_5 //数据口D1引脚
#define TG12232_D2 GPIO_Pin_6 //数据口D2引脚
#define TG12232_D3 GPIO_Pin_7 //数据口D3引脚
#define TG12232_D4 GPIO_Pin_8 //数据口D4引脚
#define TG12232_D5 GPIO_Pin_9 //数据口D5引脚
#define TG12232_D6 GPIO_Pin_10 //数据口D6引脚
#define TG12232_D7 GPIO_Pin_11 //数据口D7引脚
void TG12232_GPIO_Init(void);
void TG12232_WriteCommand(uint8_t command);
void TG12232_WriteData(uint8_t data);
void TG12232_Init(void);
void TG12232_DisplayChar(uint8_t x, uint8_t y, uint8_t c);
int main(void)
{
TG12232_GPIO_Init();
TG12232_Init();
TG12232_DisplayChar(0, 0, 'H');
TG12232_DisplayChar(1, 0, 'e');
TG12232_DisplayChar(2, 0, 'l');
TG12232_DisplayChar(3, 0, 'l');
TG12232_DisplayChar(4, 0, 'o');
while(1);
}
void TG12232_GPIO_Init(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE);
GPIO_InitStructure.GPIO_Pin = TG12232_RS | TG12232_RW | TG12232_E | TG12232_PSB | TG12232_D0 | TG12232_D1 | TG12232_D2 | TG12232_D3 | TG12232_D4 | TG12232_D5 | TG12232_D6 | TG12232_D7;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(TG12232_PORT, &GPIO_InitStructure);
}
void TG12232_WriteCommand(uint8_t command)
{
GPIO_ResetBits(TG12232_PORT, TG12232_RS);
GPIO_ResetBits(TG12232_PORT, TG12232_RW);
GPIO_SetBits(TG12232_PORT, TG12232_E);
GPIO_Write(GPIOB, command);
GPIO_ResetBits(TG12232_PORT, TG12232_E);
}
void TG12232_WriteData(uint8_t data)
{
GPIO_SetBits(TG12232_PORT, TG12232_RS);
GPIO_ResetBits(TG12232_PORT, TG12232_RW);
GPIO_SetBits(TG12232_PORT, TG12232_E);
GPIO_Write(GPIOB, data);
GPIO_ResetBits(TG12232_PORT, TG12232_E);
}
void TG12232_Init(void)
{
TG12232_WriteCommand(0x30); //基本指令集1,8位数据总线,基本指令集2和扩展指令集无效
TG12232_WriteCommand(0x0C); //显示开,光标关,闪烁关
TG12232_WriteCommand(0x01); //清屏
TG12232_WriteCommand(0x06); //光标移动方向:右,字符不移动
}
void TG12232_DisplayChar(uint8_t x, uint8_t y, uint8_t c)
{
uint8_t address;
address = x + y * 16;
TG12232_WriteCommand(0x80 | address);
TG12232_WriteData(c);
}
```