/*********************************************** **** LAUNCH PAD 学习之LCD *** **** MCU: MSP430 *** **** 作者: 常见泽 *** **** *** **** *** **** 2012.05.30.11:16 *** **** 实验现象:LCD显示EE LOG *** **** *** ****P1.0~P1.7 数据口 P2.0 P2.1 P2.2 en rs Psb*** ***********************************************/ #include <msp430g2452.h> #define uchar unsigned char #define uint unsigned int
unsigned char table[]="EE-LaunchPad"; unsigned char num; void delay_1ms(void) { unsigned int i; for (i=0;i<1140;i++); }
const unsigned char ucpic[]= { 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x0F,0xFF,0xFF,0xF8,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x1F,0xFF,0xFF,0xFC,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x3F,0xFF,0xC3,0xFC,0x00,0x30,0x00,0x06,0x00,0xE0,0x06,0x66,0x19,0x8C,0x31, 0x00,0x3F,0xFF,0xC3,0xFC,0x00,0x30,0x00,0x06,0x00,0xE0,0x06,0x66,0x19,0x8C,0x31, 0x00,0x3F,0xFE,0x01,0xFE,0x02,0x39,0x00,0x06,0x00,0xC0,0x0C,0x62,0x19,0x8C,0x31, 0x00,0x3F,0xF8,0x00,0xFE,0x07,0x31,0x80,0xFC,0x00,0xC0,0x0C,0x62,0x19,0x8C,0x31, 0x00,0x3F,0xF0,0x00,0xFE,0x06,0x31,0x80,0x78,0x00,0xC0,0x0C,0x66,0x1D,0xDC,0x31, 0x00,0x3F,0xE0,0x01,0xFE,0x06,0x31,0x80,0x30,0x00,0xC0,0x0C,0x00,0x19,0xCC,0x30, 0x00,0x3F,0xC0,0x03,0xFE,0x07,0x39,0x80,0x38,0x00,0xC0,0x1F,0x00,0x18,0x8C,0x00, 0x00,0x3F,0xC0,0x03,0xFE,0x07,0x39,0x80,0x38,0x00,0xC0,0x1F,0x00,0x18,0x8C,0x00, 0x00,0x3F,0xC0,0x3F,0xFE,0x06,0x31,0x80,0x38,0x00,0xC0,0x3D,0x18,0x19,0x8C,0x0C, 0x00,0x3F,0x80,0x7F,0xFE,0x06,0x31,0x80,0x38,0x00,0xE0,0x3D,0x18,0x19,0x8C,0x1C, 0x00,0x3F,0x80,0xFF,0xFE,0x06,0x31,0x80,0x18,0x00,0xE0,0x3D,0x18,0x19,0x8C,0x3C, 0x00,0x3F,0x81,0xF3,0xFE,0x07,0x31,0x80,0x38,0x00,0xE0,0x3F,0x18,0x19,0xD8,0x0C, 0x00,0x3F,0x81,0xF3,0xFE,0x07,0x31,0x80,0x38,0x00,0xE0,0x3F,0x18,0x19,0xD8,0x0C, 0x00,0x3F,0x03,0xC1,0xFE,0x00,0x30,0x00,0x30,0x00,0xE0,0x3F,0x18,0x18,0x00,0x0C, 0x00,0x3F,0x03,0xC0,0xFE,0x00,0x30,0x01,0xF0,0x00,0xE0,0x35,0x18,0x1C,0x00,0x0C, 0x00,0x3F,0x03,0x80,0xFE,0x00,0x3C,0x80,0x00,0x00,0xE0,0x0C,0x18,0x0C,0x00,0x18, 0x00,0x3F,0x03,0x80,0xFE,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x3F,0x03,0x80,0xFE,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x3F,0x03,0xC0,0xFE,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x3F,0x01,0xC1,0xFE,0x1F,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF, 0x00,0x3F,0x81,0xFF,0xFE,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x3F,0x80,0xFF,0xFE,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x3F,0x80,0xFF,0xFE,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x3F,0x80,0x7F,0xFE,0x00,0x00,0x00,0x00,0x00,0x08,0x08,0x00,0x00,0x00,0x00, 0x00,0x3F,0xC0,0x0F,0xFE,0x00,0x00,0x00,0x00,0x00,0x18,0x18,0x00,0x00,0x00,0x00, 0x00,0x3F,0xE0,0x01,0xFE,0x01,0x01,0x80,0x00,0x60,0x10,0xD0,0x00,0x00,0x00,0x00, 0x00,0x3F,0xF0,0x01,0xFE,0x04,0x44,0x4C,0x89,0xB1,0x93,0x70,0x00,0x00,0x00,0x00, 0x00,0x3F,0xF8,0x00,0xFE,0x0C,0x4C,0x4D,0xD3,0x1B,0x12,0x30,0x78,0xE3,0xF8,0x3C, 0x00,0x3F,0xF8,0x00,0xFE,0x0C,0x4C,0x4D,0xD3,0x1B,0x12,0x30,0x78,0xE3,0xF8,0x3C, 0x00,0x3F,0xFC,0x01,0xFE,0x0F,0xCF,0xC5,0xF2,0x12,0x24,0x30,0x81,0x16,0x48,0x60, 0x00,0x3F,0xFF,0x01,0xFE,0x08,0x08,0x06,0x62,0x12,0x24,0x20,0x82,0x14,0x88,0x40, 0x00,0x3F,0xFF,0xFF,0xFE,0x08,0x08,0x06,0x63,0x26,0x26,0x60,0x83,0x24,0x88,0x40, 0x00,0x0F,0xFF,0xFF,0xFE,0x07,0x07,0x04,0x41,0xC4,0x63,0xE4,0x71,0xC0,0x92,0x39, 0x00,0x0F,0xFF,0xFF,0xFE,0x07,0x07,0x04,0x41,0xC4,0x63,0xE4,0x71,0xC0,0x92,0x39, 0x00,0x07,0xFF,0xFF,0xFC,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
}; //图像数据
/***************************************** * * N ms延时函数 * ****************************************/ void delay_nms(unsigned int n) { unsigned int i=0; for (i=0;i<n;i++) delay_1ms(); }
void write_com(unsigned int com) { //lcdrs = 0; P2OUT&= 0xfd; P1OUT = com; delay_nms(5); //lcden = 1; P2OUT|= 0x01; delay_nms(5); P2OUT&= 0xfe; }
void write_dat(unsigned int dat) { //lcdrs = 1; P2OUT |= 0x02; P1OUT = dat; delay_nms(5); //lcden=1; P2OUT|= 0x01; delay_nms(5); // lcden=0; P2OUT&= 0xfe;
} void disp_12864(uchar addr,const uchar *pt,uchar num) { uchar i; write_com(addr); for(i=0;i<(num*2);i++) write_dat(*(pt++)); } void init() { //PSB=1;//并口模式 P2OUT |= BIT2; delay_nms(15); //EN=0; P2OUT&= 0xfe; delay_nms(5); write_com(0x30); delay_nms(1); write_com(0x08);//清屏 delay_nms(1); write_com(0x0c);//开显示,关光标 delay_nms(1); write_com(0x01); delay_nms(1); write_com(0x06);//第一行显示位置 delay_nms(1); }
void lcd12864_image(const unsigned char *p) { int x,y; write_com(0x34); //扩展指令集动作,绘图显示OFF for (y=0;y<32;y++) //送上半屏显示数据 { write_com(0x80|y); //送显示Y坐标0x80-0x9f write_com(0x80); //送显示X坐标0x80 for (x=0;x<16;x++) { write_dat(*p); p++; } }
for (y=0;y<32;y++) //送下半屏显示数据 { write_com(0x80|y); //送显示Y坐标0x80-0x9f write_com(0x88); //送显示X坐标0x88 for (x=0;x<16;x++) { write_dat(*p); p++; } } write_com(0x36); //扩展指令集动作,绘图显示ON }
void main(void) { WDTCTL = WDTPW + WDTHOLD; // Stop WDT P1DIR |= 0xff; // P1.2 output P2DIR |= 0xff; init();
write_com(0x01); //清除显示(清零DDRAM)
lcd12864_image(ucpic); //送图像显示数据 delay_nms(5000); while(1); }
复制代码 |