并口LCD2402 显示

2019-03-24 14:59发布

void LCD_GpioInit(void)
{
 SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD);      // RS  RW  EN  D0
 GPIODirModeSet(GPIO_PORTD_BASE , GPIO_PIN_7|GPIO_PIN_6|GPIO_PIN_5|GPIO_PIN_4,GPIO_DIR_MODE_OUT);
 GPIOPadConfigSet(GPIO_PORTD_BASE, GPIO_PIN_7|GPIO_PIN_6|GPIO_PIN_5|GPIO_PIN_4, GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_STD);
  
 SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE);      // D1 D2
 GPIODirModeSet(GPIO_PORTE_BASE , GPIO_PIN_3|GPIO_PIN_2,GPIO_DIR_MODE_OUT);
 GPIOPadConfigSet(GPIO_PORTE_BASE, GPIO_PIN_3|GPIO_PIN_2, GPIO_STRENGTH_8MA, GPIO_PIN_TYPE_STD);
 
 SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);      // D5  D4  D3
 GPIODirModeSet(GPIO_PORTB_BASE , GPIO_PIN_6|GPIO_PIN_5|GPIO_PIN_4,GPIO_DIR_MODE_OUT);
 GPIOPadConfigSet(GPIO_PORTB_BASE, GPIO_PIN_6|GPIO_PIN_5|GPIO_PIN_4, GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_STD);  SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOJ);      // D7
 GPIODirModeSet(GPIO_PORTJ_BASE , GPIO_PIN_1,GPIO_DIR_MODE_OUT);
 GPIOPadConfigSet(GPIO_PORTJ_BASE, GPIO_PIN_1, GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_STD);  
 SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOH);      // D6 BLA
 GPIODirModeSet(GPIO_PORTH_BASE , GPIO_PIN_6|GPIO_PIN_0,GPIO_DIR_MODE_OUT);
 GPIOPadConfigSet(GPIO_PORTH_BASE, GPIO_PIN_6|GPIO_PIN_0, GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_STD); // GPIOPinWrite(GPIO_PORTJ_BASE,GPIO_PIN_1,GPIO_PIN_1);                 //D7
