基于MDK编译器 STM32与12864液晶显示程序 和电路连接

连接[转载]基于MDK编译器 <wbr>STM32与12864液晶显示程序 <wbr>和电路连接

[转载]基于MDK编译器 <wbr>STM32与12864液晶显示程序 <wbr>和电路连接

这里用的12864液晶是5v的,电路链接部分 RS PE2 RW PE4 EN PE6  15口PSB串并 PE3

#include "stm32f10x.h"

GPIO_InitTypeDef GPIO_InitStructure;

#define RS_SET  GPIO_SetBits(GPIOE, GPIO_Pin_2)

#define RS_CLR  GPIO_ResetBits(GPIOE, GPIO_Pin_2)

#define RW_SET  GPIO_SetBits(GPIOE, GPIO_Pin_4)

#define RW_CLR  GPIO_ResetBits(GPIOE, GPIO_Pin_4)

#define EN_SET  GPIO_SetBits(GPIOE, GPIO_Pin_6)

#define EN_CLR  GPIO_ResetBits(GPIOE, GPIO_Pin_6)

#define PSB_SET  GPIO_SetBits(GPIOE, GPIO_Pin_3)

#define PSB_CLR  GPIO_ResetBits(GPIOE, GPIO_Pin_3)

#define DATA_IO GPIOC->ODR

void RCC_Configuration(void);

void LCD12864_Config(void);

void Delay_nus(__IO uint32_t nCount);

void Delay_mus(__IO uint32_t nCount);

uint8_t table[]="做我女朋友吧!";

void write_12864com(uint8_t com)

{

RW_CLR;

RS_CLR;

Delay_nus(500);

DATA_IO=com;

EN_SET;

Delay_nus(1000);

EN_CLR;

Delay_nus(1000);

}

void write_12864dat(uint8_t dat)

{

RW_CLR;

RS_SET;

Delay_nus(500);

DATA_IO=dat;

EN_SET;

Delay_nus(1000);

EN_CLR;

Delay_nus(1000);

}

void init12864lcd(void)

{

Delay_mus(500);

write_12864com(0x30);

Delay_nus(500);

write_12864com(0x30);

Delay_nus(500);

write_12864com(0x0f);

Delay_nus(500);

write_12864com(0x01);

Delay_nus(25);

write_12864com(0x06);

Delay_nus(2500);

write_12864com(0x0c);

Delay_nus(500);

}

void display(void)

{

uint8_t i;

write_12864com(0x80);

for(i=0;i<14;i++)

{

write_12864dat(table[i]);

Delay_mus(50);

}

}

void LCD12864_Config(void)

{

  RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOE | RCC_APB2Periph_GPIOC , ENABLE);

  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2|GPIO_Pin_3|GPIO_Pin_4|GPIO_Pin_6;  

  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;

  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;

  GPIO_Init(GPIOE, &GPIO_InitStructure);  

  

  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0|GPIO_Pin_1|GPIO_Pin_2|GPIO_Pin_3

     |GPIO_Pin_4|GPIO_Pin_5|GPIO_Pin_6|GPIO_Pin_7;  

  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;

  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;

  GPIO_Init(GPIOC, &GPIO_InitStructure);

}

int main(void)

{

  RCC_Configuration();  //系统时钟配置

  LCD12864_Config(); 

  PSB_SET; 

  init12864lcd();

  while (1)

  {

     display();

  }

}

void RCC_Configuration(void)

{   

  SystemInit();

}

void Delay_nus(uint32_t nCount)

{

 uint32_t j;

 while(nCount--)

 { 

    j=8;

    while(j--);

 }

}

void Delay_mus(uint32_t nCount)

{

    while(nCount--)

    Delay_nus(1100);

}

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值