#include <msp430x14x.h>
#include "12864.h"
typedef unsigned int uint;
typedef unsigned char uchar;
#define BIT(x) ( 1<<(x))
extern const unsigned char shuzi_table[];
/**********液晶控制IO的宏定义*************/
#define cyCS 0 //P5.0,片选信号
#define cySID 1 //P5.1,串行数据
#define cyCLK 2 //P5.2,同步时钟
#define PSB 3 //P5.3, 串并选择
#define cyPORT P5OUT
#define cyDDR P5DIR
/*******************************************
函数名称:delay_Nus
功 能:延时N个us的时间
参 数:n--延时长度
返回值 :无
********************************************/
void delay_Nus(uint n)
{
uchar i;
for(i = n;i > 0;i--)
_NOP();
}
/*******************************************
函数名称:delay_1ms
功 能:延时约1ms的时间
参 数:无
返回值 :无
********************************************/
void delay_1ms(void)
{
uchar i;
for(i = 150;i > 0;i--) _NOP();
}
/*******************************************
函数名称:delay_Nms
功 能:延时N个ms的时间
参 数:无
返回值 :无
********************************************/
void delay_Nms(uint n)
{
uint i = 0;
for(i = n;i > 0;i--)
delay_1ms();
}
/*******************************************
函数名称:Ini_Lcd
功 能:初始化液晶模块
参 数:无
返回值 :无
********************************************/
void LCD_Init(void)
{
cyDDR |= BIT(cyCLK) + BIT(cySID) + BIT(cyCS) + BIT(PSB); //相应的位端口设置为输出
cyPORT&= ~BIT(PSB); //设置串行传输方式
// P5DIR |=0X10;
//P5OUT |=0X10;
delay_Nms(100); //延时等待液晶完成复位
Send(0,0x30); /*功能设置:一次送8位数据,基本指令集*/
delay_Nus(72);
Send(0,0x02); /*DDRAM地址归位*/
delay_Nus(72);
Send(0,0x0c); /*显示设定:开显示,不显示光标,不做当前显示位反白闪动*/
delay_Nus(72);
Send(0,0x01); /*清屏,将DDRAM的位址计数器调整为“00H”*/
delay_Nus(72);
Send(0,0x06); /*功能设置,点设定:显示字符/光标从左到右移位,DDRAM地址加1*/
delay_Nus(72);
}
/*******************************************
函数名称:Send
功 能:MCU向液晶模块发送1一个字节的数据
参 数:type--数据类型,0--控制命令,1--显示数据
transdata--发送的数据
返回值 :无
********************************************/
void Send(uchar type,uchar transdata)
{
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_Nus(600);
else delay_Nus(200);
j--;
}
cyPORT &= ~BIT(cySID);
cyPORT &= ~BIT(cyCS);
}
void LCD_SetXY( uchar X, uchar Y)
{
switch(X)
{
case 1:
Send(0,0x7F + Y);
break;
case 2:
Send(0,0x8F + Y);
break;
case 3:
Send(0,0x87 + Y);
break;
case 4:
Send(0,0x97 + Y);
}
}
void show(uchar X, uchar Y, uchar wdata)
{
LCD_SetXY(X,Y);
Send(1,wdata);
}
void showstr(uchar X, uchar Y, uchar *String)
{
unsigned char temp;
LCD_SetXY(X,Y);
temp = *String;
while(temp!=0) {
Send(1,temp);
temp = *(++String);
}
}
void LCD_WriteComm(uchar comm)
{
Send(0,comm);
}
MSP430利用定时器测频率
4星 · 超过85%的资源 需积分: 50 52 浏览量
2010-11-23
20:50:34
上传
评论 8
收藏 32KB RAR 举报
zxm1001091
- 粉丝: 0
- 资源: 3
最新资源
- BLOCK_TYPE_HEARTBEAT_D70A3465D4EE4E9_046141_dump_1st.dmp
- 项目方法测试调用接口工具
- studyupdate
- 基于西瓜数据集的决策树实现.zip
- 60套HTML网站源码-响应式-涵盖(简历&作品展示&商业&科技&培训&商城&课设等)-适配移动设备-解压即用.zip
- 贪心算法要点和难点实例代码解析
- 65套HTML网站源码-响应式-涵盖(简历&作品展示&商业&科技&培训&商城&课设等)-适配移动设备-解压即用.zip
- 多因素决策树的Python实现.zip
- 使用Python在莺尾花数据集上实现了决策树算法,文件里有数据集.zip
- python实现决策树.zip
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
- 1
- 2
- 3
前往页