// GPIOPinWrite(GPIO_PORTH_BASE,GPIO_PIN_6,GPIO_PIN_6);                //D6   
// GPIOPinWrite(GPIO_PORTB_BASE,GPIO_PIN_6,GPIO_PIN_6);                 //D5
// GPIOPinWrite(GPIO_PORTB_BASE,GPIO_PIN_5,GPIO_PIN_5);                 //D4
// GPIOPinWrite(GPIO_PORTB_BASE,GPIO_PIN_4,GPIO_PIN_4);                 //D3
// GPIOPinWrite(GPIO_PORTE_BASE,GPIO_PIN_2,GPIO_PIN_2);                 //D2
// GPIOPinWrite(GPIO_PORTE_BASE,GPIO_PIN_3,GPIO_PIN_3);                 //D1
// GPIOPinWrite(GPIO_PORTD_BASE,GPIO_PIN_4,GPIO_PIN_4);                 //D0
//GPIOPinWrite(GPIO_PORTD_BASE,GPIO_PIN_7,0);                                    //RS
// GPIOPinWrite(GPIO_PORTD_BASE,GPIO_PIN_6,GPIO_PIN_6);                 //RW   
// GPIOPinWrite(GPIO_PORTD_BASE,GPIO_PIN_5,GPIO_PIN_5);                 //EN
}
void delay(unsigned int delay_Time)
{   
    for( ;delay_Time!=0;delay_Time--)
  ; 
}
void DelayMS(unsigned int time)
{
 unsigned int i=0;
 for(i=0;i<time;i++)
 {
//  GPIOPinWrite(WDT_PORT, WDT_PIN, ~WDT_PIN); //看门狗
  delay(5000);
//  GPIOPinWrite(WDT_PORT, WDT_PIN, WDT_PIN);  //看门狗  
 }
} void  write(char date)
{
 if(date&0x80)             //D7
     GPIOPinWrite(GPIO_PORTJ_BASE,GPIO_PIN_1,GPIO_PIN_1);
   else
   GPIOPinWrite(GPIO_PORTJ_BASE,GPIO_PIN_1,0);
 if(date&0x40)                //D6
     GPIOPinWrite(GPIO_PORTH_BASE,GPIO_PIN_6,GPIO_PIN_6);
  else
   GPIOPinWrite(GPIO_PORTH_BASE,GPIO_PIN_6,0);
 if(date&0x20)                //D5
     GPIOPinWrite(GPIO_PORTB_BASE,GPIO_PIN_6,GPIO_PIN_6);
  else
   GPIOPinWrite(GPIO_PORTB_BASE,GPIO_PIN_6,0);
 if(date&0x10)             //D4
     GPIOPinWrite(GPIO_PORTB_BASE,GPIO_PIN_5,GPIO_PIN_5);
  else
   GPIOPinWrite(GPIO_PORTB_BASE,GPIO_PIN_5,0);
 if(date&0x08)             //D3
     GPIOPinWrite(GPIO_PORTB_BASE,GPIO_PIN_4,GPIO_PIN_4);
  else
   GPIOPinWrite(GPIO_PORTB_BASE,GPIO_PIN_4,0);
 if(date&0x04)             //D2
     GPIOPinWrite(GPIO_PORTE_BASE,GPIO_PIN_2,GPIO_PIN_2);
  else
   GPIOPinWrite(GPIO_PORTE_BASE,GPIO_PIN_2,0);
 if(date&0x02)             //D1
     GPIOPinWrite(GPIO_PORTE_BASE,GPIO_PIN_3,GPIO_PIN_3);
  else
   GPIOPinWrite(GPIO_PORTE_BASE,GPIO_PIN_3,0);
 if(date&0x01)             //D0
     GPIOPinWrite(GPIO_PORTD_BASE,GPIO_PIN_4,GPIO_PIN_4);
  else
   GPIOPinWrite(GPIO_PORTD_BASE,GPIO_PIN_4,0);   
}  //int LCD_check_busy(void)                          //定义LCD_check_busy()返回值是字节
//{
//     int result;
//     GPIOPinWrite(GPIO_PORTD_BASE,GPIO_PIN_7,0);                //RS=0
//     GPIOPinWrite(GPIO_PORTD_BASE,GPIO_PIN_6,GPIO_PIN_6);    //RW=1
//     GPIOPinWrite(GPIO_PORTD_BASE,GPIO_PIN_5,GPIO_PIN_5);    //EN=1
//     GPIOPinTypeGPIOInput(GPIO_PORTJ_BASE , GPIO_PIN_1);           //设置数据口为输入       
//   result = GPIOPinRead(GPIO_PORTJ_BASE,GPIO_PIN_1);         //读取第八位       
//     GPIOPinTypeGPIOOutput(GPIO_PORTJ_BASE , GPIO_PIN_1);             //重新设置数据口为输出
//     GPIOPinWrite(GPIO_PORTD_BASE,GPIO_PIN_5,0);               //EN=0   
//     return result;                                             //返回检测信号
//}
int LCD_check_busy(void)                          //定义LCD_check_busy()返回值是字节
{
     write(0x80);
     GPIOPinWrite(GPIO_PORTD_BASE,GPIO_PIN_7,0);                        //RS=0
     GPIOPinWrite(GPIO_PORTD_BASE,GPIO_PIN_6,GPIO_PIN_6);            //RW=1
     GPIOPinWrite(GPIO_PORTD_BASE,GPIO_PIN_5,GPIO_PIN_5);            //EN=1
     GPIOPinTypeGPIOInput(GPIO_PORTJ_BASE , GPIO_PIN_1);           //设置数据口为输入       
   while(GPIOPinRead(GPIO_PORTJ_BASE,GPIO_PIN_1));                 //读取第八位       
     GPIOPinTypeGPIOOutput(GPIO_PORTJ_BASE , GPIO_PIN_1);               //重新设置数据口为输出
     GPIOPinWrite(GPIO_PORTD_BASE,GPIO_PIN_5,0);                 //EN=0    }
void LCD_write(unsigned  char cd,unsigned  char temp)    // 写入指令数据到LCD
{     
 LCD_check_busy();
 write(temp);             //送数据到LCD
    if(cd)                //当写数据时使RS=1,当为写指令时RS=0
     GPIOPinWrite(GPIO_PORTD_BASE,GPIO_PIN_7,GPIO_PIN_7);
    else
        GPIOPinWrite(GPIO_PORTD_BASE,GPIO_PIN_7,0);        
    GPIOPinWrite(GPIO_PORTD_BASE,GPIO_PIN_6,0);
    GPIOPinWrite(GPIO_PORTD_BASE,GPIO_PIN_5,GPIO_PIN_5);                   
 GPIOPinWrite(GPIO_PORTD_BASE,GPIO_PIN_5,0);
    DelayMS(200);                                          //此延时必须要,不然不能显示   
}
/*=============LCD显示======================*/
void LCD_print(unsigned char a,unsigned char *str)   //字符串
{
 LCD_write(0,a | 0x80);
   while(*str != '')
   {
     LCD_write(1,*str++);      
   }
   *str = 0;
}
void LCD_print2(unsigned char a,unsigned char t)     //字符
{
    LCD_write(0,a | 0x80);
    LCD_write(1,t);
}
/*=============设定显示位置======================*/
void LCD_pos(unsigned  char x,unsigned  char y)

 if(x<16)
 {
  if(y==0)
     x=0x80+x;
  else
     x=0xc0+x;
  LCD_write(0,x);  
 }
}
//LCD初始化设定
void init_lcd(void)
{   
 LCD_write(0, 0x38);
 DelayMS(10);
 LCD_write(0, 0x38);
 DelayMS(10);
 LCD_write(0, 0x38);
 DelayMS(10);
 LCD_write(0, 0x01);
 DelayMS(10);
 LCD_write(0, 0x06);
 DelayMS(10);
 LCD_write(0, 0x0f);  
} 用表测试管脚可以安指定的数据输出,但是接LCD2402就不行了,大家指点一下 此帖出自小平头技术问答
0条回答

一周热门 更多>

相关问题

    相关文章