Download as pdf or txt
Download as pdf or txt
You are on page 1of 5

10/30/2015

TextLCD16x2viSTM32F4ICViet.vn

Nidung
1.GiithiuTextLCD16x2
2.Ktniphncng
3.LptrnhTextLCDcbn
4.Codetrongbivit

Ccbicnthamkhotrc
ToProjectviIAR&Keil
BI1:GPIOviSTM32F4

Download Samplecode
1.GiithiuTextLCD16x2

TextLCDlloimnhnhtinhthlngdnghinthcckttrongbngmASCII.Text
LCDcnhiukchthckhcnhaunh16x1,16x2,16x4,20x2,20x4,Trongbivithmnay
tisdngloimnhnh16x2.

2.Ktniphncng

Bnvuilngktninhsbndi.

data:text/htmlcharset=utf8,%3Ctable%20border%3D%220%22%20cellspacing%3D%221%22%20cellpadding%3D%221%22%20width%3D%22100%25

1/5

10/30/2015

TextLCD16x2viSTM32F4ICViet.vn

3.LptrnhTextLCDcbn

TrongthmcdnchobihchmnaytikmthvinlcdtrongfolderUtilities.Bn
cnaddthmngdnvcctptincnthitvoprojectcabnnhhnhbndi.

data:text/htmlcharset=utf8,%3Ctable%20border%3D%220%22%20cellspacing%3D%221%22%20cellpadding%3D%221%22%20width%3D%22100%25

2/5

10/30/2015

TextLCD16x2viSTM32F4ICViet.vn

TiliuvdatasheetlptrnhTextLCDcrtnhiutrninternetnntiskhngisu
vobntrongcaLCDmhngdnbnsdngbthvintinhkm,nhvystitkim
cthigianhcvkhngqunngiviccbnmitmhiu.HocmunhiusuvText
LCDbncthxemchitittnghmbntrongthvinlcd.c.
Bcubncnmfilelcd.hvtmndngLCDControlpinsnhnghaliccchn
mbnsdng.
/*LCDControlpins*/
#defineLCD_RS_GPIO_PORT
GPIOB
#defineLCD_RS_GPIO_CLK RCC_AHB1Periph_GPIOB
#defineLCD_RS_GPIO_PIN GPIO_Pin_0
//#defineLCD_RW_GPIO_PORTGPIOC
//#defineLCD_RW_GPIO_CLK
//#defineLCD_RW_GPIO_PIN
#defineLCD_EN_GPIO_PORT
#defineLCD_EN_GPIO_CLK
#defineLCD_EN_GPIO_PIN
//XXXXXXXXXXXXXXXXXXXXXXXXDATAD4..7
#defineLCD_D4_GPIO_PORT
#defineLCD_D4_GPIO_CLK
#defineLCD_D4_GPIO_PIN

RCC_APB2Periph_GPIOC//CONNETPINRWTOGND
GPIO_Pin_10

GPIOB
RCC_AHB1Periph_GPIOB
GPIO_Pin_1
GPIOC
RCC_AHB1Periph_GPIOC
GPIO_Pin_0

#defineLCD_D5_GPIO_PORT
GPIOC
#defineLCD_D5_GPIO_CLK RCC_AHB1Periph_GPIOC
#defineLCD_D5_GPIO_PIN GPIO_Pin_1
#defineLCD_D6_GPIO_PORT
GPIOC
#defineLCD_D6_GPIO_CLK RCC_AHB1Periph_GPIOC
#defineLCD_D6_GPIO_PIN GPIO_Pin_2
#defineLCD_D7_GPIO_PORT
GPIOC
#defineLCD_D7_GPIO_CLK RCC_AHB1Periph_GPIOC
#defineLCD_D7_GPIO_PIN GPIO_Pin_3

data:text/htmlcharset=utf8,%3Ctable%20border%3D%220%22%20cellspacing%3D%221%22%20cellpadding%3D%221%22%20width%3D%22100%25

3/5

10/30/2015

TextLCD16x2viSTM32F4ICViet.vn

Bivitnytisdngch4bittitkimchnIOvkhngcdliutlcdvdoti
thyiunylkhngcnthit,nnchns5RWtinimass.
Trongchngtrnhchnhmain.cbnchcnkhaibohmlcd_Init()lcthsdng
TextLCD.Trongbivittisdnghmprintfcathvinstdio.hnnbntrntikhaibo
thvinny.MilnhmprintfgiktsngaylptcnhynhmPUTCHAR_PROTOTYPE
dng46vthchinlnhgimtktnraLCDbnghmlcd_Data_Write().
Dng20:hmlcd_Clear()sxatrngmnhnh.
Dng21:lnhnystrnhngutinctutininktrahngct.is
thnhtlhng,isth2lct.
19lcd_Init();
20lcd_Clear();
21lcd_Goto(0,0);

Vylktqu:

4.Codetrongbivit

main.c
01#include"stm32f4xx.h"
02#include"lcd.h"
03#include<stdio.h>
04
05voidDelay(__IOuint32_tnCount);
06
07/*Privatefunctionprototypes*/
08#ifdef__GNUC__
09/*WithGCC/RAISONANCE,smallprintf(optionLDLinker>Libraries>Smallprintf
10setto'Yes')calls__io_putchar()*/
11#definePUTCHAR_PROTOTYPEint__io_putchar(intch)
12#else
13#definePUTCHAR_PROTOTYPEintfputc(intch,FILE*f)
14#endif/*__GNUC__*/
15
16intmain(void)
17{
18inti;
19lcd_Init();

20lcd_Clear();
21lcd_Goto(0,0);
22printf("Welcometo:");
23lcd_Goto(1,0);
24printf("...ICViet.vn");
25Delay(50000000);
26while(1)
27{
28for(i=0;i<1000;i++)
29{

data:text/htmlcharset=utf8,%3Ctable%20border%3D%220%22%20cellspacing%3D%221%22%20cellpadding%3D%221%22%20width%3D%22100%25

4/5

10/30/2015

TextLCD16x2viSTM32F4ICViet.vn

29{
30lcd_Goto(0,0);
31printf("Counting:");
32lcd_Goto(1,0);
33printf("%d",i);
34Delay(1000000);
35}
36}
37}
38
39voidDelay(__IOuint32_tnCount)
40{
41while(nCount)
42{
43}
44}
45
46PUTCHAR_PROTOTYPE
47{
48lcd_Data_Write((u8)ch);
49returnch;
50}
51
52#ifdefUSE_FULL_ASSERT
53voidassert_failed(uint8_t*file,uint32_tline)
54{
55/*Usercanaddhisownimplementationtoreportthefilenameandlinenumber,
56ex:printf("Wrongparametersvalue:file%sonline%d\r\n",file,line)*/
57
58/*Infiniteloop*/
59while(1)
60{
61}
62}
63#endif
64
65

data:text/htmlcharset=utf8,%3Ctable%20border%3D%220%22%20cellspacing%3D%221%22%20cellpadding%3D%221%22%20width%3D%22100%25

5/5

You might also like