標(biāo)題: STM32F103單片機(jī)的LCD12864程序 親測(cè)可用 [打印本頁(yè)]

作者: wliuxiaoxiaow    時(shí)間: 2022-4-1 22:02
標(biāo)題: STM32F103單片機(jī)的LCD12864程序 親測(cè)可用
STM32F103ZET6并行驅(qū)動(dòng)LCD12864的程序,親測(cè)可用

單片機(jī)源程序如下:
  1. #include "lcd.h"
  2. #include "sys.h"
  3. #include "delay.h"

  4. u16 temp;

  5. void IO_Init(void)
  6. {
  7.         GPIO_InitTypeDef GPIO_InitStructure;
  8.         RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA|RCC_APB2Periph_GPIOC,ENABLE);
  9.        
  10.         GPIO_InitStructure.GPIO_Mode=GPIO_Mode_Out_PP;
  11.         GPIO_InitStructure.GPIO_Pin=GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_2;
  12.         GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz;
  13.         GPIO_Init(GPIOC,&GPIO_InitStructure);
  14.        
  15.         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;
  16.         GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
  17.         GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz;
  18.         GPIO_Init(GPIOA,&GPIO_InitStructure);       
  19. }
  20. //LCD初始化
  21. void LCD_Init()
  22. {
  23.         LCD_wcmd(0x30);//功能設(shè)定:基本指令集
  24.         delay_ms(5);
  25.         LCD_wcmd(0x0C);//顯示開(kāi),關(guān)光標(biāo)
  26.         delay_ms(5);
  27.         LCD_wcmd(0x01);//清除顯示
  28. }
  29. //忙判斷
  30. void CheckBusy(void)
  31. {
  32.         u8 status;
  33.         RS=0;
  34.         RW=1;
  35.         GPIOA->ODR = 0xFF;//和這個(gè)有什么關(guān)系??
  36.         do
  37.         {
  38.                 EN = 1;
  39.                 delay_ms(5);
  40.                 status = GPIO_ReadInputDataBit(GPIOA, GPIO_Pin_7);//判斷BF位
  41.         }while(status & 0x80);
  42.         EN=0;
  43. }
  44. //LCD寫命令
  45. void LCD_wcmd(u8 cmd)
  46. {
  47.         CheckBusy();
  48.         RS=0;
  49.         RW=0;
  50.         delay_ms(5);
  51.         temp=(temp&0xff00)|cmd;
  52.         GPIO_Write(GPIOA,temp);
  53.         EN=1;
  54.         delay_ms(10);
  55.         EN=0;
  56. }
  57. //LCD寫數(shù)據(jù)
  58. void LCD_wdat(u8 dat)
  59. {
  60.         CheckBusy();
  61.         RS=1;
  62.         RW=0;
  63.         delay_ms(5);
  64.         temp=(temp&0xff00)|dat;
  65.         GPIO_Write(GPIOA,temp);
  66.         EN=1;
  67.         delay_ms(10);
  68.         EN=0;
  69. }
  70. //向LCD12864中寫入一行數(shù)據(jù)
  71. void LCD_Wmessage(u8* message,u8 address)
  72. {
  73.         LCD_wcmd(address);//要顯示的位置
  74.        
  75.         while(*message>0)//這個(gè)判斷很關(guān)鍵
  76.         {
  77.                 LCD_wdat(*message);
  78.                 message++;
  79.         }
  80. }
復(fù)制代碼

Keil代碼下載: 代碼.7z (186.01 KB, 下載次數(shù): 84)

作者: cdh98mail    時(shí)間: 2022-10-17 18:21
這個(gè)就是正點(diǎn)原子的例子程序,完全沒(méi)有必要下
作者: cdh98mail    時(shí)間: 2022-10-17 18:22
這個(gè)就是正點(diǎn)原子的例子程序,沒(méi)有必要下載。




歡迎光臨 (http://www.torrancerestoration.com/bbs/) Powered by Discuz! X3.1