?? cryfuncs.c
字號(hào):
#include <msp430x14x.h>
typedef unsigned int uint;
typedef unsigned char uchar;
#define BIT(x) (1 << (x))
void Send(uchar type,uchar transdata);
/**********液晶控制IO的宏定義*************/
#define cyCS 0 //P3.0,片選信號(hào)
#define cySID 1 //P3.1,串行數(shù)據(jù)
#define cyCLK 2 //P3.2,同步時(shí)鐘
#define cyPORT P3OUT
#define cyDDR P3DIR
/*******************************************
函數(shù)名稱:delay_Nus
功 能:延時(shí)N個(gè)us的時(shí)間
參 數(shù):n--延時(shí)長(zhǎng)度
返回值 :無(wú)
********************************************/
void delay_Nus(uint n)
{
uchar i;
for(i = n;i > 0;i--)
_NOP();
}
/*******************************************
函數(shù)名稱:delay_1ms
功 能:延時(shí)約1ms的時(shí)間
參 數(shù):無(wú)
返回值 :無(wú)
********************************************/
void delay_1ms(void)
{
uchar i;
for(i = 150;i > 0;i--) _NOP();
}
/*******************************************
函數(shù)名稱:delay_Nms
功 能:延時(shí)N個(gè)ms的時(shí)間
參 數(shù):無(wú)
返回值 :無(wú)
********************************************/
void delay_Nms(uint n)
{
uint i = 0;
for(i = n;i > 0;i--)
delay_1ms();
}
/*******************************************
函數(shù)名稱:Ini_Lcd
功 能:初始化液晶模塊
參 數(shù):無(wú)
返回值 :無(wú)
********************************************/
void Ini_Lcd(void)
{
cyDDR |= BIT(cyCLK) + BIT(cySID) + BIT(cyCS); //相應(yīng)的位端口設(shè)置為輸出
delay_Nms(100); //延時(shí)等待液晶完成復(fù)位
Send(0,0x30); /*功能設(shè)置:一次送8位數(shù)據(jù),基本指令集*/
delay_Nus(72);
Send(0,0x02); /*DDRAM地址歸位*/
delay_Nus(72);
Send(0,0x0c); /*顯示設(shè)定:開(kāi)顯示,不顯示光標(biāo),不做當(dāng)前顯示位反白閃動(dòng)*/
delay_Nus(72);
Send(0,0x01); /*清屏,將DDRAM的位址計(jì)數(shù)器調(diào)整為“00H”*/
delay_Nus(72);
Send(0,0x06); /*功能設(shè)置,點(diǎn)設(shè)定:顯示字符/光標(biāo)從左到右移位,DDRAM地址加1*/
delay_Nus(72);
}
/*******************************************
函數(shù)名稱:Send
功 能:MCU向液晶模塊發(fā)送1一個(gè)字節(jié)的數(shù)據(jù)
參 數(shù):type--數(shù)據(jù)類型,0--控制命令,1--顯示數(shù)據(jù)
transdata--發(fā)送的數(shù)據(jù)
返回值 :無(wú)
********************************************/
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);
}
//三個(gè)字節(jié)之間一定要有足夠的延時(shí),否則易出現(xiàn)時(shí)序問(wèn)題
if(j == 3) delay_Nus(600);
else delay_Nus(200);
j--;
}
cyPORT &= ~BIT(cySID);
cyPORT &= ~BIT(cyCS);
}
/*******************************************
函數(shù)名稱:Clear_GDRAM
功 能:清除液晶GDRAM內(nèi)部的隨機(jī)數(shù)據(jù)
參 數(shù):無(wú)
返回值 :無(wú)
********************************************/
void Clear_GDRAM(void)
{
uchar i,j,k;
Send(0,0x34); //打開(kāi)擴(kuò)展指令集
i = 0x80;
for(j = 0;j < 32;j++)
{
Send(0,i++);
Send(0,0x80);
for(k = 0;k < 16;k++)
{
Send(1,0x00);
}
}
i = 0x80;
for(j = 0;j < 32;j++)
{
Send(0,i++);
Send(0,0x88);
for(k = 0;k < 16;k++)
{
Send(1,0x00);
}
}
Send(0,0x30); //回到基本指令集
}
/*******************************************
函數(shù)名稱:Disp_HZ
功 能:顯示漢字程序
參 數(shù):addr--顯示位置的首地址
pt--指向顯示數(shù)據(jù)的指針
num--顯示數(shù)據(jù)的個(gè)數(shù)
返回值 :無(wú)
********************************************/
void Disp_HZ(uchar addr,const uchar * pt,uchar num)
{
uchar i;
Send(0,addr);
for(i = 0;i < (num*2);i++)
Send(1,*(pt++));
}
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -