欧美极品高清xxxxhd,国产日产欧美最新,无码AV国产东京热AV无码,国产精品人与动性XXX,国产传媒亚洲综合一区二区,四库影院永久国产精品,毛片免费免费高清视频,福利所导航夜趣136
標(biāo)題:
lcd12864按鍵測(cè)試單個(gè)菜單顯示 stc89c52rc單片機(jī)
[打印本頁(yè)]
作者:
朝朝1
時(shí)間:
2021-2-2 18:35
標(biāo)題:
lcd12864按鍵測(cè)試單個(gè)菜單顯示 stc89c52rc單片機(jī)
/*-----------------------------------------------
名稱:按鍵測(cè)試單個(gè)菜單顯示
編寫(xiě):shifang
修改:無(wú)
內(nèi)容:?jiǎn)蝹(gè)菜單,多頁(yè)顯示,不帶子菜單
------------------------------------------------*/
#include <reg52.h>
#include <intrins.h>
sbit RS = P1^0;
sbit RW = P1^1;
sbit E = P2^5;
sbit RES = P2^3;
sbit PSB = P1^3;
sbit PAUSE = P3^0;
sbit beep=P2^3;
#define DataPort P0 //單片機(jī) P0<------> 液晶DB0-DB7
sbit KEY_ADD=P3^4; //定義按鍵輸入端口
sbit KEY_DEC=P3^5;
sbit k3=P3^6;
unsigned char curr,currold;//全局變量,當(dāng)前箭頭位置
unsigned char code user16x16[]={ //箭頭圖片
0x00,0x00,0x20,0x00,0x30,0x00,0x38,0x00,0x3C,0x00,0x3E,0x00,0x3F,0x00,0x3F,0x80,
0x3F,0xC0,0x3F,0x80,0x3F,0x00,0x3E,0x00,0x3C,0x00,0x38,0x00,0x30,0x00,0x20,0x00,
};
unsigned char code *MainMenu[]=
{
{" 1.蜂鳴器響"},
{" 2.蜂鳴器滅"},
{" 3.蜂鳴器亮"},
{" 4.蜂鳴器滅"},
{" 5.蜂鳴器亮"},
{" 6.蜂鳴器滅"},
};
/*------------------------------------------------
檢測(cè)忙位
------------------------------------------------*/
void DelayUs2x(unsigned char t)
{
while(--t);
}
/*------------------------------------------------
mS延時(shí)函數(shù),含有輸入?yún)?shù) unsigned char t,無(wú)返回值
unsigned char 是定義無(wú)符號(hào)字符變量,其值的范圍是
0~255 這里使用晶振12M,精確延時(shí)請(qǐng)使用匯編
------------------------------------------------*/
void DelayMs(unsigned char t)
{
while(t--)
{
//大致延時(shí)1mS
DelayUs2x(245);
DelayUs2x(245);
}
}
void Check_Busy()
{
RS=0;
RW=1;
E=1;
DataPort=0xff;
while((DataPort&0x80)==0x80);//忙則等待
E=0;
}
/*------------------------------------------------
寫(xiě)命令
------------------------------------------------*/
void Write_Cmd(unsigned char Cmd)
{
Check_Busy();
RS=0;
RW=0;
E=1;
DataPort=Cmd;
DelayUs2x(5);
E=0;
DelayUs2x(5);
}
/*------------------------------------------------
寫(xiě)數(shù)據(jù)
------------------------------------------------*/
void Write_Data(unsigned char Data)
{
Check_Busy();
RS=1;
RW=0;
E=1;
DataPort=Data;
DelayUs2x(5);
E=0;
DelayUs2x(5);
}
/*------------------------------------------------
液晶屏初始化
------------------------------------------------*/
void Init_ST7920()
{
DelayMs(40); //大于40MS的延時(shí)程序
PSB=1; //設(shè)置為8BIT并口工作模式
DelayMs(1); //延時(shí)
RES=0; //復(fù)位
DelayMs(1); //延時(shí)
RES=1; //復(fù)位置高
DelayMs(10);
Write_Cmd(0x30); //選擇基本指令集
DelayUs2x(50); //延時(shí)大于100us
Write_Cmd(0x30); //選擇8bit數(shù)據(jù)流
DelayUs2x(20); //延時(shí)大于37us
Write_Cmd(0x0c); //開(kāi)顯示(無(wú)游標(biāo)、不反白)
DelayUs2x(50); //延時(shí)大于100us
Write_Cmd(0x01); //清除顯示,并且設(shè)定地址指針為00H
DelayMs(15); //延時(shí)大于10ms
Write_Cmd(0x06); //指定在資料的讀取及寫(xiě)入時(shí),設(shè)定游標(biāo)的移動(dòng)方向及指定顯示的移位,光標(biāo)從右向左加1位移動(dòng)
DelayUs2x(50); //延時(shí)大于100us
}
/*------------------------------------------------
用戶自定義字符
------------------------------------------------*/
void CGRAM()
{
int i;
Write_Cmd(0x30);
Write_Cmd(0x40);
for(i=0;i<16;i++)
{
Write_Data(user16x16[i*2]);
Write_Data(user16x16[i*2+1]);
}
}
/*------------------------------------------------
顯示用戶自定義字符
------------------------------------------------*/
void DisplayCGRAM(unsigned char x,unsigned char y)
{
switch(y)
{
case 1: Write_Cmd(0x80+x);break;
case 2: Write_Cmd(0x90+x);break;
case 3: Write_Cmd(0x88+x);break;
case 4: Write_Cmd(0x98+x);break;
default:break;
}
Write_Data(00);
Write_Data(00);
}
/*------------------------------------------------
顯示字符串
x:橫坐標(biāo)值,范圍0~8
y:縱坐標(biāo)值,范圍1~4
------------------------------------------------*/
void LCD_PutString(unsigned char x,unsigned char y,unsigned char code *s)
{
switch(y)
{
case 1: Write_Cmd(0x80+x);break;
case 2: Write_Cmd(0x90+x);break;
case 3: Write_Cmd(0x88+x);break;
case 4: Write_Cmd(0x98+x);break;
default:break;
}
while(*s>0)
{
Write_Data(*s);
s++;
DelayUs2x(50);
}
}
/*------------------------------------------------
清屏
------------------------------------------------*/
void ClrScreen()
{
Write_Cmd(0x01);
DelayMs(15);
}
/*------------------------------------------------
顯示圖片
------------------------------------------------*/
/*void LCD_PutGraphic(unsigned char code *img)
{
int i,j;
//顯示上半屏內(nèi)容設(shè)置
for(i=0;i<32;i++)
{
Write_Cmd(0x80 + i); //SET 垂直地址 VERTICAL ADD
Write_Cmd(0x80); //SET 水平地址 HORIZONTAL ADD
for(j=0;j<16;j++)
{
Write_Data(*img);
img++;
}
}
//顯示下半屏內(nèi)容設(shè)置
for(i=0;i<32;i++)
{
Write_Cmd(0x80 + i); //SET 垂直地址 VERTICAL ADD
Write_Cmd(0x88); //SET 水平地址 HORIZONTAL ADD
for(j=0;j<16;j++)
{
Write_Data(*img);
img++;
}
}
}*/
/*------------------------------------------------
設(shè)置到繪圖模式
------------------------------------------------*/
/*void SetGraphicMode()
{
Write_Cmd(0x36); //選擇8bit數(shù)據(jù)流 圖形模式
DelayUs2x(20);
}*/
/*------------------------------------------------
調(diào)用顯示更新
------------------------------------------------*/
void DisplayUpdata(void)
{
unsigned char num;
ClrScreen();
num=sizeof(MainMenu)/sizeof(MainMenu[0]);//判斷數(shù)組中數(shù)值個(gè)數(shù)
if((0+(curr/4)*4)<num)
LCD_PutString(0,1,MainMenu[0+(curr/4)*4]);
else //如果超出數(shù)組最大元素,則寫(xiě)空信息,不判斷此信息可能會(huì)出現(xiàn)亂碼
LCD_PutString(0,1,"");
if((1+(curr/4)*4)<num)
LCD_PutString(0,2,MainMenu[1+(curr/4)*4]);
else
LCD_PutString(0,2,"");
if((2+(curr/4)*4)<num)
LCD_PutString(0,3,MainMenu[2+(curr/4)*4]);
else
LCD_PutString(0,3,"");
if((3+(curr/4)*4)<num)
LCD_PutString(0,4,MainMenu[3+(curr/4)*4]);
else
LCD_PutString(0,4,"");
DisplayCGRAM(0,curr%4+1);
}
/*------------------------------------------------
主程序
------------------------------------------------*/
main()
{
Init_ST7920(); //初始化
CGRAM(); //寫(xiě)入自定義字符
DisplayUpdata();
while(1)
{
// beep=0;
if(curr!=currold) //光標(biāo)位置變化,則更新顯示
{
DisplayUpdata();
currold=curr;
}
if(!KEY_ADD) //如果檢測(cè)到低電平,說(shuō)明按鍵按下
{
DelayMs(10); //延時(shí)去抖,一般10-20ms
if(!KEY_ADD) //再次確認(rèn)按鍵是否按下,沒(méi)有按下則退出
{
while(!KEY_ADD);//如果確認(rèn)按下按鍵等待按鍵釋放,沒(méi)有釋放則一直等待
{
if(curr<sizeof(MainMenu)/sizeof(MainMenu[0])-1)//判斷數(shù)組中數(shù)值個(gè)數(shù)
{
curr++;
}
}
}
}
if(!KEY_DEC) //如果檢測(cè)到低電平,說(shuō)明按鍵按下
{
DelayMs(10); //延時(shí)去抖,一般10-20ms
if(!KEY_DEC) //再次確認(rèn)按鍵是否按下,沒(méi)有按下則退出
{
while(!KEY_DEC);//如果確認(rèn)按下按鍵等待按鍵釋放,沒(méi)有釋放則一直等待
{
if(curr>0)
{
curr--;
}
}
}
}
if(k3==0)
{
switch(curr)
{
case 0: beep=0; break;
case 1: beep=1; break;
case 2: beep=0; break;
case 3: beep=1; break;
case 4: beep=0; break;
case 5: beep=1; break;
}
}
}
}
歡迎光臨 (http://www.raoushi.com/bbs/)
Powered by Discuz! X3.1