📄 液晶调好的程序.c
字号:
#include<msp430x16x.h>
#define uint unsigned int
#define uchar unsigned char
uchar chushi[7]={0x08,0x10,0x17,0x05,0x22,0x55,0x23};
uchar xianshi[7];
void cs_high()
{
P4OUT |=0x01;
}
void cs_low()
{
P4OUT &=0xfe;
}
void std_high()
{
P4OUT |=0x02;
}
void std_low()
{
P4OUT &=0xfd;
}
void sclk_high()
{
P4OUT |=0x04;
}
void sclk_low()
{
P4OUT &=0xfb;
}
void delay (uint s) //延迟
{ while(s--);
}
void lcdio_ini()
{
P4DIR |=0x07;
P4SEL &=0xF8;
}
void sendcom(uchar com)
{
uchar com1,com2,i;
com1=com&0xf0;
com2=com<<4;
cs_high();
sclk_low();
for(i=0;i<5;i++)
{
std_high();
sclk_high();
sclk_low();
std_low();
delay (2);
}
std_low();
sclk_high();
sclk_low();
delay (2);
sclk_high();
sclk_low();
delay(2);
sclk_high();
sclk_low();
for(i=0;i<8;i++)
{
if(com1&0x80)
{
std_high();
sclk_high();
sclk_low();
}
else
{
std_low();
sclk_high();
sclk_low();
}
com1=com1<<1;
}
for(i=0;i<8;i++)
{
if(com2&0x80)
{
std_high();
sclk_high();
sclk_low();
}
else
{
std_low();
sclk_high();
sclk_low();
}
com2=com2<<1;
}
}
void senddata(uchar dat)
{
uchar dat1,dat2,i;
dat1=dat&0xf0;
dat2=dat<<4;
cs_high();
sclk_low();
std_high();
for(i=0;i<5;i++)
{
sclk_high();
sclk_low();
delay (2);
}
std_low();
sclk_high();
sclk_low();
std_high();
sclk_high();
sclk_low();
delay(2);
sclk_high();
sclk_low();
for(i=0;i<8;i++)
{
if(dat1&0x80)
{
std_high();
sclk_high();
sclk_low();
}
else
{
std_low();
sclk_high();
sclk_low();
}
dat1=dat1<<1;
}
for(i=0;i<8;i++)
{
if(dat2&0x80)
{
std_high();
sclk_high();
sclk_low();
}
else
{
std_low();
sclk_high();
sclk_low();
}
dat2=dat2<<1;
delay(100);
}
}
void init_lcd()
{
sendcom(0x30); /*30---基本指令动作*/
sendcom(0x01); /*清屏,地址指针指向00H*/
delay (50);
sendcom(0x06); /*光标的移动方向*/
sendcom(0x0c); /*开显示,关游标*/
}
void rijizifu()
{
sendcom(0x30);
sendcom(0x80);
senddata(0x32);
senddata(0x30);
sendcom(0x82);
senddata(0xc4);
senddata(0x6a);
sendcom(0x84);
senddata(0xd4);
senddata(0xc2);
sendcom(0x86);
senddata(0xc8);
senddata(0xd5);
sendcom(0x92);
senddata(0xd0);
senddata(0xc7);
senddata(0xc6);
senddata(0xda);
sendcom(0x8a);
senddata(0xca);
senddata(0xb1);
sendcom(0x8c);
senddata(0xb7);
senddata(0xd6);
sendcom(0x8e);
senddata(0xc3);
senddata(0x6b);
sendcom(0x99);
senddata(0xca);
senddata(0xaa);
sendcom(0x9a);
senddata(0xb6);
senddata(0xc8);
}
/*void riqishuju(uchar const *shijian)
{
uchar temp,temp1,temp2,temp3,temp4;
sendcom(0x30);
temp1=shijian[0]>>7;
temp2=(shijian[0]&0x40)>>6;
temp3=(shijian[0]&0x20)>>5;
temp4=(shijian[0]&0x10)>>4;
temp=temp1*8+temp2*4+temp3*2+temp4;
temp=3*16+temp;
sendcom(0x81);
senddata(temp);
temp1=(shijian[0]&0x08)>>3;
temp2=(shijian[0]&0x04)>>2;
temp3=(shijian[0]&0x02)>>1;
temp4=shijian[0]&0x01;
temp=temp1*8+temp2*4+temp3*2+temp4;
temp=3*16+temp;
senddata(temp);
temp4=(shijian[1]&0x10)>>4;
temp=temp4;
temp=3*16+temp;
sendcom(0x83);
senddata(temp);
temp1=(shijian[1]&0x08)>>3;
temp2=(shijian[1]&0x04)>>2;
temp3=(shijian[1]&0x02)>>1;
temp4=shijian[1]&0x01;
temp=temp1*8+temp2*4+temp3*2+temp4;
temp=3*16+temp;
senddata(temp);
temp3=(shijian[2]&0x20)>>5;
temp4=(shijian[2]&0x10)>>4;
temp=temp3*2+temp4;
temp=3*16+temp;
sendcom(0x85);
senddata(temp);
temp1=(shijian[2]&0x08)>>3;
temp2=(shijian[2]&0x04)>>2;
temp3=(shijian[2]&0x02)>>1;
temp4=shijian[2]&0x01;
temp=temp1*8+temp2*4+temp3*2+temp4;
temp=3*16+temp;
senddata(temp);
temp2=(shijian[3]&0x04)>>2;
temp3=(shijian[3]&0x02)>>1;
temp4=shijian[3]&0x01;
temp=temp2*4+temp3*2+temp4;
temp=3*16+temp;
sendcom(0x94);
senddata(temp);
temp3=(shijian[4]&0x20)>>5;
temp4=(shijian[4]&0x10)>>4;
temp=temp3*2+temp4;
temp=3*16+temp;
sendcom(0x89);
senddata(temp);
temp1=(shijian[4]&0x08)>>3;
temp2=(shijian[4]&0x04)>>2;
temp3=(shijian[4]&0x02)>>1;
temp4=shijian[4]&0x01;
temp=temp1*8+temp2*4+temp3*2+temp4;
temp=3*16+temp;
senddata(temp);
temp2=(shijian[5]&0x40)>>6;
temp3=(shijian[5]&0x20)>>5;
temp4=(shijian[5]&0x10)>>4;
temp=temp2*4+temp3*2+temp4;
temp=3*16+temp;
sendcom(0x8b);
senddata(temp);
temp1=(shijian[5]&0x08)>>3;
temp2=(shijian[5]&0x04)>>2;
temp3=(shijian[5]&0x02)>>1;
temp4=shijian[5]&0x01;
temp=temp1*8+temp2*4+temp3*2+temp4;
temp=3*16+temp;
senddata(temp);
temp2=(shijian[6]&0x40)>>6;
temp3=(shijian[6]&0x20)>>5;
temp4=(shijian[6]&0x10)>>4;
temp=temp2*4+temp3*2+temp4;
temp=3*16+temp;
sendcom(0x8d);
senddata(temp);
temp1=(shijian[6]&0x08)>>3;
temp2=(shijian[6]&0x04)>>2;
temp3=(shijian[6]&0x02)>>1;
temp4=shijian[6]&0x01;
temp=temp1*8+temp2*4+temp3*2+temp4;
temp=3*16+temp;
senddata(temp);
}
*/
main()
{
WDTCTL=WDTPW+WDTHOLD;
lcdio_ini();
init_lcd();
rijizifu();
while(1);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -