?? lcd.c
字號:
/***********************************
project: 凌陽SPCE61A單片機應用例程
item:液晶顯示
version: V1.0
Description:
液晶基本操作,顯示一行
Author: 江蘇大學電氣信息工程學院
***********************************/
#include "spce061v004.h"
#include "main.h"
int De;
//=========================================================================================
//寫一位
//=========================================================================================
void WriteBit(char B)
{
int D;
D=*P_IOB_Buffer&0xfffd; //SDA輸出數據
if(B!=0)
*P_IOB_Data=D|0x0002;
else
*P_IOB_Data=D&0xfffd;
D=*P_IOB_Buffer&0xfffe; //SCK脈沖
*P_IOB_Data=D|0x0001;
De=8;
while(De--);
*P_IOB_Data=D&0xfffe;
}
//=========================================================================================
//寫一個字節
//=========================================================================================
void WriteByte(char B,char I)
{
int D,i;
D=*P_IOB_Buffer&0xffbf;
*P_IOB_Data=D|0x0040; //片選有效
for(i=1;i<6;i++)
WriteBit(1); //5個空脈沖,數據為1 synchronizing bitstring
WriteBit(0); //RW=0
De=5;
while(De--);
WriteBit(I); //寫指令還是數據?
De=5;
while(De--);
WriteBit(0); //寫一個0
De=5;
while(De--);
WriteBit(B&0x0080);//寫第7位
De=5;
while(De--);
WriteBit(B&0x0040);//寫第6位
De=5;
while(De--);
WriteBit(B&0x0020);//寫第5位
De=5;
while(De--);
WriteBit(B&0x0010);//寫第4位
De=5;
while(De--);
for(i=1;i<5;i++)
WriteBit(0); //4個空脈沖,數據為0
De=5;
while(De--);
WriteBit(B&0x0008);//寫第3位
De=5;
while(De--);
WriteBit(B&0x0004);//寫第2位
De=5;
while(De--);
WriteBit(B&0x0002);//寫第1位
De=5;
while(De--);
WriteBit(B&0x0001);//寫第0位
De=5;
while(De--);
for(i=1;i<5;i++)
WriteBit(0); //4個空脈沖,數據為0
De=5;
while(De--);
D=*P_IOB_Buffer&0xffbf;
*P_IOB_Data=D&0xffbf; //片選有效
*P_Watchdog_Clear=C_WDTCLR;
}
//=========================================================================================
//LCD初始化
//=========================================================================================
void LCDinit(void)
{
int D,i;
i=3;while(i--);
WriteByte(0x30,0);
Delay(DELAYINTERNAL1);
WriteByte(0x01,0);
Delay(DELAYINTERNAL1);
WriteByte(0x06,0);
Delay(DELAYINTERNAL1);
WriteByte(0x0c,0);
Delay(DELAYINTERNAL1);
}
//=========================================================================================
//顯示一行
//=========================================================================================
void LCDWriteLine(int Line,unsigned int HZCode[10])
{
int i;
switch (Line)
{
case 1:Line=0x80;break;
case 2:Line=0x90;break;
case 3:Line=0x88;break;
case 4:Line=0x98;break;
}
WriteByte(Line,0);
Delay(1000);
for (i=0;i<8;i++)
{
WriteByte((HZCode[i]&0xff00)>>8,1);
WriteByte(HZCode[i]&0x00ff,1);
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -