LCD1602_8 data
程序要寫出自己的風(fēng)格
******************************************************
**這是學(xué)習(xí) msp430g2553 單片機(jī)時(shí)寫的 1602 的程序**
**時(shí)間精確到us,基本不出亂碼**
**P1為數(shù)據(jù)輸出端口**
**rs 接 p2.1**
**rw 接地**
**en 接 p2.0**
******************************************************
#include
#include
#define rs_0 P2OUT&=~BIT1
#define rs_1 P2OUT|=BIT1
#define en_0 P2OUT&=~BIT0
#define en_1 P2OUT|=BIT0
char table_1[]={"SHOU BU NIAO L !"};
char table_2[]={"2012.8.02"};
unsigned int num;
unsigned int con_1,con_2;
void LCD1602_write_command(unsigned int com)
{
rs_0;
P1OUT=com;
__delay_cycles(500);
en_1;
__delay_cycles(500);
en_0;
}
void LCD1602_write_data(unsigned int dat)
{
rs_1;
P1OUT=dat;
__delay_cycles(500);
en_1;
__delay_cycles(500);
en_0;
}
void LCD1602_init()
{
LCD1602_write_command(0x38);//5*7點(diǎn)陣,雙行顯示
LCD1602_write_command(0x0c);//0x0f 有光標(biāo),
LCD1602_write_command(0x01);//清屏
LCD1602_write_command(0x06);//寫入數(shù)據(jù)后,光標(biāo)右移,顯示屏不動(dòng)
LCD1602_write_command(0x80);
}
void main ()
{
con_1=strlen(table_1);
con_2=strlen(table_2);
WDTCTL=WDTPW+WDTHOLD;
P1DIR =0XFF;
P2DIR=0XFF;
LCD1602_init();
for(num=0;num
LCD1602_write_data(table_1[num]);
__delay_cycles(1000);
}
LCD1602_write_command(0x80+0x40);
for(num=0;num
LCD1602_write_data(table_2[num]);
__delay_cycles(1000);
}
while(1);
}