麻烦大家看一下,就是不显示东西,我调了两天了,好伤心。谢谢多多交流~
#include <msp430g2553.h>
#define uint unsigned int
#define uchar unsigned char
#define CS_H P2OUT|=BIT2
#define CS_L P2OUT&=~BIT2
#define SID_H P2OUT|=BIT1
#define SID_L P2OUT&=~BIT1
#define SCLK_H P2OUT|=BIT0
#define SCLK_L P2OUT&=~BIT0
void delay(uchar z)
{
uint x,y;
for(x = 110;x>0;x--)
for(y = z;y>0;y--);
}
void PORT_init()
{
WDTCTL = WDTPW + WDTHOLD;
P1DIR = 0XFF;
P1OUT = 0XFF;
}
void Sys_init()
{
WDTCTL = WDTPW + WDTHOLD;
BCSCTL1 = CALBC1_8MHZ;
DCOCTL = CALDCO_8MHZ;//设置内部时钟8M
}
void send_byte(uchar bbyte)
{
uchar i;
for(i=0;i<8;i++)
{
P2DIR = 0xff;
if((bbyte<<i) & 0x80)
{
SID_H;
}
else
{
SID_L;
}
SCLK_L;
SCLK_H;
}
}
void LCD12864_write_cmd(uchar ddata)
{
uchar hdata,ldata;
hdata = ddata & 0xf0;
ldata = (ddata<<4) & 0xf0;
// CS_H;
send_byte(0xf8);
delay(5);
send_byte(hdata);
delay(1);
send_byte(ldata);
delay(1);
// CS_L;
}
void LCD12864_write_data(uchar ddata)
{
uchar hdata,ldata;
hdata = ddata & 0xf0;
ldata = (ddata<<4) & 0xf0;
// CS_H;
send_byte(0xfa);
delay(5);
send_byte(hdata);
delay(1);
send_byte(ldata);
delay(1);
// CS_L;
}
void LCD12864_init()
{
delay(10);
CS_H;
LCD12864_write_cmd(0x30);
LCD12864_write_cmd(0x0c);//
LCD12864_write_cmd(0x01);
// LCD12864_write_cmd(0x06);
}
void LCD12864_write(uchar add,uchar *str)
{
uchar k;
LCD12864_write_cmd(add);
for(k = 0;k<*str;k++)
{
LCD12864_write_data(*str);
str++;
}
}
void main(void)
{
WDTCTL = WDTPW + WDTHOLD;
PORT_init();
Sys_init();
LCD12864_init();
while(1)
{
delay(5);
LCD12864_write_cmd(0x80);
LCD12864_write(0x80,"???V");
LCD12864_write(0x90,"哇");
}
}
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
刚刚学习,谢谢分享
一周热门 更多>