?? lm3033basicserialoperation.c
字號:
#include "Lm3033BasicOperation.h"
struct MenuStruct *nowmenupt;
void LcdWriteOneLineString(unsigned char row,unsigned char col,unsigned char* p);
void LcdClearScreen(void) ; //清屏
BYTE menu1[4][17]={
"1 進入menu1_1 ",
"2 進入menu1_2 ",
"3 進入menu1_3",
" null "
};
MenuStruct menu1struct;
BYTE menu1_1[4][17]={
"1 進入menu1_1_1 ",
"2 進入menu1_1_2 ",
"process1",
"null"
};
MenuStruct menu1_1struct;
BYTE menu1_2[4][17]={
"process2 ",
"process3 ",
"process4",
" null"
};
MenuStruct menu1_2struct;
BYTE menu1_3[4][17]={
"menu1_3 ",
"menu1_3 ",
"process5",
"null"
};
MenuStruct menu1_3struct;
BYTE menu1_1_1[4][17]={
"process7 ",
"process8",
"null",
"null"
};
struct MenuStruct menu1_1_1struct;
BYTE menu1_1_2[4][17]={
" null",
" null ",
"process6",
" null"
};
struct MenuStruct menu1_1_2struct;
/****以下函數用于菜單測試***********************/
void Process1(void)
{
LcdClearScreen();
LcdWriteOneLineString(1,1,"Process1 running");
}
void Process2(void)
{
LcdClearScreen();
LcdWriteOneLineString(1,1,"Process2 running");
}
void Process3(void)
{
LcdClearScreen();
LcdWriteOneLineString(1,1,"Process3 running");
}
void Process4(void)
{
LcdClearScreen();
LcdWriteOneLineString(1,1,"Process4 running");
}
void Process5(void)
{
LcdClearScreen();
LcdWriteOneLineString(1,1,"Process5 running");
}
void Process6(void)
{
LcdClearScreen();
LcdWriteOneLineString(1,1,"Process6 running");
}
void Process7(void)
{
LcdClearScreen();
LcdWriteOneLineString(1,1,"Process7 running");
}
void Process8(void)
{
LcdClearScreen();
LcdWriteOneLineString(1,1,"Process8 running");
}
void MenuInit(void) //初始發菜單
{
nowmenupt=&menu1struct;
menu1struct.menusize=4;
menu1struct.menuconcentpt=menu1[0];
menu1struct.premenupt=NULL;
menu1struct.nextmenupt[0]=&menu1_1struct;
menu1struct.nextmenupt[1]=&menu1_2struct;
menu1struct.nextmenupt[2]=&menu1_3struct;
menu1struct.nextmenupt[3]=NULL;
menu1struct.funpt[0]=NULL;
menu1struct.funpt[1]=NULL;
menu1struct.funpt[2]=NULL;
menu1struct.funpt[3]=NULL;
menu1_1struct.menusize=4;
menu1_1struct.menuconcentpt=menu1_1[0];
menu1_1struct.premenupt=&menu1struct;
menu1_1struct.nextmenupt[0]=&menu1_1_1struct;
menu1_1struct.nextmenupt[1]=&menu1_1_2struct;
menu1_1struct.nextmenupt[2]=NULL;
menu1_1struct.nextmenupt[3]=NULL;
menu1_1struct.funpt[0]=NULL;
menu1_1struct.funpt[1]=NULL;
menu1_1struct.funpt[2]=Process1;
menu1_1struct.funpt[3]=NULL;
menu1_2struct.menusize=4;
menu1_2struct.menuconcentpt=menu1_2[0];
menu1_2struct.premenupt=&menu1struct;
menu1_2struct.nextmenupt[0]=NULL;
menu1_2struct.nextmenupt[1]=NULL;
menu1_2struct.nextmenupt[2]=NULL;
menu1_2struct.nextmenupt[3]=NULL;
menu1_2struct.funpt[0]=Process2;
menu1_2struct.funpt[1]=Process3;
menu1_2struct.funpt[2]=Process4;
menu1_2struct.funpt[3]=NULL;
menu1_3struct.menusize=4;
menu1_3struct.menuconcentpt=menu1_3[0];
menu1_3struct.premenupt=&menu1struct;
menu1_3struct.nextmenupt[0]=NULL;
menu1_3struct.nextmenupt[1]=NULL;
menu1_3struct.nextmenupt[2]=NULL;
menu1_3struct.nextmenupt[3]=NULL;
menu1_3struct.funpt[0]=NULL;
menu1_3struct.funpt[1]=NULL;
menu1_3struct.funpt[2]=Process5;
menu1_3struct.funpt[3]=NULL;
menu1_1_1struct.menusize=4;
menu1_1_1struct.menuconcentpt=menu1_1_1[0];
menu1_1_1struct.premenupt=&menu1_1struct;
menu1_1_1struct.nextmenupt[0]=NULL;
menu1_1_1struct.nextmenupt[1]=NULL;
menu1_1_1struct.nextmenupt[2]=NULL;
menu1_1_1struct.nextmenupt[3]=NULL;
menu1_1_1struct.funpt[0]=Process7;
menu1_1_1struct.funpt[1]=Process8;
menu1_1_1struct.funpt[2]=NULL;
menu1_1_1struct.funpt[3]=NULL;
menu1_1_2struct.menusize=4;
menu1_1_2struct.menuconcentpt=menu1_1_2[0];
menu1_1_2struct.premenupt=&menu1_1struct;
menu1_1_2struct.nextmenupt[0]=NULL;
menu1_1_2struct.nextmenupt[1]=NULL;
menu1_1_2struct.nextmenupt[2]=NULL;
menu1_1_2struct.nextmenupt[3]=NULL;
menu1_1_2struct.funpt[0]=NULL;
menu1_1_2struct.funpt[1]=NULL;
menu1_1_2struct.funpt[2]=Process6;
menu1_1_2struct.funpt[3]=NULL;
}
/*void LcdModeSel(unsigned int mode) //LCD 串并行模式選擇
{
if(mode==SERIALMODE)
{
LcdSerialModSel_ ;
LcdModeFlag=SERIALMODE;
}
else
{
LcdParallelModSel_;
LcdModeFlag=PARALLELMODE;
}
}*/
void LcdDelay(int i) //等待LCD處理指令
{
int j=0xff;
for(;i>0;i--)
for(;j>0;j--);
}
void LcdSMWrite1ByteData(unsigned char data) //LCD串行模式寫一個字節數據
{
unsigned int i=0;
//LcdEnable;
LcdSID_H; //發送5個1
for(i=5;i>0;i--)
{
LcdClock_L;
LcdClock_H;
}
LcdSID_L; //發送1個0
LcdClock_L;
LcdClock_H;
LcdSID_H; //發送1個1 RS=1
LcdClock_L;
LcdClock_H;
LcdSID_L; //發送1個0
LcdClock_L;
LcdClock_H;
for(i=4;i>0;i--) //發送高4位
{
if(data&0x80)
{LcdSID_H;LcdClock_L; LcdClock_H;}
else
{LcdSID_L;LcdClock_L; LcdClock_H;}
data=data<<1;
}
LcdSID_L; //發送4個0
for(i=4;i>0;i--)
{
LcdClock_L;
LcdClock_H;
}
for(i=4;i>0;i--) //發送低4位
{
if(data&0x80)
{LcdSID_H;LcdClock_L; LcdClock_H;}
else
{LcdSID_L;LcdClock_L; LcdClock_H;}
data=data<<1;
}
LcdSID_L; //發送4個0
for(i=4;i>0;i--)
{
LcdClock_L;
LcdClock_H;
}
//LcdDisable;
LcdClock_L;
}
void LcdSMWrite1ByteInstruc(unsigned char data) //LCD串行模式寫一個字節指令
{
unsigned int i=0;
//LcdEnable;
LcdSID_H; //發送5個1
for(i=5;i>0;i--)
{
LcdClock_L;
LcdClock_H;
}
LcdSID_L; //發送3個0
for(i=3;i>0;i--)
{
LcdClock_L;
LcdClock_H;
}
for(i=4;i>0;i--) //發送高4位
{
if(data&0x80)
{LcdSID_H;LcdClock_L; LcdClock_H;}
else
{LcdSID_L;LcdClock_L; LcdClock_H;}
data=data<<1;
}
LcdSID_L; //發送4個0
for(i=4;i>0;i--)
{
LcdClock_L;
LcdClock_H;
}
for(i=4;i>0;i--) //發送低4位
{
if(data&0x80)
{LcdSID_H;LcdClock_L; LcdClock_H;}
else
{LcdSID_L;LcdClock_L; LcdClock_H;}
data=data<<1;
}
LcdSID_L; //發送4個0
for(i=4;i>0;i--)
{
LcdClock_L;
LcdClock_H;
}
//LcdDisable;
LcdClock_L;
}
/*
void ResetLCD(void) //LCD 復位
{
LcdRest;
}
*/
void LcdClearScreen(void) //清屏
{
LcdSMWrite1ByteInstruc(CLEAR);
LcdDelay(1200);
}
void LcdAddrReset(void) //address count 寄存器復位為0
{
LcdSMWrite1ByteInstruc(HOME);
}
void LcdAddrInc(void) //address count 每次遞增1,光標右移
{
LcdSMWrite1ByteInstruc(AC_INC);
}
void LcdAddrDec(void) //address count 每次遞減1,光標左移
{
LcdSMWrite1ByteInstruc(AC_DEC);
}
void LcdDisplayMode(unsigned int is_on) //LCD顯示模式:是否顯示,光標是否顯示與閃爍
{
LcdSMWrite1ByteInstruc(is_on);
}
void LcdCursorDisplayMode(unsigned int is_on) //?????????????????????????
{
LcdSMWrite1ByteInstruc(is_on);
}
void LcdFunSet(unsigned int mode) //設置是用基本還是擴展指令,是8bit還是4bit輸入
{
LcdSMWrite1ByteInstruc(mode);
}
void LcdCGRAMAddrSet(unsigned int address) //設置用戶自定義漢字數據地址
{
LcdSMWrite1ByteInstruc(CGRAM_ADDR+address);
}
void LcdDDRAMAddrSet(unsigned int address) //設置顯示數據的地址
{
LcdSMWrite1ByteInstruc(CGRAM_ADDR+address);
}
/*void IniLCD(void) //初始化LCD
{
LcdClearScreen();
}*/
//設置顯示開始的位置,共4行(1--4),8列(1--8),第一個參數為行數,第二個為列數。
void LcdSetDDRAMADDR(unsigned char row,unsigned char col)
{
switch(row)
{
case 1:LcdSMWrite1ByteInstruc(0x80+col-1);break;
case 2:LcdSMWrite1ByteInstruc(0x90+col-1);break;
case 3:LcdSMWrite1ByteInstruc(0x80+col+7);break;
case 4:LcdSMWrite1ByteInstruc(0x90+col+7);break;
default:break;
}
}
//在指定的位置顯示一行字符,超過一行的將截止(不顯示),
void LcdWriteOneLineString(unsigned char row,unsigned char col,unsigned char* p)
{
unsigned char i;
i=col+col;
LcdSetDDRAMADDR(row,col);
while((*p)&&i<18)
{
LcdSMWrite1ByteData(*p);
p++;
i++;
}
}
void LcdBasicFunctionSelect(void) //使用基本指令
{
LcdSMWrite1ByteInstruc(0x30);
}
void LcdExtendFunctionSelect(void) //使用擴展指令
{
LcdSMWrite1ByteInstruc(FUNCTION_SET+EIGHT_INTER+EX_INSTRUCTION);
}
void LcdReverse(unsigned char row) //隔行反顯,為0反顯1 3行,為1反顯2 4行
{
LcdSMWrite1ByteInstruc(0x04+row);
}
void LcdGraphicsDisplaySelect(void) //選擇顯示圖形
{
LcdSMWrite1ByteInstruc(0x36);
}
void LcdSetGDRAMADDR(unsigned char x,unsigned char y)//設置圖形顯示的地址
{
if(y<32)
{
LcdSMWrite1ByteInstruc(0x80+y);
LcdSMWrite1ByteInstruc(0x80+x);
}
else
{
LcdSMWrite1ByteInstruc(0x80+y-32);
LcdSMWrite1ByteInstruc(0x80+x+8);
}
}
void LcdWriteDataToGDRAM(unsigned char data) //向圖形顯示RAM區寫數據
{
LcdSMWrite1ByteData(data);
}
void LcdClearGDRAM(void) //清楚GDRAM內的內容
{
unsigned char x,y;
for(x=0;x<8;x++)
for(y=0;y<64;y++)
{
LcdSetGDRAMADDR( x, y);
LcdSMWrite1ByteData(0);
LcdSMWrite1ByteData(0);
}
}
void LcdDisplayOnePage(const unsigned char *p) //在圖形顯示模式下顯示一屏
{
int i,j=0;
for(i=0;i<64;i++)
{
for(j=0;j<8;j++)
{LcdSetGDRAMADDR(j,i);
LcdSMWrite1ByteData(*p++);
LcdSMWrite1ByteData(*p++);
}
j=0;
}
}
//在指定的位置顯示一個整數,超過一行的將截止(不顯示),
void LcdDisplayInteger(unsigned char row,unsigned char col,unsigned long value)
{
unsigned char number[11],temp[11];
unsigned j;
int i;
j=0;
for(i=0;i<11;i++)
{
temp[i]=value%10;
value=value/10;
if(value==0)
{
number[i+1]='\0';
for(j=0;i>-1;i--)
{
number[j++]=temp[i]+48;
}
i=100;
}
}
LcdWriteOneLineString( row, col,number);
}
void LcdWriteOneChar(unsigned char data)//在當前位置顯示一個字符
{
static unsigned char count=0;
switch(count)
{
case 0:LcdSetDDRAMADDR(1,1);break;
case 16:LcdSetDDRAMADDR(2,1);break;
case 32:LcdSetDDRAMADDR(3,1);break;
case 48:LcdSetDDRAMADDR(4,1);break;
default:break;
}
LcdSMWrite1ByteData(data);
count++;
if(count==64)
count=0;
}
void ShowMenu(BYTE max,BYTE *pt) //顯示下一級菜單
{
BYTE index=0;
LcdClearScreen();
for(;index<max;index++)
LcdWriteOneLineString(index+1,1,pt+index*17);
}
void MenuKeyProcess(BYTE key)//菜單按鍵處理函數
{
switch(key)
{
case 0x01:if((*nowmenupt).premenupt==NULL);
else
{ nowmenupt=(*nowmenupt).premenupt ;
ShowMenu((*nowmenupt).menusize,(*nowmenupt).menuconcentpt);
} break;
case 0x02:if(((*nowmenupt).nextmenupt[0]==NULL)&&((*nowmenupt).funpt[0]==NULL)) break;
else if((*nowmenupt).funpt[0]==NULL)
{
nowmenupt=(*nowmenupt).nextmenupt[0];
ShowMenu((*nowmenupt).menusize,(*nowmenupt).menuconcentpt);
}
else
(*nowmenupt).funpt[0]();
break;
case 0x04:if(((*nowmenupt).nextmenupt[1]==NULL)&&((*nowmenupt).funpt[1]==NULL)) break;
else if((*nowmenupt).funpt[1]==NULL)
{
nowmenupt=(*nowmenupt).nextmenupt[1];
ShowMenu((*nowmenupt).menusize,(*nowmenupt).menuconcentpt);
}
else
(*nowmenupt).funpt[1]();
break;
case 0x08:if(((*nowmenupt).nextmenupt[2]==NULL)&&((*nowmenupt).funpt[2]==NULL)) break;
else if((*nowmenupt).funpt[2]==NULL)
{
nowmenupt=(*nowmenupt).nextmenupt[2];
ShowMenu((*nowmenupt).menusize,(*nowmenupt).menuconcentpt);
}
else
(*nowmenupt).funpt[2]();
break;
case 0x10:if(((*nowmenupt).nextmenupt[3]==NULL)&&((*nowmenupt).funpt[3]==NULL)) break;
else if((*nowmenupt).funpt[3]==NULL)
{
nowmenupt=(*nowmenupt).nextmenupt[3];
ShowMenu((*nowmenupt).menusize,(*nowmenupt).menuconcentpt);
}
else
(*nowmenupt).funpt[3]();
break;
default:_NOP();
}
}
void InitLCD(void)//初始化液晶
{
P3DIR|=0x30; //P3.4 5口為輸出
MenuInit(); //初始發菜單
LcdBasicFunctionSelect();
LcdDisplayMode(DISPLAY_CTL+DISPLAY_ON);//
LcdAddrReset();
LcdClearScreen();
//ShowMenu((*nowmenupt).menusize,(*nowmenupt).menuconcentpt);
//LcdWriteOneLineString(1,1,"電子科技大學");
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -