#include <msp430g2553.h> //包含库文件 #define uint unsigned int #define uchar unsigned char uchar LCD_table1[]={0x30,0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39};//0123456789 #define LCD_DataIn P1DIR=0x00;//数据口方向设置为输入 #define LCD_DataOut P1DIR=0xff;//数据口方向为输出 #define LCD2MCU_Data P1IN #define MCU2LCD_Data P1OUT #define LCD_RS_L P2OUT&=~BIT0;//11111110 #define LCD_RS_H P2OUT|=BIT0; #define LCD_RW_L P2OUT&=~BIT1; #define LCD_RW_H P2OUT|=BIT1; #define LCD_EN_L P2OUT&=~BIT2; #define LCD_EN_H P2OUT|=BIT2; #define LCD_PSB_L P2OUT&=~BIT3; #define LCD_PSB_H P2OUT|=BIT3; #define LCD_RST_L P2OUT&=~BIT4; #define LCD_RST_H P2OUT|=BIT4; const unsigned char nBitmapDot[] = // 数据表 { 0x02,0x08,0x00,0x08,0x00,0x00,0x04,0x00,0x07,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0xD0,0x06,0x04,0x08,0x03,0x02,0x00,0x38,0x80,0x00,0x00,0x00,0x00,0x00,0x00, 0x41,0x00,0x09,0x43,0x00,0x04,0xA1,0x80,0x41,0xFF,0x00,0x00,0x00,0x00,0x00,0x00, 0x42,0x00,0x29,0x00,0x00,0x14,0x80,0x00,0x8E,0x00,0xE7,0x00,0x00,0x00,0x00,0x00, 0x32,0x88,0x29,0x30,0x04,0x14,0x98,0x00,0x70,0x00,0x1C,0x80,0x00,0x00,0x00,0x00, 0x0C,0x00,0x16,0x48,0x00,0x0B,0x24,0x00,0x20,0x00,0x08,0x60,0x00,0x00,0x00,0x00, 0x00,0x20,0x4D,0x80,0x00,0x26,0xC0,0x00,0x40,0x00,0x08,0x10,0x00,0x00,0x00,0x00, 0x40,0x20,0x00,0x10,0x00,0x00,0x08,0x00,0x4C,0x00,0x08,0x10,0x00,0x00,0x00,0x00, 0x04,0x24,0x00,0x00,0x00,0x00,0x00,0x00,0x90,0x00,0x08,0x20,0x00,0x00,0x00,0x00, 0x00,0x20,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0x08,0x09,0xC0,0x00,0x00,0x00,0x00, 0x18,0x10,0x00,0x00,0x00,0x00,0x00,0x01,0x00,0x04,0x00,0x40,0x00,0x00,0x00,0x00, 0x25,0x3F,0xC3,0xFE,0x3F,0xE0,0x00,0x01,0x10,0x04,0x00,0x40,0x00,0x00,0x00,0x00, 0xA4,0x08,0x40,0x20,0x00,0x41,0x80,0x01,0x10,0x00,0x00,0x20,0x00,0x00,0x00,0x00, 0xA4,0xC8,0x47,0xFF,0x00,0x83,0xC0,0x01,0x00,0x40,0x00,0x20,0x00,0x00,0x00,0x00, 0x59,0x28,0x40,0x20,0x03,0x03,0xC0,0x02,0x00,0x40,0x00,0x20,0x00,0x00,0x00,0x00, 0x36,0x08,0x81,0xFC,0x02,0x03,0xC0,0x02,0xF0,0x40,0x10,0x20,0x00,0x00,0x00,0x00, 0x00,0x44,0x81,0x24,0x02,0x01,0x80,0x05,0x0C,0x04,0x10,0x20,0x00,0x00,0x00,0x00, 0x00,0x05,0x01,0xFC,0x02,0x01,0x80,0x05,0x42,0x00,0x14,0x40,0x00,0x00,0x00,0x00, 0x00,0x02,0x01,0x24,0x02,0x00,0x00,0x05,0x51,0x00,0x1C,0x40,0x00,0x00,0x00,0x00, 0x00,0x05,0x03,0xFE,0x02,0x01,0x80,0x04,0x91,0x03,0xC0,0x40,0x00,0x00,0x00,0x00, 0x00,0x18,0xC0,0x20,0x02,0x01,0x80,0x04,0x61,0x00,0x00,0x40,0x00,0x00,0x00,0x00, 0x02,0x60,0x37,0xFF,0x0E,0x00,0x00,0x04,0x1E,0x00,0x00,0x80,0x00,0x00,0x00,0x00, 0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x02,0x00,0x00,0x00,0x80,0x00,0x00,0x00,0x00, 0x40,0x7F,0xF4,0x0A,0x3B,0xF3,0xFE,0x01,0x01,0xF0,0x01,0x00,0x00,0x00,0x00,0x00, 0x38,0x05,0x02,0x0A,0x2A,0x90,0x04,0x00,0xC7,0xF8,0x02,0x00,0x00,0x00,0x00,0x00, 0x04,0x3F,0xE2,0xFF,0x2A,0x90,0x08,0x00,0x70,0xF8,0x04,0x00,0x00,0x00,0x00,0x00, 0x20,0x25,0x20,0x88,0x3A,0x90,0x30,0x00,0xC7,0x00,0x08,0x00,0x00,0x00,0x00,0x00, 0x00,0x3F,0xE2,0xF9,0x2B,0xF0,0x20,0x01,0x00,0x00,0xFE,0x00,0x00,0x00,0x00,0x00, 0x00,0x04,0x02,0x89,0x2A,0x00,0x20,0x02,0x20,0x00,0x01,0x00,0x00,0x00,0x00,0x00, 0x41,0x7F,0xF4,0xFA,0x3A,0x00,0x20,0x04,0x48,0x00,0x00,0x80,0x00,0x00,0x00,0x00, 0x18,0x08,0x84,0xD4,0x2A,0x00,0x20,0x08,0x80,0x08,0x00,0x80,0x00,0x00,0x00,0x00, 0x20,0x1D,0x05,0x75,0x2A,0x10,0x20,0x09,0x00,0x00,0x00,0x40,0x00,0x00,0x00,0x00, 0x40,0x03,0x85,0x4B,0x4A,0x10,0x20,0x12,0x30,0x00,0x80,0x40,0x00,0x00,0x00,0x00, 0x50,0x7C,0x62,0x11,0x5B,0xF0,0xE0,0x13,0x8F,0xC0,0x80,0x20,0x00,0x00,0x00,0x00, 0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x14,0x78,0x3F,0x00,0x20,0x00,0x00,0x00,0x00, 0x04,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x03,0xC0,0x80,0x20,0x00,0x00,0x00,0x00, 0x04,0x00,0x00,0x00,0x00,0x00,0x00,0x28,0x00,0x0F,0x80,0x20,0x00,0x00,0x00,0x00, 0x84,0x80,0x00,0x1C,0x08,0x0E,0x04,0x28,0x00,0x00,0x40,0x20,0x00,0x00,0x00,0x00, 0x04,0x1C,0x08,0x22,0x00,0x11,0x00,0x18,0x00,0x00,0x20,0x20,0x00,0x00,0x00,0x00, 0x02,0x22,0x00,0x21,0x00,0x10,0x80,0x08,0x00,0x00,0x20,0x20,0x00,0x00,0x00,0x00, 0xA1,0xA1,0x00,0x24,0xE0,0x12,0x70,0x10,0x00,0x00,0x30,0x20,0x00,0x00,0x00,0x00, 0x80,0x24,0xE0,0x18,0x10,0x0C,0x08,0x10,0x00,0x00,0x28,0x20,0x00,0x00,0x00,0x00, 0x98,0x18,0x10,0x00,0x80,0x00,0x40,0x10,0x08,0x00,0x25,0xE0,0x00,0x00,0x00,0x00, 0x24,0x00,0x81,0x00,0x00,0x80,0x00,0x1A,0x08,0x00,0x22,0x20,0x00,0x00,0x00,0x00, 0xC1,0x00,0x00,0x00,0x00,0x00,0x00,0x1D,0x46,0x00,0x22,0xA0,0x00,0x00,0x00,0x00, 0x08,0x00,0x00,0x01,0x04,0x00,0x82,0x0F,0x93,0x40,0x21,0x40,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 }; void delay_1ms() { uint i; for(i=0;i<1140;i++); } void delay_nms(uint n) { uint j; for(j=0;j<n;j++) delay_1ms(); } /*------------------检查忙位-----------------------------*/ void chk_busy() { uchar lcdtemp=0; LCD_RS_L; LCD_RW_H; LCD_DataIn; do { LCD_EN_H; _NOP(); lcdtemp = LCD2MCU_Data; LCD_EN_L; } while(lcdtemp&0x80); LCD_DataOut; } /*------------------写命令到LCD------------------------------*/ void write_com(uchar cmdcode) { chk_busy(); LCD_RW_L; MCU2LCD_Data = cmdcode; LCD_EN_H; _NOP(); LCD_EN_L; } /*-------------------写数据到LCD----------------------------*/ void write_data(uchar Dispdata) { chk_busy(); LCD_RS_H; LCD_RW_L; MCU2LCD_Data = Dispdata; LCD_EN_H; _NOP(); LCD_EN_L; } /*------------------初始化LCD屏--------------------------*/ void lcdreset() { LCD_RST_L; delay_nms(60); LCD_RST_H; delay_nms(1); LCD_PSB_H; delay_nms(600); write_com(0x30); delay_nms(10); //选择基本指令集 write_com(0x02); //地址归位 delay_nms(5); write_com(0x0c); //开显示(无游标、不反白) delay_nms(10); write_com(0x01); //清除显示,并且设定地址指针为00H delay_nms(500); write_com(0x06); //指定在资料的读取及写入时,设定游标的移动方向及指定显示的移位 delay_nms(10); } /*------------------显示字符串--------------------------*/ void printstring(uchar *s) { while(*s>0) { write_data(*s); s++; delay_nms(5); } } /*------------------清屏命令--------------------------*/ void clrscreen() { write_com(0x01); delay_nms(10); } void write_swcom(uchar com) { LCD_RS_L; LCD_RW_L; delay_nms(1); MCU2LCD_Data=com; LCD_EN_L; delay_nms(1); } void write_swdat(uchar dat) { chk_busy(); LCD_RS_H; LCD_RW_L; delay_nms(1); MCU2LCD_Data=dat; LCD_EN_H; delay_nms(1); LCD_EN_L; delay_nms(1); } void LCD_ImgDisplay(const unsigned char *img) { unsigned char i,j; for(j=0;j<32;j++) //垂直坐标Y { for(i=0;i<8;i++) //水平坐标X { write_com(0x34); write_com(0x80+j); //(扩展扩展指令集)设置GDRAM垂直Y位置 write_com(0x80+i); //(扩展扩展指令集)设置GDRAM水平X位置 write_com(0x30); write_data(img[j*16+i*2]); //放入数据高字节 write_data(img[j*16+i*2+1]); //放入数据低字节 } } for(j=32;j<64;j++) //垂直坐标Y { for(i=0;i<8;i++) //水平坐标X {write_com(0x34); write_com(0x80+j-32); write_com(0x88+i); write_com(0x30); write_data(img[j*16+i*2]); write_data(img[j*16+i*2+1]); } } write_com(0x36);} void main() { WDTCTL = WDTPW + WDTHOLD; P1DIR|=0xff; P2DIR|=0xff; lcdreset(); clrscreen(); LCD_ImgDisplay(nBitmapDot); }