Beispiel #1
0
void LCD_write_data(unsigned char Recdata) //写数据
{
    uint16_t PORT_DATA, tmpCmd = 0;
    Delay_1ms(2);

    //LCD1602_RS=1; //RS=1
    GPIO_SetBits(LCD1602_RS_PORT, LCD1602_RS_PIN);
    Delay_1ms(2);

    PORT_DATA = GPIO_ReadInputData(LCD1602_DB_PORT);
    PORT_DATA &= (~LCD1602_DB_MASK);

    tmpCmd = (uint16_t)(LCD_SWAP_High4Bits(Recdata) & 0xf0) << 2;
    PORT_DATA |= tmpCmd;
    GPIO_Write(LCD1602_DB_PORT, PORT_DATA);		//    写高四位
    //LCD_DATA&=0X0f; //    清高四位
    //LCD_DATA|=Recdata&0xf0; //    写高四位

    LCD_en_write();

    Recdata=Recdata<<4; //    低四位移到高四位

    PORT_DATA = GPIO_ReadInputData(LCD1602_DB_PORT);
    PORT_DATA &= (~LCD1602_DB_MASK);

    tmpCmd = 0;
    tmpCmd = (uint16_t)(LCD_SWAP_High4Bits(Recdata) & 0xf0) << 2;
    PORT_DATA |= tmpCmd;
    GPIO_Write(LCD1602_DB_PORT, PORT_DATA);   //    写低四位
    //LCD_DATA&=0X0f; //    清高四位
    //LCD_DATA|=Recdata&0xf0; //    写低四位

    LCD_en_write();
}
Beispiel #2
0
void LCD_write_command(unsigned char command)    //写指令
{
    uint16_t PORT_DATA, tmpCmd = 0;

    //LCD1602_RS=0; //RS=0
    GPIO_ResetBits(LCD1602_RS_PORT, LCD1602_RS_PIN);
    Delay_1ms(2);

    PORT_DATA = GPIO_ReadInputData(LCD1602_DB_PORT);
    PORT_DATA &= (~LCD1602_DB_MASK);
    //GPIO_Write(LCD1602_DB_PORT, PORT_DATA);

    tmpCmd = ((uint16_t)(LCD_SWAP_High4Bits(command) & 0xf0)) << 2;
    PORT_DATA |= tmpCmd;
    GPIO_Write(LCD1602_DB_PORT, PORT_DATA);		//    写高四位

    LCD_en_write();

    command=command<<4; //    低四位移到高四位

    PORT_DATA = GPIO_ReadInputData(LCD1602_DB_PORT);
    PORT_DATA &= (~LCD1602_DB_MASK);
    //GPIO_Write(LCD1602_DB_PORT, PORT_DATA);

    tmpCmd = 0;
    tmpCmd = ((uint16_t)(LCD_SWAP_High4Bits(command) & 0xf0)) << 2;
    PORT_DATA |= tmpCmd;
    GPIO_Write(LCD1602_DB_PORT, PORT_DATA);   //    写低四位
    //LCD_DATA|=command&0xf0;

    LCD_en_write();
}
void LCD_byte(INT8U abc)
{
	RW = 0;
	LCD_E = 0;
	LCD_DATA = abc;
	LCD_en_write();
}
Beispiel #4
0
void LCD_init(void)      //
{
    LCD_GPIO_Init();
#if 1
    Delay_1ms(20);
    w_4bit_INIT_LCD1602(0x30);     //写第一次0x3N命令(N为任意值)
    Delay_1ms(10);       //至少延迟4.1ms
    w_4bit_INIT_LCD1602(0x30);    //写第二次0x3N命令(N为任意值)
    Delay_1us(200);       //至少延迟100us
    w_4bit_INIT_LCD1602(0x30);    //写第三次0x3N命令(N为任意值)
    Delay_1us(100);       //至少延迟40us
    w_4bit_INIT_LCD1602(0x20);    //设置为4位模式
    Delay_1us(100);        //至少延迟40us
    LCD_write_command(0x28);      //设置为4位模式,2行字符,5 x 7点阵/每字符
    Delay_1us(100);       //至少延迟40us
    LCD_write_command(0x06);     //写入新数据后光标右移,写入新数据后显示屏不移动
    Delay_1us(100);       //至少延迟40us
    LCD_write_command(0x0e);     //显示功能开,有光标,光标不闪烁
    Delay_1us(100);       //至少延迟40us
    LCD_write_command(0x01);     //清除液晶显示器
    Delay_1ms(10);          //至少延迟1.64ms
    GPIO_ResetBits(LCD1602_RW_PORT, LCD1602_RW_PIN);
    Delay_1ms(10);
#else
    LCD_write_command(0x33);
    Delay_1ms(5);

    LCD_write_command(0x28);
    Delay_1ms(5);

    LCD_write_command(0x28);
    Delay_1ms(5);

    LCD_write_command(0x28);
    Delay_1ms(5);

    LCD_en_write();
    Delay_1ms(5);

    LCD_write_command(0x28); //4
    Delay_1ms(5);

    LCD_write_command(0x0c); //    显示开
    Delay_1ms(5);

    LCD_write_command(0x01); //    清屏
    Delay_1ms(5);

    GPIO_ResetBits(LCD1602_RW_PORT, LCD1602_RW_PIN);
#endif
}
Beispiel #5
0
void w_4bit_INIT_LCD1602(unsigned char ucCMD)
{
    uint16_t PORT_DATA, tmpCmd = 0;
    GPIO_ResetBits(LCD1602_RS_PORT, LCD1602_RS_PIN);		//RS_L;  //写入的是命令字
    GPIO_ResetBits(LCD1602_RW_PORT, LCD1602_RW_PIN);    	//RW_W;  //置为写状态

    PORT_DATA = GPIO_ReadInputData(LCD1602_DB_PORT);
    PORT_DATA &= (~LCD1602_DB_MASK);

    tmpCmd = (uint16_t)(LCD_SWAP_High4Bits(ucCMD) & 0xf0) << 2;
    PORT_DATA |= tmpCmd;
    GPIO_Write(LCD1602_DB_PORT, PORT_DATA);			//    写高四位
    //P1 = (P1 & 0x0F) | (ucCMD & 0xF0);  //注意不要改变P2低四位的状态

    LCD_en_write();    //En_Toggle();  //产生使能脉冲,使之在下降沿开始执行指令
}
Beispiel #6
0
//写一个字节到LCD ,COMM(指令)   DAT(显示数据)
void LCD_write_onechar(unsigned char COMM,unsigned char DAT)
{ 
	 wait_LCD_Ready();         //等待LCD空闲
	 LCD_RW_0;                 //写
	 
	 //写数据
	 if(COMM==0)
	 {
	    LCD_RS_1;  //RS高电平向LCD写数据
		LCD_DATA_PORT=DAT;
	 } 
	 //写命令
	 else
	 {
	    LCD_RS_0;
        LCD_DATA_PORT=COMM;
	 }
	 LCD_en_write(); 
	 Delay_nUS(2);
	 LCD_RW_1;
	 LCD_RS_1;
}