LCD1602 使用4條資料線

1602原使用 8 條資料線,經小幅修改即可用4條資料線完成顯示。

原:D0~D7

改:D4~D7

再說的簡單一點...把改碼後的區塊覆蓋原來區塊就可以了!

原碼(擷取自業餘衛星通信用控制器源碼 )

//1.資料傳輸之定義

改碼

//1.資料傳輸之定義

//************************

//LCD 初始化

//************************

InitLCD(void)

{

wcode(0x01); //清屏

wcode(0x06); //輸入方式控制,增量光標不移位

wcode(0x0e); //顯示開關控制

wcode(0x38); //功能設定:16x2,5x7,8位數據口

}

//************************

//LCD 初始化

//************************

InitLCD(void)

{

wcode(0x01); //清屏

wcode(0x06); //輸入方式控制,增量光標不移位

wcode(0x0e); //顯示開關控制

wcode(0x28); //功能設定:16x2,5x7,4位數據口 }

//說明: 4位數據接口 是0x28,8位數據接口是0x38

//*********************************

//2.指令與數據傳送

//*********************************

//2.指令與數據傳送

//***********************

//向LCD寫一命令

//************************

wcode(uchar t)

{

rs=0; // 寫的是命令

rw=0; // 寫狀態

e=1; //使能

Dataport=t; //寫入命令

delay(45); //等待寫入

e=0; //數據的鎖定

}

//************************

//向LCD寫一數據

//************************

wdata(uchar t)

{

rs=1; // 寫的是數據

rw=0; // 寫狀態

e=1; //使能

Dataport=t; //寫入數據

delay(45); //等待寫入

e=0; //數據的鎖定

}

//************************

//向LCD寫一命令

//************************

wcode(uchar t)

{

uchar ae,ae0,ae1,ae2,ae3;

rs=0; // 寫的是命令

rw=0; // 寫狀態

ae1=t;

ae0=Dataport;

ae0=ae0&0b00001111;

ae1=ae1&0b11110000;

ae=ae1|ae0;

e=1; //使能

Dataport=ae;

delay_20us(1);

e=0; //數據的鎖定

t=t<<4;

ae3=t;

ae3=ae3&0b11110000;

ae=ae3|ae0;

e=1; //使能

Dataport=ae;

delay_20us(1);

e=0; //數據的鎖定

//delay(55); //等待寫入

}

//************************

//向LCD寫一數據

//************************

wdata(uchar t)

{

uchar ae,ae0,ae1,ae2,ae3;

rs=1; // 寫的是數據

rw=0; // 寫狀態

ae1=t;

ae0=Dataport;

ae0=ae0&0b00001111;

ae1=ae1&0b11110000;

ae=ae1|ae0;

e=1; //使能

Dataport=ae;

delay_20us(1);

e=0; //數據的鎖定

t=t<<4;

ae3=t;

ae3=ae3&0b11110000;

ae=ae3|ae0;

e=1; //使能

Dataport=ae;

delay_20us(1);

e=0; //數據的鎖定

}