Home > other >  The LCD1602 stm32F103 driver program I wrote why not show
The LCD1602 stm32F103 driver program I wrote why not show

Time:09-18

This is the program I wrote, did not show, just began to learn the LCD and stm32, don't know lack what part and write wrong, have a big help to have a look at it


The header file:
# # ifndef _LCD_H_
# define _LCD_H_
# include "stm32f10x. H"



///by defining a belt operation control RS RW EN

# define BITBAND (addr, bitnum) ((addr & amp; 0 xf0000000) + 0 x2000000 + ((addr & amp; 0 XFFFFF) & lt; <5) + (bitnum<2))
# define MEM_ADDR (addr) * ((volatile unsigned long *) (addr))
# define BIT_ADDR (addr, bitnum) MEM_ADDR (BITBAND (addr, bitnum))

# define GPIOA_ODR_Addr (GPIOA_BASE + 12)//0 x40010c0c
# define GPIOA_IDR_Addr (GPIOA_BASE + 8)//0 x40010c08

# define PAout (n) BIT_ADDR (GPIOA_ODR_Addr, n)//output
# define PAin (n) BIT_ADDR (GPIOA_IDR_Addr, n)//input

//-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --

# define GPIOB_ODR_Addr (GPIOB_BASE + 12)//0 x40010c0c
# define GPIOB_IDR_Addr (GPIOB_BASE + 8)//0 x40010c08

# define PBout (n) BIT_ADDR (GPIOB_ODR_Addr, n)//output
# define PBin (n) BIT_ADDR (GPIOB_IDR_Addr, n)//input

# define RS PBout (3)
# define RW PBout (4)
# define EN PBout (5)


Void LCD_Init (void);

Void LCD_Write_cmd u8 (CMD);

Void LCD_Write_dat u8 (dat);

Void GPIO_Write (GPIO_TypeDef * GPIOx, uint16_t PortVal);


# endif _LCD_H_/* */



LCD1602. C file
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --

# include "LCD. H"
# include "stm32f10x. H"
# include "delay. H"

//send the command





Void LCD_Write_cmd u8 (CMD)//write command

{

RS=0;

RW=0;

EN=0;
EN=1;

//GPIO_Write (GPIOA, (GPIO_ReadOutputData (GPIOA) & amp; 0 xff00) | CMD);//this function is generally used once a GPIO multiple ports set

GPIO_Write (GPIOA, 0 x00ff & amp; CMD);//GPIOA eighth mouth used as 8 bits of data
Delay_ms (5);

EN=0;

}





//send data

Void LCD_Write_dat u8 (dat)//write data

{

RS=1;

RW=0;

EN=0;

EN=1;

//GPIO_Write (GPIOA, (GPIO_ReadOutputData (GPIOA) & amp; 0 xff00) | dat);//this function is generally used once a GPIO multiple ports set

GPIO_Write (GPIOA, 0 x00ff & amp; Dat);//GPIOA eighth mouth used as 8 bits of data
Delay_ms (5);

EN=0;

}




Void LCD_Init ()

{

GPIO_InitTypeDef GPIO_Initlcd;
RCC_APB2PeriphClockCmd (RCC_APB2Periph_GPIOA, ENABLE);
RCC_APB2PeriphClockCmd (RCC_APB2Periph_GPIOB, ENABLE);

GPIO_Initlcd. GPIO_Mode=GPIO_Mode_Out_PP;//set the work mode
GPIO_Initlcd. 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;//selected pin
GPIO_Initlcd. GPIO_Speed=GPIO_Speed_50MHz;//select working frequency
GPIO_Init (GPIOA, & amp; GPIO_Initlcd);//control register write

GPIO_Initlcd. GPIO_Mode=GPIO_Mode_Out_PP;//set the work mode
GPIO_Initlcd. GPIO_Pin=GPIO_Pin_3 | GPIO_Pin_4 | GPIO_Pin_5;//rs selected pin rw en
GPIO_Initlcd. GPIO_Speed=GPIO_Speed_50MHz;//select working frequency
GPIO_Init (GPIOB, & amp; GPIO_Initlcd);


Delay_ms (5);
LCD_Write_cmd (0 x01);//clear screen
Delay_ms (5);

LCD_Write_cmd (0 x02);//cursor home
Delay_ms (5);

LCD_Write_cmd x06 (0);//set the input mode
Delay_ms (5);

X0c LCD_Write_cmd (0);//display Settings
Delay_ms (5);

X38 LCD_Write_cmd (0);//function set
Delay_ms (5);

}


-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
. The main c files

# include "stm32f10x. H"
# include "delay. H"
# include "stdio.h"
# include "LCD. H"




Int main (void)
{
Char [] h={" LCD1602 test "};
uint8_t i;
LCD_Init ();//LCD1602 initialization function

While (1)
{
LCD_Write_cmd (0 x80 + 0 x01);//in the first row address
for(i=0; i<12. I++)
{
[I] LCD_Write_dat (h);
Delay_ms (5);
}

}
}

CodePudding user response:

Myself found a afternoon I don't know what is the problem, hope someone help me

CodePudding user response:

1, in the void LCD_Write_cmd (u8 CMD)//write command, there will be GPIO_Write (GPIOA, 0 x00ff & amp; CMD);//the eighth GPIOA used as 8 bits of data to remove mouth, instead GPIO_Write (GPIOA, (cmd& 0 x00ff) | (GPIO_ReadOutputData (GPIOA) & amp; 0 xff00));//high shielding eight
2 in the void LCD_Write_dat (u8 dat)//write data, there will be GPIO_Write (GPIOA, 0 x00ff & amp; Dat);//the eighth GPIOA used as 8 bits of data to remove mouth,
To GPIO_Write (GPIOA, (dat& 0 x00ff) | (GPIO_ReadOutputData (GPIOA) & amp; 0 xff00));
A word said: GPIO low 8 definition is wrong
  • Related