|
通過(guò)移植51單片機(jī)的菜單顯示程序,成功顯示并增加反白滾動(dòng) 菜單
單片機(jī)源程序如下:
- #include"stm8s.h"
- #include"stm8s_gpio.h"
- #include"Cry12864.h"
- uchar curr=1,currold;
- uchar curr_flag,currold_flag;
- uchar curr_flag1,currold_flag1;
- uchar curr_flag2,currold_flag2;
- uchar flag,flag1,flag2;
- uchar 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 *MainMenu[]=
- {
- {" 功能菜單"},
- {"登錄系統(tǒng)"},
- {"電壓顯示一"},
- {"電壓顯示二"},
- };
- unsigned char *MainMenu1[]=
- {
- {" 電流顯示一"},
- {"電流顯示二"},
- {"制作萬(wàn)年歷"},
- {"溫度傳感器"},
- {" QQ音樂(lè)"},
- {"我的圖片"},
- {"本地音樂(lè)"},
- {"更多應(yīng)用"},
- };
- unsigned char *MainMenu2[8]=
- {
- {" 全民清賬"},
- {"CF"},
- {"飛機(jī)"},
- {"王者榮耀"},
- {" 超級(jí)瑪麗"},
- {"魂斗羅"},
- {"非常英雄"},
- {"下一頁(yè)"},
- };
- unsigned char *MainMenu3[]=
- {
- {" 幻月后續(xù)"},
- {"能否敵發(fā)送"},
- {"測(cè)試的個(gè)i哦"},
- {"飯店附近"},
- {"大幅度"},
- {"放大發(fā)送單個(gè)"},
- {"地方"},
- {"放大上輸給"},
- };
- extern const unsigned char shuzi_table[];
- #define LCD_RS_H GPIOG->ODR|=0x01 //PD6拉高
- #define LCD_RS_L GPIOG->ODR&=~0x01 //PD6拉低
- #define LCD_RW_H GPIOG->ODR|=0x02 //PD7拉高
- #define LCD_RW_L GPIOG->ODR&=~0x02 //PD7拉低
- #define LCD_EN_H GPIOG->ODR|=0x04 //PD5拉高
- #define LCD_EN_L GPIOG->ODR&=~0x04 //PD5拉低
- #define LCD_PSB_H GPIOG->ODR|=0x08 //PD0拉高
- #define LCD_CSB_L GPIOG->ODR&=~0x08 //PD0拉低
- /*******************************************
- 函數(shù)名稱(chēng):Delay_1ms
- 功 能:延時(shí)約1ms的時(shí)間
- 參 數(shù):無(wú)
- 返回值 :無(wú)
- ********************************************/
- void Delay_1ms(void)
- {
- uint i,j;
-
- for(i = 16;i > 0;i--)
- for(j=10;j>0;j--);
-
- }
- /*******************************************
- 函數(shù)名稱(chēng):Delay_Nms
- 功 能:延時(shí)N個(gè)1ms的時(shí)間
- 參 數(shù):n--延時(shí)長(zhǎng)度
- 返回值 :無(wú)
- ********************************************/
- void Delay_Nms(uint n)
- {
- uint k;
-
- for(k = n;k > 0;k--) Delay_1ms();
- }
- void Io_Config(void)
- { GPIOB->DDR|=0xff; //PB端口設(shè)置為輸出
- GPIOB->CR1|=0xff;//推免模式
- GPIOB->CR2&=~0xff;//低速模式
- GPIOG->DDR|=0xff; //PA端口設(shè)置為輸出
- GPIOG->CR1|=0xff;//推免模式
- GPIOG->CR2&=~0xff;//低速模式*/
- }
- //讀狀態(tài),檢測(cè)忙
- void check_busy(void)
- {uchar busy;
- do
- { LCD_RS_L;
- LCD_RW_H;
- LCD_EN_L;
- Delay_1ms();
- LCD_EN_H;
- busy=GPIOB->IDR;
- Delay_1ms();
- LCD_EN_L;
- }
- while(busy&0x80);
- }
- /*******************************************
- 函數(shù)名稱(chēng):Write_Cmd
- 功 能:向液晶中寫(xiě)控制命令
- 參 數(shù):cmd--控制命令
- 返回值 :無(wú)
- ********************************************/
- void Write_Cmd(uchar cmd)
- {
- // check_busy();
- LCD_RW_L;
- LCD_RS_L;
- Delay_1ms();
- GPIOB->ODR&=0x00;
- GPIOB->ODR|=cmd;
- LCD_EN_H;
- Delay_1ms();
- LCD_EN_L;
- Delay_1ms();
-
-
-
- }
- /*******************************************
- 函數(shù)名稱(chēng):Write_Data
- 功 能:向液晶中寫(xiě)顯示數(shù)據(jù)
- 參 數(shù):dat--顯示數(shù)據(jù)
- 返回值 :無(wú)
- ********************************************/
- void Write_Data(uchar dat)
- { // check_busy();
- LCD_RW_L;
- LCD_RS_H;
- Delay_1ms();
- GPIOB->ODR&=0x00;
- GPIOB->ODR|=dat;
- LCD_EN_H;
- Delay_1ms();
- LCD_EN_L;
- Delay_1ms();
- }
- /*******************************************
- 函數(shù)名稱(chēng):Ini_Lcd
- 功 能:初始化液晶模塊
- 參 數(shù):無(wú)
- 返回值 :無(wú)
- ********************************************/
- void Ini_Lcd(void)
- { Io_Config();
- LCD_PSB_H;
- Delay_Nms(100);
- Write_Cmd(0x30); //基本指令集
- Delay_Nms(10);
- Write_Cmd(0x02); // 地址歸位
- Delay_Nms(10);
- Write_Cmd(0x0c); //整體顯示打開(kāi),游標(biāo)關(guān)閉
- Delay_Nms(10);
- Write_Cmd(0x01); //清除顯示
- Delay_Nms(10);
- Write_Cmd(0x06); //游標(biāo)右移
- Delay_Nms(10);
- Write_Cmd(0x80); //設(shè)定顯示的起始地址
- }
- /*******************************************
- 函數(shù)名稱(chēng):Clear_GDRAM
- 功 能:清除液晶GDRAM中的隨機(jī)數(shù)據(jù)
- 參 數(shù):無(wú)
- 返回值 :無(wú)
- ********************************************/
- void Clear_GDRAM(void)
- {
- /* uchar i,j,k;
-
- Write_Cmd(0x34); //打開(kāi)擴(kuò)展指令集
- i = 0x80;
- for(j = 0;j < 32;j++)
- {
- Write_Cmd(i++);
- Write_Cmd(0x80);
- for(k = 0;k < 16;k++)
- {
- Write_Data(0x00);
- }
- }
- i = 0x80;
- for(j = 0;j < 32;j++)
- {
- Write_Cmd(i++);
- Write_Cmd(0x88);
- for(k = 0;k < 16;k++)
- {
- Write_Data(0x00);
- }
- }
-
- Write_Cmd(0x30); //回到基本指令集
- */
- Write_Cmd(0x01);
- Delay_Nms(15);
-
- }
- /*******************************************
- 函數(shù)名稱(chēng):Draw_PM
- 功 能:在整個(gè)液晶屏幕上畫(huà)圖
- 參 數(shù):無(wú)
- 返回值 :無(wú)
- ********************************************/
- void Draw_PM(const uchar *ptr)
- {
- uchar i,j,k;
-
- Write_Cmd(0x34); //打開(kāi)擴(kuò)展指令集
- i = 0x80;
- for(j = 0;j < 32;j++)
- {
- Write_Cmd(i++);
- Write_Cmd(0x80);
- for(k = 0;k < 16;k++)
- {
- Write_Data(*ptr++);
- }
- }
- i = 0x80;
- for(j = 0;j < 32;j++)
- {
- Write_Cmd(i++);
- Write_Cmd(0x88);
- for(k = 0;k < 16;k++)
- {
- Write_Data(*ptr++);
- }
- }
- Write_Cmd(0x36); //打開(kāi)繪圖顯示
- Write_Cmd(0x30); //回到基本指令集
- }
- /*********************************************************/
- /* */
- /* 設(shè)定顯示位置 */
- /* */
- /*********************************************************/
- void lcd_pos(uchar X,uchar Y)
- {
- uchar pos;
- if (X==0)
- {X=0x80;}
- else if (X==1)
- {X=0x90;}
- else if (X==2)
- {X=0x88;}
- else if (X==3)
- {X=0x98;}
- pos = X+Y ;
- Write_Cmd(pos); //顯示地址
- }
- /*******************************************
- 函數(shù)名稱(chēng):Disp1Char
- 功 能:在某個(gè)位置顯示一個(gè)字符
- 參 數(shù):x--位置的列坐標(biāo)
- y--位置的行坐標(biāo)
- data--顯示的字符數(shù)據(jù)
- 返回值 :無(wú)
- ********************************************/
- void Disp1Char(uchar x,uchar y,uchar data)
- {
- lcd_pos( x, y );
- Write_Data( data );
- }
- /*******************************************
- 函數(shù)名稱(chēng):DispNchar
- 功 能:讓液晶從某個(gè)位置起連續(xù)顯示N個(gè)字符
- 參 數(shù):x--位置的列坐標(biāo)
- y--位置的行坐標(biāo)
- n--字符個(gè)數(shù)
- ptr--指向字符存放位置的指針
- 返回值 :無(wú)
- ********************************************/
- void DispNChar(uchar x,uchar y, uchar n,uchar *ptr)
- {
- uchar i;
-
- for (i=0;i<n;i++)
- {
- Disp1Char(x++,y,ptr[i]);
- if (x == 0x0f)
- {
- x = 0;
- y ^= 1;
- }
- }
- }
- /*******************************************
- 函數(shù)名稱(chēng):DispString
- 功 能:讓液晶從某個(gè)位置起連續(xù)顯示N個(gè)字符
- 參 數(shù):x--位置的列坐標(biāo)
- y--位置的行坐標(biāo)
- n--字符個(gè)數(shù)
- ptr--指向字符存放位置的指針
- 返回值 :無(wú)
- ********************************************/
- void DispString(uchar x,uchar y,uchar *ptr)
- {
- uchar i = 0;
- lcd_pos( x, y );
- while(ptr[i] != '\0')
- { //顯示字符
-
- Write_Data(ptr[i]);
- i++;
- }
- }
- /*******************************************
- 函數(shù)名稱(chēng):Draw_TX
- 功 能:顯示一個(gè)16*16大小的圖形
- 參 數(shù):Yaddr--Y地址
- Xaddr--X地址
- dp--指向圖形數(shù)據(jù)存放地址的指針
- 返回值 :無(wú)
- ********************************************/
- void Draw_TX(uchar Yaddr,uchar Xaddr,const uchar * dp)
- {
- uchar j;
- uchar k=0;
-
- // Write_Cmd(0x01); //清屏,只能清除DDRAM
- Write_Cmd(0x34); //使用擴(kuò)展指令集,關(guān)閉繪圖顯示
- for(j=0;j<16;j++)
- {
- Write_Cmd(Yaddr++); //Y地址
- Write_Cmd(Xaddr); //X地址
- Write_Data(dp[k++]);
- Write_Data(dp[k++]);
- }
- Write_Cmd(0x36); //打開(kāi)繪圖顯示
- // Write_Cmd(0x30); //回到基本指令集模式
- }
- /***********************************************
- 寫(xiě)入用戶(hù)自定義函數(shù)
- ***********************************************/
- void CGRAM()
- {
- int i;
- Write_Cmd(0x30);
- Write_Cmd(0x40); //對(duì)CGRAM第一個(gè)自定義符操作
- for(i=0;i<16;i++)
- {
- Write_Data(user16x16[i*2]);
- Write_Data(user16x16[i*2+1]);
- }
- }
- /***********************************************
- 顯示用戶(hù)自定義字符
- ***********************************************/
- 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); //é???óDò???×?·?2ù×÷0x04á? ?ùò??±?óD′
- Write_Data(00); //D′×?·? Write_Data(user16x16[i*2]);
- // Write_Data(user16x16[i*2+1]);
- }
- /*************************************************************
- //為反白做準(zhǔn)備,目地是在圖形顯示時(shí)防止有噪點(diǎn)
- *************************************************************/
- void display() //為反白做準(zhǔn)備,目地是在圖形顯示時(shí)防止有噪點(diǎn)
- {
- uchar i,j;
- Write_Cmd(0x34); //寫(xiě)數(shù)據(jù)時(shí),關(guān)閉圖形顯示
- for(i=0;i<32;i++)
- {
- Write_Cmd(0x80+i); //先寫(xiě)入水平坐標(biāo)值
- Write_Cmd(0x80); //寫(xiě)入垂直坐標(biāo)值
- for(j=0;j<16;j++) //再寫(xiě)入兩個(gè)8位元的數(shù)據(jù)
- Write_Data(0x00);
- Delay_Nms(1);
- }
- for(i=0;i<32;i++)
- {
- Write_Cmd(0x80+i);
- Write_Cmd(0x88);
- for(j=0;j<16;j++)
- Write_Data(0x00);
- Delay_Nms(1);
- }
- Write_Cmd(0x36);//寫(xiě)完數(shù)據(jù),開(kāi)圖形顯示
- }
- /*******************************************************
- 反白函數(shù)
- *********************************************************/
- void photodisplay(uchar x,uchar y,uchar width) //反白,X值為0-7,Y值為0-3,width為行反白格數(shù)
- {
- uchar i,j,flag=0x00;
- display();
- if(y>1)
- {
- flag=0x08;
- y=y-2;
- }
- Write_Cmd(0x34); //寫(xiě)數(shù)據(jù)時(shí),關(guān)閉圖形顯示,且打開(kāi)擴(kuò)展指令集
- ……………………
- …………限于本文篇幅 余下代碼請(qǐng)從51黑下載附件…………
復(fù)制代碼
所有資料51hei提供下載:
12864菜單程序.rar
(1 MB, 下載次數(shù): 61)
2017-12-4 20:41 上傳
點(diǎn)擊文件名下載附件
|
|