#include
#define uint unsigned int
#define uchar unsigned char
#define SDA_1 P2OUT |= BIT2
#define SDA_0 P2OUT &=~BIT2
#define SCLK_1 P2OUT |= BIT1
#define SCLK_0 P2OUT &= ~BIT1
/*#define CS_1 P2OUT |= BIT2 CS直接接电源
#define //CS_0 P2OUT &= ~BIT2*/
uchar a[]="11";
/***********************************************************
*名 称:LCD_Write_cmd()
*功 能:写一个命令/数据到LCD12864
*入口参数:cmd:待写入的命令,无符号字节形式
*出口参数:tepy:0指令,1数据
*说 明:
*格 式:11111 RW0 RS 0 D7D6D5D40000 xxxx0000
* |最高的字节 |命令的bit7~4|命令的bit3~0|
***********************************************************/
void write_cmddat(uchar tepy,uchar cmd)
{
uchar i;
uchar i_data;
if(tepy==1)
i_data=0xfa;
else
i_data=0xf8;
for(i=0;i<8;i++)
{
if(i_data&0x80) SDA_1;
else SDA_0;
SCLK_1;
SCLK_0;
i_data<<=1;
}
i_data=cmd;
i_data&=0xf0;
for(i=0;i<8;i++)
{
if(i_data&0x80) SDA_1;
else SDA_0;
SCLK_1;
SCLK_0;
i_data<<=1;
}
i_data=cmd<<4;
for(i=0;i<8;i++)
{
if(i_data&0x80) SDA_1;
else SDA_0;
SCLK_1;
SCLK_0;
i_data<<=1;
}
}
void lcd_pos(uchar x,uchar y)
{
uchar pos;
switch(x)
{
case 1:pos=0x80;break;
case 2:pos=0x90;break;
case 3:pos=0x88;break;
case 4:pos=0x98;break;
}
pos=y+pos;
write_cmddat(0,pos);
}
/****************************************************/
//LCD12864初始化
void LCD_init(void)
{
__delay_cycles(1000);
write_cmddat(0,0x30);
__delay_cycles(1000);
write_cmddat(0,0x01);
__delay_cycles(1000);
write_cmddat(0,0x06);
write_cmddat(0,0x0f);
}
int main( void )
{
uint i;
// Stop watchdog timer to prevent time out reset
WDTCTL = WDTPW + WDTHOLD;
P2DIR = BIT1 + BIT2 ;
LCD_init();
lcd_pos(1,0);
for(i=0;i<6;i++)
{
write_cmddat(1,a);
}
} |