📄 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 + -