/***************************************************************
*MSP430各系列单片机串行控制LCD12864头文件
*by:杜运福 2011-3-20
*文件名称:MSP430_LCD12864.c
***************************************************************/
#define uint unsigned int
#define uchar unsigned char
#define ulong unsigned long
#define SID BIT0
#define SCLK BIT1
#define CS BIT2
#define LCDPORT P1OUT
#define SID_1 LCDPORT |= SID
#define SID_0 LCDPORT &= ~SID
#define SCLK_1 LCDPORT |= SCLK
#define SCLK_0 LCDPORT &= ~SCLK
#define CS_1 LCDPORT |= CS
#define CS_0 LCDPORT &= ~CS
//延时 n (ms)
void delay(uint nms)
{
while(nms>0)
{ __delay_cycles(1000);
--nms;
}
}
//LCD12864连接端口初始化
void LCDPort_Init()
{
P1SEL = 0;
P1DIR |= BIT0+BIT1+BIT2+BIT3;
P1OUT = 0xff;
}
/***********************************************************
*名 称:LCD_Write_cmd()
*功 能:写一个命令到LCD12864
*入口参数:cmd:待写入的命令,无符号字节形式
*出口参数:无
*说 明:写入命令时,RW=0,RS=0 扩展成24位串行发送
*格 式:11111 RW RS 0 xxxx0000 xxxx0000
* |最高的字节 |命令的bit7~4|命令的bit3~0|
***********************************************************/
void LCD_Write_cmd(uchar cmd)
{
uchar i,high4bits,low4bits;
ulong lcdcmd;
high4bits = cmd & 0xf0;
low4bits = (cmd<<4)&0xf0;
lcdcmd=((ulong)0xf8<<16)+((ulong)high4bits<<8)+(ulong)low4bits;
CS_1;
SCLK_0;
for(i=0;i<24;i++)
{
SID_0;
if(lcdcmd & 0x00800000) SID_1;
lcdcmd <<=1;
SCLK_1;
_NOP();
SCLK_0;
}
CS_0;
}
void Write_cmd(uchar cmd) //写命令到LCD12864
{ LCD_Write_cmd(cmd);
}
/***********************************************************
*名 称:LCD_Write_Byte()
*功 能:向LCD12864写入一个字节数据
*入口参数:byte:待写入的字符,无符号形式
*出口参数:无
*范 例:LCD_Write_Byte('F') //写入字符'F'
***********************************************************/
void LCD_Write_Byte(uchar byte)
{
uchar i,high4bits,low4bits;
ulong lcddat;
//while(IsBusy());///
high4bits = byte & 0xf0;
low4bits = (byte<<4)&0xf0;
lcddat=((ulong)0xfa<<16)+((ulong)high4bits<<8)+(ulong)low4bits;
CS_1;
for(i=0;i<24;i++)
{
SID_0;
if(lcddat & 0x00800000) SID_1;
lcddat <<=1;
SCLK_1;
SCLK_0;
}
CS_0;
}
void Write_data(uchar dat) //写一个字符到LCD12864
{ LCD_Write_Byte(dat);
}
void Write_char(uchar ch) //写一个字符到LCD12864
{ LCD_Write_Byte(ch);
}
/****************************************************/
//LCD12864初始化
void LCD_Init()
{
P1OUT &= ~BIT3; //复位LCD12864
__delay_cycles(50000); //50ms
P1OUT |= BIT3;
__delay_cycles(50000);
LCD_Write_cmd(0x30); //开显示
__delay_cycles(150); //150us
LCD_Write_cmd(0x30);
__delay_cycles(50); //50us
LCD_Write_cmd(0x0c);
__delay_cycles(150); //150us
LCD_Write_cmd(0x01);
__delay_cycles(12000);//12ms
LCD_Write_cmd(0x06);
__delay_cycles(10); //10us
LCD_Write_cmd(0x02);
__delay_cycles(10); //10us
LCD_Write_cmd(0x80);
__delay_cycles(10); //10us
}
/***********************************************************
*名 称:LCD_pos()
*功 能:设置液晶的显示位置
*入口参数:x:第几行,1~4对应第1行~第4行
* y:第几列,0~15对应第1列~第16列
*出口参数:无
*范 例:LCD_pos(2,3) //第二行,第四列
***********************************************************/
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;
LCD_Write_cmd(pos);
}
void Write_pos(uchar x,uchar y) //写地址 等效LCD_pos()
{ LCD_pos(x,y);
}
void Set_pos(uchar x,uchar y) //按自然习惯设置行列位置
{ LCD_pos(x,y-1);
}
/***********************************************************
*名 称:LCD_flash()
*功 能:LCD闪烁函数
*入口参数:times:屏幕闪烁的次数 1~255次
*出口参数:无
*说 明:闪烁周期为800ms左右
***********************************************************/
void LCD_flash(uchar times)
{
while(times>0)
{
LCD_Write_cmd(0x08);
delay(400);
LCD_Write_cmd(0x0C);
delay(400);
--times;
}
}
MSP430各系列单片机串行控制LCD12864头文件
需积分: 5 168 浏览量
2011-03-24
19:23:23
上传
评论
收藏 2KB RAR 举报
1______1
- 粉丝: 58
- 资源: 258
最新资源
- 毕业设计项目源码-使用Matlab基于PSO工具箱的函数寻优算法实现.zip
- libusb源码,libusb是一个跨平台的用户空间USB库
- 独栋别墅图纸CAD图纸D025-两层-10.72&06.36米-施工图.dwg
- 甄嬛传后宫大合影(闲的没事....)
- SAP GUI for Windows 8.00 patch 7 64Bit
- 毕业设计项目源码-使用Matlab基于动态粒子群算法的动态环境寻优算法.zip
- 华为云会议安装包适配华为擎云L410 -1060 ARM架构
- 清空redis缓存脚本指令
- Keithley6517静电计测试软件,支持24通道切换,DAQ高速采集
- STM8S微控制器-寄存器操作指南
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