最近翻出玩过的TI LaunchPad,顺手连了一个12864屏,串连驱动,过年了,向EEPW示爱,,呵呵,,祝论坛马年火爆异常,,
看看照片
顺便贴出程序
#include <msp430g2553.h>
//#include"LCD12864P.h"
#define uint unsigned int
#define uchar unsigned char
extern uchar LCD_table[];//0123456789
extern void delay_1ms();
extern void delay_nms(uint n);
extern void Ini_Lcd(void);
extern void Send(uchar type,uchar transdata);//0-写控制命令,1-写数据
extern void lcd_pos(uchar x,uchar y);//定位
extern void Disp_HZ(const uchar * pt,uchar num);//显示汉字
extern void Disp_SZ(uchar shuzi);//显示一个数字
#define BIT(x) (1 << (x))
#define uint unsigned int
#define uchar unsigned char
uchar LCD_table[]={0x30,0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39};//0123456789
void Send(uchar type,uchar transdata);
#define cyCS 0 //P1.0,片选信号 接屏4脚
#define cySID 1 //P1.1,串行数据 接屏5脚
#define cyCLK 2 //P1.2,同步时钟 接屏6脚
#define cyPORT P1OUT
#define cyDDR P1DIR
void delay_1ms()
{
uint i;
for(i=0;i<1140;i++);
}
void delay_nms(uint n)
{
uint i = 0;
for(i = n;i > 0;i--)
delay_1ms();
}
void Ini_Lcd(void)
{
cyDDR |= BIT(cyCLK) + BIT(cySID) + BIT(cyCS); //相应的位端口设置为输出
delay_nms(600); //延时等待液晶完成复位
Send(0,0x30); /*功能设置:一次送8位数据,基本指令集*/
delay_nms(10);
Send(0,0x02); /*DDRAM地址归位*/
delay_nms(5);
Send(0,0x0c); /*显示设定:开显示,不显示光标,不做当前显示位反白闪动*/
delay_nms(5);
Send(0,0x01); /*清屏,将DDRAM的位址计数器调整为“00H”*/
delay_nms(500);
Send(0,0x06); /*功能设置,点设定:显示字符/光标从左到右移位,DDRAM地址加1*/
delay_nms(10);
}
void Send(uchar type,uchar transdata)//0-写控制命令,1-写数据
{
uchar firstbyte = 0xf8;
uchar temp;
uchar i,j = 3;
if(type) firstbyte |= 0x02;
cyPORT |= BIT(cyCS);
cyPORT &= ~BIT(cyCLK);
while(j > 0)
{
if(j == 3) temp = firstbyte;
else if(j == 2) temp = transdata&0xf0;
else temp = (transdata << 4) & 0xf0;
for(i = 8;i > 0;i--)
{
if(temp & 0x80) cyPORT |= BIT(cySID);
else cyPORT &= ~BIT(cySID);
cyPORT |= BIT(cyCLK);
temp <<= 1;
cyPORT &= ~BIT(cyCLK);
}
//三个字节之间一定要有足够的延时,否则易出现时序问题
if(j == 3) delay_nms(1);
else delay_nms(1);
j--;
}
cyPORT &= ~BIT(cySID);
cyPORT &= ~BIT(cyCS);
}
void lcd_pos(uchar x,uchar y)//定位
{
uchar pos;
switch(x)
{
case 1:pos=0x80;break;
case 2:pos=0x90;break;
case 3:pos=0x88;break;
case 4:pos=0x98;break;
default:pos=0x80;
}
pos += y;
Send(0,pos);
}
void Disp_HZ(const uchar * pt,uchar num)//显示汉字
{
uchar i;
for(i = 0;i < (num*2);i++)
Send(1,*(pt++));
}
void Disp_SZ(uchar shuzi)//显示一个数字
{
Send(1,LCD_table[shuzi]);
}
void main()
{
WDTCTL = WDTPW + WDTHOLD;
Ini_Lcd();
lcd_pos(1,1);
Disp_HZ("EEPW论坛新年好",7);
lcd_pos(3,2);
Disp_HZ("马年火爆",4);
lcd_pos(2,3);
Disp_SZ(2);
Disp_SZ(0);
Disp_SZ(1);
Disp_SZ(4);
lcd_pos(4,1);
Disp_HZ("LED",4);
lcd_pos(4,3);
Disp_HZ("版块祝贺",4);
while(1);
}