串口画图
#include <msp430x14x.h>
#include <math.h>
#include "pic.h"
#define LCD_CS_High P5OUT|=BIT2 // LCD_RS P62
#define LCD_CS_Low P5OUT&=~BIT2 // LCD_RS
#define LCD_SID_High P5OUT|=BIT4 // LCD_RW DB0_DB7 P64
#define LCD_SID_Low P5OUT&=~BIT4 // LCD_RW IR DR
#define LCD_CLK_High P5OUT|=BIT3 // LCD_EN P63
#define LCD_CLK_Low P5OUT&=~BIT3 // LCD_EN
#define LCD_PSB_High P5OUT|=BIT0 //
#define LCD_PSB_Low P5OUT&=~BIT0 // P30
#define uchar unsigned char
#define uint unsigned int
uchar line[64][16]={0},Point[8]={0x80,0x40,0x20,0x10,0x08,0x04,0x02,0x01};
void delay_ms(unsigned int timer)
{
unsigned int i;
for(i=0;i<1000;i--)
for(;timer>0;timer--)
;
}
void Send_Byte(unsigned byte)
{
uchar i;
for(i=0;i<8;i++)
{
LCD_CLK_Low;
if(byte&0x80)
{LCD_SID_High; delay_ms(10);}
else
{ LCD_SID_Low ;delay_ms(10);}
byte<<=1;
LCD_CLK_High;
delay_ms(10);
LCD_CLK_Low;
delay_ms(10);
}
}
/*鍐欏懡浠ゅ埌娑叉櫠*/
void LCD_WCMD(unsigned char cmd)
{
delay_ms(1);
Send_Byte(0xf8); //11111,RW(0),RS(0),0;
delay_ms(2);
Send_Byte(0xf0&cmd);
delay_ms(2);
Send_Byte(0xf0&cmd<<4);
delay_ms(2);
}
/*鍐欐暟鎹埌娑叉櫠*/
void LCD_WDAT(unsigned char date)
{
delay_ms(1);
Send_Byte(0xfa); //11111,RW(0),RS(1),0
delay_ms(2);
Send_Byte(0xf0&date);
delay_ms(2);
Send_Byte(0xf0&date<<4);
delay_ms(2);
}
void Display(unsigned char X,unsigned char Y,unsigned char *string)
{
if (X==0)
{X=0x80;}
else if (X==1)
{X=0x90;}
else if (X==2)
{X=0x88;}
else if (X==3)
{X=0x98;}
LCD_WCMD(X+Y);
while(*string )
{ //鏄
LCD_WDAT(*string++);
}
}
void Display_number(unsigned char X,unsigned char Y,unsigned char number)
{
if (X==0)
{X=0x80;}
else if (X==1)
{X=0x90;}
else if (X==2)
{X=0x88;}
else if (X==3)
{X=0x98;}
LCD_WCMD(X+Y);
LCD_WDAT(48+number);
}
void Clock_init()
{
unsigned char t;
BCSCTL1 = RSEL0 + RSEL1 + RSEL2; // XT2on, max RSEL
BCSCTL1&=~XT2OFF; //鎵撳紑XT2鎸崱鍣?
do
{
IFG1 &= ~OFIFG; // 娓呴櫎鎸崱鍣ㄥけ鏁堟爣蹇?
for (t = 255; t > 0; t--); // 寤舵椂锛岀瓑寰匵T2璧锋尟
}
while ((IFG1 & OFIFG) != 0); // 鍒ゆ柇XT2鏄惁璧锋尟
BCSCTL2 |= SELS+SELM_2; // SMCLK = XT2
}
void LCD_init()
{
LCD_WCMD(0x34); //鎵嶄綔
delay_ms(2);
LCD_WCMD(0x30); //嶄綔
delay_ms(2);
LCD_WCMD(0x0C); //鏄叧鍏夋爣
delay_ms(2);
LCD_WCMD(0x01); //
delay_ms(2);
}
/*------------------------------------------------
娓呭睆
------------------------------------------------*/
void ClrScreen()
{
LCD_WCMD(0x01);
delay_ms(15);
}
/*------------------------------------------------
璁剧疆鍒扮粯鍥炬ā寮?
------------------------------------------------*/
void SetGraphicMode()
{
LCD_WCMD(0x36); //閫夋嫨紡
delay_ms(20);
}
/*------------------------------------------------
鏄剧ず鍥剧墖
------------------------------------------------*/
void LCD_PutGraphic(unsigned char *img)
{
int i,j;
for(i=0;i<32;i++)
{
LCD_WCMD(0x80 + i); //
LCD_WCMD(0x80); //
for(j=0;j<16;j++)
{
LCD_WDAT(*img);
img++;
}
}
for(i=0;i<32;i++)
{
LCD_WCMD(0x80 + i);
LCD_WCMD(0x88);
for(j=0;j<16;j++)
{
LCD_WDAT(*img);
img++;
}
}
}
void DrawPoint(uchar x,uchar y)
{
line[x][y/8]|=Point[y%8];
//delay_ms(100);
}
void main( void )
{
uchar u;
//unsigned char x,y,colour=1 ;
WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer to prevent time out reset
//Clock_init(); //
P5DIR|=BIT0+BIT2+BIT3+BIT4;
LCD_PSB_Low;
LCD_init();
for(u=0;u<64;u++)
DrawPoint(u,u);
for(u=32;u<63;u++)
DrawPoint(32,u);
for(u=32;u<63;u++)
DrawPoint(32,u+32);
for(u=63;u>0;u--)
DrawPoint(63-u,u+63);
ClrScreen(); //清屏
SetGraphicMode(); //设置成绘图模式
LCD_PutGraphic(&line[0][0]);
delay_ms(5000);
_BIS_SR(LPM0_bits);
}
|