这个程序的LCD1602引脚D0-D7是接到PB8-PB15吗? RS PB5, RW PB4 , E PB3这样接对吗
我这样接的为什么不显示
- #include "public.h"
- #define DATA (GPIO_Pin_8|GPIO_Pin_9|GPIO_Pin_10|GPIO_Pin_11|GPIO_Pin_12|GPIO_Pin_13|GPIO_Pin_14|GPIO_Pin_15)
- #define rs (GPIO_Pin_5)
- #define rw (GPIO_Pin_4)
- #define e (GPIO_Pin_3)
- u8 num[]="0123456789";
- u8 a[]=" welcome to PZ ";
- u8 b[]=" Beautiful Girl ";
- void GPIOINIT() //¶Ë¿Ú³õʼ»¯
- {
- GPIO_InitTypeDef GPIO_InitStructure;
- GPIO_InitStructure.GPIO_Pin=DATA|rs|rw|e;
- GPIO_InitStructure.GPIO_Mode=GPIO_Mode_Out_PP;
- GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz;
- GPIO_Init(GPIOB,&GPIO_InitStructure);
- // GPIO_PinRemapConfig(GPIO_Remap_SWJ_Disable,ENABLE);//°Ñµ÷ÊÔÉèÖÃÆÕͨIO¿Ú
- }
- void RCCINIT() //ϵͳ³õʼ»¯
- {
- SystemInit();
- RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB,ENABLE);
- //RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO,ENABLE);
- //Èç¹û²»¼ÓÕâÌõÓï¾ä³ÌÐòÏÔʾ¾Í»á³ö´í£¬¼´Ã»Óдò¿ª¶Ë¿Ú¸´Óù¦ÄܵÄʱÖÓÅäÖÃ
- }
- u8 readbusy() //æÐźżì²â
- {
- u8 f;
- GPIO_ResetBits(GPIOB,rs);
- GPIO_SetBits(GPIOB,rw);
- GPIO_SetBits(GPIOB,e);
- f=((GPIO_ReadInputData(GPIOB)&0X8000));
- delayms(10);
- GPIO_ResetBits(GPIOB,e);
- return f;
- }
- void lcdwrc(u8 c) //д°ËλÊý¾Ý
- {
- while(readbusy());
- GPIO_ResetBits(GPIOB,rs);
- GPIO_ResetBits(GPIOB,rw);
- GPIO_ResetBits(GPIOB,e);
- delayms(1);
- GPIOB->BSRR = c<<8 & 0xf000; //½«Êý¾ÝË͵½P0¿Ú
- GPIOB->BRR = ((~c)<<8) & 0xf000;
- delayms(1);
- GPIO_SetBits(GPIOB,e);
- delayms(1);
- GPIO_ResetBits(GPIOB,e);
- delayms(1);
- }
- void lcdwrc4bit(long c) //д8λÊý¾Ý,ͨ¹ý4¸öÒý½Å
- {
- while(readbusy());
- GPIO_ResetBits(GPIOB,rs);
- GPIO_ResetBits(GPIOB,rw);
- GPIO_ResetBits(GPIOB,e);
- delayms(1);
- GPIOB->BSRR = c<<8 & 0xf000; //½«Êý¾ÝË͵½P0¿Ú
- GPIOB->BRR = ((~c)<<8) & 0xf000;
- delayms(1);
- GPIO_SetBits(GPIOB,e);
- delayms(1);
- GPIO_ResetBits(GPIOB,e);
- delayms(1);
- GPIOB->BSRR = c<<12 & 0xf000; //½«Êý¾ÝË͵½P0¿Ú
- GPIOB->BRR = ((~c)<<12) & 0xf000;
- delayms(1);
- GPIO_SetBits(GPIOB,e);
- delayms(1);
- GPIO_ResetBits(GPIOB,e);
- delayms(1);
- }
- void lcdwrd(long dat) //¶Á°ËλÊý¾Ýͨ¹ý4¸öÒý½Å
- {
- while(readbusy());
- GPIO_SetBits(GPIOB,rs);
- GPIO_ResetBits(GPIOB,rw);
- GPIO_ResetBits(GPIOB,e);
- delayms(1);
- GPIOB->BSRR = dat<<8 & 0xf000; //½«Êý¾ÝË͵½P0¿Ú
- GPIOB->BRR = ((~dat)<<8) & 0xf000;
- delayms(1);
- GPIO_SetBits(GPIOB,e);
- delayms(1);
- GPIO_ResetBits(GPIOB,e);
- delayms(1);
- GPIOB->BSRR = dat<<12 & 0xf000; //½«Êý¾ÝË͵½P0¿Ú
- GPIOB->BRR = ((~dat)<<12) & 0xf000;
- delayms(1);
- GPIO_SetBits(GPIOB,e);
- delayms(1);
- GPIO_ResetBits(GPIOB,e);
- delayms(1);
- GPIO_ResetBits(GPIOB,rs);
- }
- void lcdinit() //LCD³õʼ»¯
- {
- delayms(15);
- lcdwrc4bit(0x32);
- delayms(5);
- lcdwrc4bit(0x28);
- delayms(5);
- lcdwrc4bit(0x08);
- delayms(5);
- lcdwrc4bit(0x01);
- delayms(5);
- lcdwrc4bit(0x06);
- delayms(5);
- lcdwrc4bit(0x0c);
- delayms(5);
- }
- void display() //ÏÔʾ
- {
- u8 i;
- lcdwrc4bit(0x00+0x80);
- for(i=0;i<16;i++)
- {
- lcdwrd(a[i]);
- }
- lcdwrc4bit(0x40+0x80);
- for(i=0;i<16;i++)
- {
- lcdwrd(b[i]);
- }
- }
- int main()
- {
-
- RCCINIT(); // ϵͳʱÖÓ³õʼ»¯
- GPIOINIT(); // ¶Ë¿Ú³õʼ»¯
- lcdinit(); // Òº¾§ÏÔʾ³õʼ»¯
- while(1)
- {
- display();
- }
- }
复制代码 |