找回密碼
 立即注冊

QQ登錄

只需一步,快速開始

搜索
查看: 4515|回復(fù): 0
收起左側(cè)

msp430單片機(jī)的LCD1602顯示程序

[復(fù)制鏈接]
ID:433160 發(fā)表于 2018-11-26 08:31 | 顯示全部樓層 |閱讀模式
//*************************************************************************
//          初始化IO口子程序
//*************************************************************************
void Port_init()
{

    P4SEL = 0x00;
        P4DIR = 0xFF;                   //數(shù)據(jù)口輸出模式
        P5SEL = 0x00;
        P5DIR|= BIT5 + BIT6 + BIT7;     //控制口設(shè)置為輸出模式
}

//***********************************************************************
//  顯示屏命令寫入函數(shù)
//***********************************************************************
void LCD_write_com(unsigned char com)
{
    RS_CLR;
    RW_CLR;
    EN_SET;
    DataPort = com;                 //命令寫入端口
    delay_ms(5);
    EN_CLR;
}

//***********************************************************************
//  顯示屏數(shù)據(jù)寫入函數(shù)
//***********************************************************************
void LCD_write_data(unsigned char data)
{
    RS_SET;
    RW_CLR;
    EN_SET;
    DataPort = data;                //數(shù)據(jù)寫入端口
    delay_ms(5);
    EN_CLR;
}

//***********************************************************************
//  顯示屏清空顯示
//***********************************************************************
void LCD_clear(void)
{
    LCD_write_com(0x01);            //清屏幕顯示
    delay_ms(5);
}

//***********************************************************************
//  顯示屏字符串寫入函數(shù)
//***********************************************************************
void LCD_write_str(unsigned char x,unsigned char y,unsigned char *s)
{

    if (y == 0)
    {
        LCD_write_com(0x80 + x);        //第一行顯示
    }
    else
    {
        LCD_write_com(0xC0 + x);        //第二行顯示
    }

    while (*s)
    {
        LCD_write_data( *s);
        s ++;
    }
}

//***********************************************************************
//  顯示屏單字符寫入函數(shù)
//***********************************************************************
void LCD_write_char(unsigned char x,unsigned char y,unsigned char data)
{

    if (y == 0)
    {
        LCD_write_com(0x80 + x);        //第一行顯示
    }
    else
    {
        LCD_write_com(0xC0 + x);        //第二行顯示
    }

    LCD_write_data( data);
}

//***********************************************************************
//  顯示屏初始化函數(shù)
//***********************************************************************
void LCD_init(void)
{
    LCD_write_com(0x38);        //顯示模式設(shè)置
    delay_ms(5);
    LCD_write_com(0x08);        //顯示關(guān)閉
    delay_ms(5);
    LCD_write_com(0x01);        //顯示清屏
    delay_ms(5);
    LCD_write_com(0x06);        //顯示光標(biāo)移動設(shè)置
    delay_ms(5);
    LCD_write_com(0x0C);        //顯示開及光標(biāo)設(shè)置
    delay_ms(5);
}

//***********************************************************************
//      液晶顯示界面初始化
//***********************************************************************
void LCD_Desk(void)
{
  LCD_clear();
  LCD_write_str(0,0,"The Key Number:");
  delay_ms(250);
}



評分

參與人數(shù) 1黑幣 +50 收起 理由
admin + 50 共享資料的黑幣獎勵!

查看全部評分

回復(fù)

使用道具 舉報

您需要登錄后才可以回帖 登錄 | 立即注冊

本版積分規(guī)則

小黑屋|51黑電子論壇 |51黑電子論壇6群 QQ 管理員QQ:125739409;技術(shù)交流QQ群281945664

Powered by 單片機(jī)教程網(wǎng)

快速回復(fù) 返回頂部 返回列表