最近在弄launch pad 串行接12864液晶屏, 但就是出不来,跪求大神们前来指导。
//P2.6为SID 接R/W, P2.7为SCLK, 接E, cs端接vcc, psb接gnd.
#include <msp430g2433.h>
unsigned char array1[]={"hello world"};
void delay(unsigned char n)
{
unsigned char i;
while(n>0)
{
for(i=0;i<200;i++);
n--;
}
}
void lcd_com(unsigned char cmd_data, unsigned char str)
{
unsigned int i,j,temp;
//temp=str;
delay(1);
P2OUT &= ~0x40; //sid=0 P2.6
delay(1);
P2OUT &= ~0x80; //p2.7 sclk=0
P2OUT |= 0x40; //p2.6 sid=1
for(i=0;i<5;i++)
{
P2OUT |= 0x80; //p2.7 sclk=1
delay(1);
P2OUT &= ~0x80; //p2.7 sclk=0
}
delay(1);
P2OUT &= ~0x40; //p2.6 sid=0
P2OUT |= 0x80; //p2.7 sclk=1
delay(1);
P2OUT &= ~0x80; //p2.7 sclk=0
// sid=1111,10 RS 0
if(cmd_data)
{
P2OUT |= 0x40; //sid=1
}
else{P2OUT &= ~0x40;}//sid=0
P2OUT |= 0x80;
delay(1);
P2OUT &= ~0x80;
P2OUT &= ~0x40;
P2OUT |= 0x80;
delay(1);
P2OUT &= ~0x80;
for(j=0;j<2;j++)
{
for(i=0;i<4;i++)
{
temp=str;
temp<<=i;
if((temp&0x80)==0)
{
P2OUT &= ~0x40;
delay(1);
P2OUT |= 0x80;
delay(1);
delay(1);
P2OUT &= ~0x80;
delay(1);
P2OUT &= ~0x40;
}
else
{
P2OUT |= 0x40;
delay(1);
P2OUT |= 0x80;
delay(1);
delay(1);
P2OUT &= ~0x80;
delay(1);
P2OUT &= ~0x40;
}
}
P2OUT &= ~0x40;
for(i=0;i<4;i++)
{
P2OUT |= 0x80;
delay(1);
P2OUT &= ~0x80;
}
}
}
void init()
{
delay(15);
lcd_com(0,0x30);
delay(10);
lcd_com(0,0x30);
delay(1);
lcd_com(0,0x0c);
delay(1);
lcd_com(0,0x01);
delay(1);
lcd_com(0,0x06);
delay(1);
lcd_com(0,0x80);
delay(1);
}
void main()
{
unsigned char p;
init();
P2DIR |= 0xc0;
while(1){
lcd_com(0,0x80);
delay(10);
for(p=0;array1[p]!='\0';p++)
{
lcd_com(1,array1[p]);
}
}
}