/* MAIN.C file
*
* Copyright (c) 2002-2005 STMicroelectronics
*/
#include "stm8s105k4.h"
#define u8 unsigned char
#define u16 unsigned short
#define u32 unsigned long
#define uint unsigned int
/*--------------------引腳定義--------------------------*/
#define OLED_SCLK_Set() (PB_ODR |= 0x01) //PB0(SCL)輸出高
#define OLED_SCLK_Clr() (PB_ODR &= 0xfe) //PB0(SCL)輸出低
#define OLED_SDIN_Set() (PB_ODR |= 0x02) //PB1(SDA)輸出高
#define OLED_SDIN_Clr() (PB_ODR &= 0xfd) //PB1(SDA)輸出高
#define OLED_READ_SDIN() (PB_IDR & 0x02) //讀取PB4(SDA)電平
//#define OLED_KEY1() (PD_IDR
/*definition--------------------------------------------*/
#define OLED_CMD 0 //寫命令
#define OLED_DATA 1 //寫數據
#define SIZE 16 //顯示字符的大小
#define Max_Column 128 //最大列數
#define Max_Row 64 //最大行數
#define X_WIDTH 128 //X軸的寬度
#define Y_WIDTH 64 //Y軸的寬度
#define IIC_ACK 0 //應答
#define IIC_NO_ACK 1 //不應答
void OLED_GPIO_Init(void);
void delay (u8 num);
void delay_ms(uint ms);
void OLED_IIC_Start(void);
void OLED_IIC_Stop(void);
u8 IIC_Wait_Ack(void);
void Write_IIC_Byte(u8 IIC_Byte);
void Write_IIC_Command(u8 IIC_Command);
void Write_IIC_Data(u8 IIC_Data);
uint OLED_Pow(u8 m,u8 n);
void OLED_WR_Byte(u8 dat,u8 cmd); //OLED寫字節函數
void OLED_Display_On(void); //開顯示函數
void OLED_Display_Off(void);//關顯示函數
void OLED_Init(void); //OLED初始化函數
void OLED_Clear(void); //清屏函數
void OLED_ShowChar(u8 x,u8 y,u8 chr); //顯示字符函數
void OLED_ShowNum(u8 x,u8 y,uint num,u8 len,u8 size2); //在指定的位置,顯示一個指定數的長度大小函數
void OLED_ShowString(u8 x,u8 y, u8 *chr); //在指定位置開始顯示字符串函數
void OLED_Set_Pos(u8 x, u8 y); //畫點函數
void OLED_ShowChinese(u8 x,u8 y,u8 no); //聲明在指定位置顯示漢字函數
void OLED_DrawBMP(u8 x0, u8 y0,u8 x1, u8 y1,u8 BMP[]); //顯示圖片函數
void OLED_Scroll(void);//滾動函數
void OLED_menu(u8 cur);
void key_Init(void);
u8 key1_scan(void);
u8 key2_scan(void);
void KeyPressed(u8 cur);
u8 key_scan(void);
const u8 table[]={2,4,6};
const u8 F6x8[][6];
const u8 F8X16[];
const u8 Hzk[][16];
//const u8 BMP1[];
main()
{
CLK_CKDIVR = 0x00;//f_HSI = f_HSI RC 輸出 f_CPU = f_MASTER 16M
OLED_Init();//OLED初始化
key_Init();
KeyPressed(1);
while (1);
}
void delay(u8 num)
{
while(num--);
}
void delay_ms(uint ms)//延遲函數,MS級別
{
uint x,y;
for(x = ms;x>0;x--)
{
for(y = 1300;y>0;y--);
}
}
void OLED_GPIO_Init(void)
{
PB_DDR |= 0x03; //將 PB0 PB1 口設為輸出
PB_CR1 &= 0xfc; //將 PB0 PB1 口設為開漏
PB_CR2 &= 0xfc;//將 PB0 PB1 口設為開漏
OLED_SCLK_Set(); //將PB4(SCL)設為高
OLED_SDIN_Set(); //將PB5(SDA)設為高
}
void OLED_IIC_Start(void)
{
OLED_SCLK_Set(); //時鐘線置高
OLED_SDIN_Set(); //信號線置高
delay(1); //延遲1us
OLED_SDIN_Clr(); //信號線置低
delay(1); //延遲1us
OLED_SCLK_Clr(); //時鐘線置低
delay(1); //延遲1us
}
void OLED_IIC_Stop(void)
{
OLED_SDIN_Clr(); //信號線置低
delay(1); //延遲1us
OLED_SCLK_Set(); //時鐘線置高
delay(1); //延遲1us
OLED_SDIN_Set(); //信號線置高
delay(1); //延遲1us
}
u8 IIC_Wait_Ack(void)
{
u8 ack;
OLED_SCLK_Clr(); //時鐘線置低
delay(1); //延遲1us
OLED_SDIN_Set(); //信號線置高
delay(1); //延遲1us
OLED_SCLK_Set(); //時鐘線置高
delay(1); //延遲1us
if(OLED_READ_SDIN()) //讀取SDA的電平
ack = IIC_NO_ACK; //如果為1,則從機沒有應答
else
ack = IIC_ACK; //如果為0,則從機應答
OLED_SCLK_Clr();//時鐘線置低
delay(1); //延遲1us
return ack; //返回讀取到的應答信息
}
void Write_IIC_Byte(u8 IIC_Byte)
{
u8 i; //定義變量
for(i=0;i<8;i++) //for循環8次
{
OLED_SCLK_Clr(); //時鐘線置低,為傳輸數據做準備
delay(1); //延遲1us
if(IIC_Byte & 0x80) //讀取最高位
OLED_SDIN_Set(); //最高位為1
else
OLED_SDIN_Clr(); //最高位為0
IIC_Byte <<= 1; //數據左移1位
delay(1); //延遲1us
OLED_SCLK_Set(); //時鐘線置高,產生上升沿,把數據發送出去
delay(1); //延遲1us
}
OLED_SCLK_Clr(); //時鐘線置低
delay(1); //延遲1us
while(IIC_Wait_Ack()); //從機應答
}
void Write_IIC_Command(u8 IIC_Command)
{
OLED_IIC_Start();
Write_IIC_Byte(0x78);//寫入從機地址,SD0 = 0
Write_IIC_Byte(0x00);//寫入命令
Write_IIC_Byte(IIC_Command);//數據
OLED_IIC_Stop(); //發送停止信號
}
void Write_IIC_Data(u8 IIC_Data)
{
OLED_IIC_Start();
Write_IIC_Byte(0x78); //寫入從機地址,SD0 = 0
Write_IIC_Byte(0x40); //寫入數據
Write_IIC_Byte(IIC_Data);//數據
OLED_IIC_Stop(); //發送停止信號
}
void OLED_WR_Byte(u8 dat,u8 cmd)
{
if(cmd)
{
Write_IIC_Data(dat); //寫入數據
}
else {
Write_IIC_Command(dat); //寫入命令
}
}
void OLED_Set_Pos(u8 x,u8 y)
{
OLED_WR_Byte(0xb0+y,OLED_CMD);//寫入頁地址
OLED_WR_Byte((x&0x0f),OLED_CMD); //寫入列的地址 低半字節
OLED_WR_Byte(((x&0xf0)>>4)|0x10,OLED_CMD);//寫入列的地址 高半字節
}
void OLED_Display_On(void)
{
OLED_WR_Byte(0X8D,OLED_CMD); //設置OLED電荷泵
OLED_WR_Byte(0X14,OLED_CMD); //使能,開
OLED_WR_Byte(0XAF,OLED_CMD); //開顯示
}
void OLED_Display_Off(void)
{
OLED_WR_Byte(0XAE,OLED_CMD); //關顯示
OLED_WR_Byte(0X8D,OLED_CMD); //設置OLED電荷泵
OLED_WR_Byte(0X10,OLED_CMD); //失能,關
}
void OLED_Clear(void)
{
u8 i,n; //定義變量
for(i=0;i<8;i++)
{
OLED_WR_Byte (0xb0+i,OLED_CMD); //從0~7頁依次寫入
OLED_WR_Byte (0x00,OLED_CMD); //列低地址
OLED_WR_Byte (0x10,OLED_CMD); //列高地址
for(n=0;n<128;n++)OLED_WR_Byte(0,OLED_DATA); //寫入 0 清屏
}
}
void OLED_ShowChar(u8 x,u8 y,u8 chr)
{
u8 c=0,i=0;
c=chr-' '; //獲取字符的偏移量
if(x>Max_Column-1){x=0;y=y+2;} //如果列數超出了范圍,就從下2頁的第0列開始
if(SIZE ==16) //字符大小如果為 16 = 8*16
{
OLED_Set_Pos(x,y); //從x y 開始畫點
for(i=0;i<8;i++) //循環8次 占8列
OLED_WR_Byte(F8X16[c*16+i],OLED_DATA); //找出字符 c 的數組位置,先在第一頁把列畫完
OLED_Set_Pos(x,y+1); //頁數加1
for(i=0;i<8;i++) //循環8次
OLED_WR_Byte(F8X16[c*16+i+8],OLED_DATA); //把第二頁的列數畫完
}
else //字符大小為 6 = 6*8
{
OLED_Set_Pos(x,y+1); //一頁就可以畫完
for(i=0;i<6;i++) //循環6次 ,占6列
OLED_WR_Byte(F6x8[c][i],OLED_DATA); //把字符畫完
}
}
uint OLED_Pow(u8 m,u8 n)
{
uint result=1;
while(n--)result*=m;
return result;
}
void OLED_ShowNum(u8 x,u8 y,uint num,u8 len,u8 size)
{
u8 t,temp; //定義變量
u8 enshow=0; //定義變量
for(t=0;t<len;t++)
{
temp=(num/OLED_Pow(10,len-t-1))%10;//取出輸入數的每個位,由高到低
if(enshow==0&&t<(len-1)) //enshow:是否為第一個數;t<(len-1):判斷是否為最后一個數
{
if(temp==0) //如果該數為0
{
OLED_ShowChar(x+(size/2)*t,y,' ');//顯示 0 ;x+(size2/2)*t根據字體大小偏移的列數(8)
continue; //跳過剩下語句,繼續重復循環(避免重復顯示)
}else enshow=1;
}
OLED_ShowChar(x+(size/2)*t,y,temp+'0'); //顯示一個位;x+(size2/2)*t根據字體大小偏移的列數(8)
}
}
void OLED_ShowString(u8 x,u8 y,u8 *chr)
{
u8 j=0; //定義變量
while (chr[j]!='\0') //如果不是最后一個字符
{
OLED_ShowChar(x,y,chr[j]); //顯示字符
x+=8; //列數加8 ,一個字符的列數占8
if(x>=128){x=0;y+=2;} //如果x大于等于128,切換頁,從該頁的第一列顯示
j++; //下一個字符
}
}
void OLED_ShowChinese(u8 x,u8 y,u8 no)
{
u8 t; //定義變量
OLED_Set_Pos(x,y); //從 x y 開始畫點,先畫第一頁
for(t=0;t<16;t++) //循環16次,畫第一頁的16列
{
OLED_WR_Byte(Hzk[no*2][t],OLED_DATA);//畫no在數組位2*no
}
OLED_Set_Pos(x,y+1); //畫第二頁
for(t=0;t<16;t++)//循環16次,畫第二頁的16列
{
OLED_WR_Byte(Hzk[2*no+1][t],OLED_DATA);//畫no在數組位置的第二頁16列的點
}
}
void OLED_DrawBMP(u8 x0, u8 y0,u8 x1, u8 y1,u8 BMP[])
{
uint j=0; //定義變量
u8 x,y; //定義變量
if(y1%8==0) y=y1/8; //判斷終止頁是否為8的整數倍
else y=y1/8+1;
for(y=y0;y<y1;y++) //從起始頁開始,畫到終止頁
{
OLED_Set_Pos(x0,y); //在頁的起始列開始畫
for(x=x0;x<x1;x++) //畫x1 - x0 列
{
OLED_WR_Byte(BMP[j++],OLED_DATA); //畫圖片的點
}
}
}
void OLED_Init(void)
{
OLED_GPIO_Init(); //GPIO口初始化
delay_ms(200); //延遲,由于單片機上電初始化比OLED快,所以必須加上延遲,等待OLED上復位完成
OLED_WR_Byte(0xAE,OLED_CMD); //關閉顯示
OLED_WR_Byte(0x00,OLED_CMD); //設置低列地址
OLED_WR_Byte(0x10,OLED_CMD); //設置高列地址
OLED_WR_Byte(0x40,OLED_CMD); //設置起始行地址
OLED_WR_Byte(0xB0,OLED_CMD); //設置頁地址
OLED_WR_Byte(0x81,OLED_CMD); // 對比度設置,可設置亮度
OLED_WR_Byte(0xFF,OLED_CMD); // 265
OLED_WR_Byte(0xA1,OLED_CMD); //設置段(SEG)的起始映射地址;column的127地址是SEG0的地址
OLED_WR_Byte(0xA6,OLED_CMD); //正常顯示;0xa7逆顯示
OLED_WR_Byte(0xA8,OLED_CMD); //設置驅動路數(16~64)
OLED_WR_Byte(0x3F,OLED_CMD); //64duty
OLED_WR_Byte(0xC8,OLED_CMD); //重映射模式,COM[N-1]~COM0掃描
OLED_WR_Byte(0xD3,OLED_CMD); //設置顯示偏移
OLED_WR_Byte(0x00,OLED_CMD); //無偏移
OLED_WR_Byte(0xD5,OLED_CMD); //設置震蕩器分頻
OLED_WR_Byte(0x80,OLED_CMD); //使用默認值
OLED_WR_Byte(0xD9,OLED_CMD); //設置 Pre-Charge Period
OLED_WR_Byte(0xF1,OLED_CMD); //使用官方推薦值
OLED_WR_Byte(0xDA,OLED_CMD); //設置 com pin configuartion
OLED_WR_Byte(0x12,OLED_CMD); //使用默認值
OLED_WR_Byte(0xDB,OLED_CMD); //設置 Vcomh,可調節亮度(默認)
OLED_WR_Byte(0x40,OLED_CMD); ////使用官方推薦值
OLED_WR_Byte(0x8D,OLED_CMD); //設置OLED電荷泵
OLED_WR_Byte(0x14,OLED_CMD); //開顯示
OLED_WR_Byte(0xAF,OLED_CMD); //開啟OLED面板顯示
OLED_Clear(); //清屏
OLED_Set_Pos(0,0); //設置數據寫入的起始行、列
}
void OLED_Scroll(void)
{
OLED_WR_Byte(0x2E,OLED_CMD); //關閉滾動
OLED_WR_Byte(0x27,OLED_CMD); //水平向左滾動
OLED_WR_Byte(0x00,OLED_CMD); //虛擬字節
OLED_WR_Byte(0x00,OLED_CMD); //起始頁 0
OLED_WR_Byte(0x00,OLED_CMD); //滾動時間間隔
OLED_WR_Byte(0x01,OLED_CMD); //終止頁 1
OLED_WR_Byte(0x00,OLED_CMD); //虛擬字節
OLED_WR_Byte(0xFF,OLED_CMD); //虛擬字節
OLED_WR_Byte(0x2F,OLED_CMD); //開啟滾動
}
const u8 F6x8[][6] =
{
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,// sp
0x00, 0x00, 0x00, 0x2f, 0x00, 0x00,// !
0x00, 0x00, 0x07, 0x00, 0x07, 0x00,// "
0x00, 0x14, 0x7f, 0x14, 0x7f, 0x14,// #
0x00, 0x24, 0x2a, 0x7f, 0x2a, 0x12,// $
0x00, 0x62, 0x64, 0x08, 0x13, 0x23,// %
0x00, 0x36, 0x49, 0x55, 0x22, 0x50,// &
0x00, 0x00, 0x05, 0x03, 0x00, 0x00,// '
0x00, 0x00, 0x1c, 0x22, 0x41, 0x00,// (
0x00, 0x00, 0x41, 0x22, 0x1c, 0x00,// )
0x00, 0x14, 0x08, 0x3E, 0x08, 0x14,// *
0x00, 0x08, 0x08, 0x3E, 0x08, 0x08,// +
0x00, 0x00, 0x00, 0xA0, 0x60, 0x00,// ,
0x00, 0x08, 0x08, 0x08, 0x08, 0x08,// -
0x00, 0x00, 0x60, 0x60, 0x00, 0x00,// .
0x00, 0x20, 0x10, 0x08, 0x04, 0x02,// /
0x00, 0x3E, 0x51, 0x49, 0x45, 0x3E,// 0
0x00, 0x00, 0x42, 0x7F, 0x40, 0x00,// 1
0x00, 0x42, 0x61, 0x51, 0x49, 0x46,// 2
0x00, 0x21, 0x41, 0x45, 0x4B, 0x31,// 3
0x00, 0x18, 0x14, 0x12, 0x7F, 0x10,// 4
0x00, 0x27, 0x45, 0x45, 0x45, 0x39,// 5
0x00, 0x3C, 0x4A, 0x49, 0x49, 0x30,// 6
0x00, 0x01, 0x71, 0x09, 0x05, 0x03,// 7
0x00, 0x36, 0x49, 0x49, 0x49, 0x36,// 8
0x00, 0x06, 0x49, 0x49, 0x29, 0x1E,// 9
0x00, 0x00, 0x36, 0x36, 0x00, 0x00,// :
0x00, 0x00, 0x56, 0x36, 0x00, 0x00,// ;
0x00, 0x08, 0x14, 0x22, 0x41, 0x00,// <
0x00, 0x14, 0x14, 0x14, 0x14, 0x14,// =
0x00, 0x00, 0x41, 0x22, 0x14, 0x08,// >
0x00, 0x02, 0x01, 0x51, 0x09, 0x06,// ?
0x00, 0x32, 0x49, 0x59, 0x51, 0x3E,// @
0x00, 0x7C, 0x12, 0x11, 0x12, 0x7C,// A
0x00, 0x7F, 0x49, 0x49, 0x49, 0x36,// B
0x00, 0x3E, 0x41, 0x41, 0x41, 0x22,// C
0x00, 0x7F, 0x41, 0x41, 0x22, 0x1C,// D
0x00, 0x7F, 0x49, 0x49, 0x49, 0x41,// E
0x00, 0x7F, 0x09, 0x09, 0x09, 0x01,// F
0x00, 0x3E, 0x41, 0x49, 0x49, 0x7A,// G
0x00, 0x7F, 0x08, 0x08, 0x08, 0x7F,// H
0x00, 0x00, 0x41, 0x7F, 0x41, 0x00,// I
0x00, 0x20, 0x40, 0x41, 0x3F, 0x01,// J
0x00, 0x7F, 0x08, 0x14, 0x22, 0x41,// K
0x00, 0x7F, 0x40, 0x40, 0x40, 0x40,// L
0x00, 0x7F, 0x02, 0x0C, 0x02, 0x7F,// M
0x00, 0x7F, 0x04, 0x08, 0x10, 0x7F,// N
0x00, 0x3E, 0x41, 0x41, 0x41, 0x3E,// O
0x00, 0x7F, 0x09, 0x09, 0x09, 0x06,// P
0x00, 0x3E, 0x41, 0x51, 0x21, 0x5E,// Q
0x00, 0x7F, 0x09, 0x19, 0x29, 0x46,// R
0x00, 0x46, 0x49, 0x49, 0x49, 0x31,// S
0x00, 0x01, 0x01, 0x7F, 0x01, 0x01,// T
0x00, 0x3F, 0x40, 0x40, 0x40, 0x3F,// U
0x00, 0x1F, 0x20, 0x40, 0x20, 0x1F,// V
0x00, 0x3F, 0x40, 0x38, 0x40, 0x3F,// W
0x00, 0x63, 0x14, 0x08, 0x14, 0x63,// X
0x00, 0x07, 0x08, 0x70, 0x08, 0x07,// Y
0x00, 0x61, 0x51, 0x49, 0x45, 0x43,// Z
0x00, 0x00, 0x7F, 0x41, 0x41, 0x00,// [
0x00, 0x55, 0x2A, 0x55, 0x2A, 0x55,// 55
0x00, 0x00, 0x41, 0x41, 0x7F, 0x00,// ]
0x00, 0x04, 0x02, 0x01, 0x02, 0x04,// ^
0x00, 0x40, 0x40, 0x40, 0x40, 0x40,// _
0x00, 0x00, 0x01, 0x02, 0x04, 0x00,// '
0x00, 0x20, 0x54, 0x54, 0x54, 0x78,// a
0x00, 0x7F, 0x48, 0x44, 0x44, 0x38,// b
0x00, 0x38, 0x44, 0x44, 0x44, 0x20,// c
0x00, 0x38, 0x44, 0x44, 0x48, 0x7F,// d
0x00, 0x38, 0x54, 0x54, 0x54, 0x18,// e
0x00, 0x08, 0x7E, 0x09, 0x01, 0x02,// f
0x00, 0x18, 0xA4, 0xA4, 0xA4, 0x7C,// g
0x00, 0x7F, 0x08, 0x04, 0x04, 0x78,// h
0x00, 0x00, 0x44, 0x7D, 0x40, 0x00,// i
0x00, 0x40, 0x80, 0x84, 0x7D, 0x00,// j
0x00, 0x7F, 0x10, 0x28, 0x44, 0x00,// k
0x00, 0x00, 0x41, 0x7F, 0x40, 0x00,// l
0x00, 0x7C, 0x04, 0x18, 0x04, 0x78,// m
0x00, 0x7C, 0x08, 0x04, 0x04, 0x78,// n
0x00, 0x38, 0x44, 0x44, 0x44, 0x38,// o
0x00, 0xFC, 0x24, 0x24, 0x24, 0x18,// p
0x00, 0x18, 0x24, 0x24, 0x18, 0xFC,// q
0x00, 0x7C, 0x08, 0x04, 0x04, 0x08,// r
0x00, 0x48, 0x54, 0x54, 0x54, 0x20,// s
0x00, 0x04, 0x3F, 0x44, 0x40, 0x20,// t
0x00, 0x3C, 0x40, 0x40, 0x20, 0x7C,// u
0x00, 0x1C, 0x20, 0x40, 0x20, 0x1C,// v
0x00, 0x3C, 0x40, 0x30, 0x40, 0x3C,// w
0x00, 0x44, 0x28, 0x10, 0x28, 0x44,// x
0x00, 0x1C, 0xA0, 0xA0, 0xA0, 0x7C,// y
0x00, 0x44, 0x64, 0x54, 0x4C, 0x44,// z
0x14, 0x14, 0x14, 0x14, 0x14, 0x14,// horiz lines
};
/****************************************8*16的點陣************************************/
const u8 F8X16[]=
{
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,// 0
0x00,0x00,0x00,0xF8,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x33,0x30,0x00,0x00,0x00,//! 1
0x00,0x10,0x0C,0x06,0x10,0x0C,0x06,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,//" 2
0x40,0xC0,0x78,0x40,0xC0,0x78,0x40,0x00,0x04,0x3F,0x04,0x04,0x3F,0x04,0x04,0x00,//# 3
0x00,0x70,0x88,0xFC,0x08,0x30,0x00,0x00,0x00,0x18,0x20,0xFF,0x21,0x1E,0x00,0x00,//$ 4
0xF0,0x08,0xF0,0x00,0xE0,0x18,0x00,0x00,0x00,0x21,0x1C,0x03,0x1E,0x21,0x1E,0x00,//% 5
0x00,0xF0,0x08,0x88,0x70,0x00,0x00,0x00,0x1E,0x21,0x23,0x24,0x19,0x27,0x21,0x10,//& 6
0x10,0x16,0x0E,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,//' 7
0x00,0x00,0x00,0xE0,0x18,0x04,0x02,0x00,0x00,0x00,0x00,0x07,0x18,0x20,0x40,0x00,//( 8
0x00,0x02,0x04,0x18,0xE0,0x00,0x00,0x00,0x00,0x40,0x20,0x18,0x07,0x00,0x00,0x00,//) 9
0x40,0x40,0x80,0xF0,0x80,0x40,0x40,0x00,0x02,0x02,0x01,0x0F,0x01,0x02,0x02,0x00,//* 10
0x00,0x00,0x00,0xF0,0x00,0x00,0x00,0x00,0x01,0x01,0x01,0x1F,0x01,0x01,0x01,0x00,//+ 11
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0xB0,0x70,0x00,0x00,0x00,0x00,0x00,//, 12
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x01,0x01,0x01,0x01,0x01,0x01,//- 13
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x30,0x30,0x00,0x00,0x00,0x00,0x00,//. 14
0x00,0x00,0x00,0x00,0x80,0x60,0x18,0x04,0x00,0x60,0x18,0x06,0x01,0x00,0x00,0x00,/// 15
0x00,0xE0,0x10,0x08,0x08,0x10,0xE0,0x00,0x00,0x0F,0x10,0x20,0x20,0x10,0x0F,0x00,//0 16
0x00,0x10,0x10,0xF8,0x00,0x00,0x00,0x00,0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00,//1 17
0x00,0x70,0x08,0x08,0x08,0x88,0x70,0x00,0x00,0x30,0x28,0x24,0x22,0x21,0x30,0x00,//2 18
0x00,0x30,0x08,0x88,0x88,0x48,0x30,0x00,0x00,0x18,0x20,0x20,0x20,0x11,0x0E,0x00,//3 19
0x00,0x00,0xC0,0x20,0x10,0xF8,0x00,0x00,0x00,0x07,0x04,0x24,0x24,0x3F,0x24,0x00,//4 20
0x00,0xF8,0x08,0x88,0x88,0x08,0x08,0x00,0x00,0x19,0x21,0x20,0x20,0x11,0x0E,0x00,//5 21
0x00,0xE0,0x10,0x88,0x88,0x18,0x00,0x00,0x00,0x0F,0x11,0x20,0x20,0x11,0x0E,0x00,//6 22
0x00,0x38,0x08,0x08,0xC8,0x38,0x08,0x00,0x00,0x00,0x00,0x3F,0x00,0x00,0x00,0x00,//7 23
0x00,0x70,0x88,0x08,0x08,0x88,0x70,0x00,0x00,0x1C,0x22,0x21,0x21,0x22,0x1C,0x00,//8 24
0x00,0xE0,0x10,0x08,0x08,0x10,0xE0,0x00,0x00,0x00,0x31,0x22,0x22,0x11,0x0F,0x00,//9 25
0x00,0x00,0x00,0xC0,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x30,0x30,0x00,0x00,0x00,//: 26
0x00,0x00,0x00,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0x60,0x00,0x00,0x00,0x00,//; 27
0x00,0x00,0x80,0x40,0x20,0x10,0x08,0x00,0x00,0x01,0x02,0x04,0x08,0x10,0x20,0x00,//< 28
0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x00,0x04,0x04,0x04,0x04,0x04,0x04,0x04,0x00,//= 29
0x00,0x08,0x10,0x20,0x40,0x80,0x00,0x00,0x00,0x20,0x10,0x08,0x04,0x02,0x01,0x00,//> 30
0x00,0x70,0x48,0x08,0x08,0x08,0xF0,0x00,0x00,0x00,0x00,0x30,0x36,0x01,0x00,0x00,//? 31
0xC0,0x30,0xC8,0x28,0xE8,0x10,0xE0,0x00,0x07,0x18,0x27,0x24,0x23,0x14,0x0B,0x00,//@ 32
0x00,0x00,0xC0,0x38,0xE0,0x00,0x00,0x00,0x20,0x3C,0x23,0x02,0x02,0x27,0x38,0x20,//A 33
0x08,0xF8,0x88,0x88,0x88,0x70,0x00,0x00,0x20,0x3F,0x20,0x20,0x20,0x11,0x0E,0x00,//B 34
0xC0,0x30,0x08,0x08,0x08,0x08,0x38,0x00,0x07,0x18,0x20,0x20,0x20,0x10,0x08,0x00,//C 35
0x08,0xF8,0x08,0x08,0x08,0x10,0xE0,0x00,0x20,0x3F,0x20,0x20,0x20,0x10,0x0F,0x00,//D 36
0x08,0xF8,0x88,0x88,0xE8,0x08,0x10,0x00,0x20,0x3F,0x20,0x20,0x23,0x20,0x18,0x00,//E 37
0x08,0xF8,0x88,0x88,0xE8,0x08,0x10,0x00,0x20,0x3F,0x20,0x00,0x03,0x00,0x00,0x00,//F 38
0xC0,0x30,0x08,0x08,0x08,0x38,0x00,0x00,0x07,0x18,0x20,0x20,0x22,0x1E,0x02,0x00,//G 39
0x08,0xF8,0x08,0x00,0x00,0x08,0xF8,0x08,0x20,0x3F,0x21,0x01,0x01,0x21,0x3F,0x20,//H 40
0x00,0x08,0x08,0xF8,0x08,0x08,0x00,0x00,0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00,//I 41
0x00,0x00,0x08,0x08,0xF8,0x08,0x08,0x00,0xC0,0x80,0x80,0x80,0x7F,0x00,0x00,0x00,//J 42
0x08,0xF8,0x88,0xC0,0x28,0x18,0x08,0x00,0x20,0x3F,0x20,0x01,0x26,0x38,0x20,0x00,//K 43
0x08,0xF8,0x08,0x00,0x00,0x00,0x00,0x00,0x20,0x3F,0x20,0x20,0x20,0x20,0x30,0x00,//L 44
0x08,0xF8,0xF8,0x00,0xF8,0xF8,0x08,0x00,0x20,0x3F,0x00,0x3F,0x00,0x3F,0x20,0x00,//M 45
0x08,0xF8,0x30,0xC0,0x00,0x08,0xF8,0x08,0x20,0x3F,0x20,0x00,0x07,0x18,0x3F,0x00,//N 46
0xE0,0x10,0x08,0x08,0x08,0x10,0xE0,0x00,0x0F,0x10,0x20,0x20,0x20,0x10,0x0F,0x00,//O 47
0x08,0xF8,0x08,0x08,0x08,0x08,0xF0,0x00,0x20,0x3F,0x21,0x01,0x01,0x01,0x00,0x00,//P 48
0xE0,0x10,0x08,0x08,0x08,0x10,0xE0,0x00,0x0F,0x18,0x24,0x24,0x38,0x50,0x4F,0x00,//Q 49
0x08,0xF8,0x88,0x88,0x88,0x88,0x70,0x00,0x20,0x3F,0x20,0x00,0x03,0x0C,0x30,0x20,//R 50
0x00,0x70,0x88,0x08,0x08,0x08,0x38,0x00,0x00,0x38,0x20,0x21,0x21,0x22,0x1C,0x00,//S 51
0x18,0x08,0x08,0xF8,0x08,0x08,0x18,0x00,0x00,0x00,0x20,0x3F,0x20,0x00,0x00,0x00,//T 52
0x08,0xF8,0x08,0x00,0x00,0x08,0xF8,0x08,0x00,0x1F,0x20,0x20,0x20,0x20,0x1F,0x00,//U 53
0x08,0x78,0x88,0x00,0x00,0xC8,0x38,0x08,0x00,0x00,0x07,0x38,0x0E,0x01,0x00,0x00,//V 54
0xF8,0x08,0x00,0xF8,0x00,0x08,0xF8,0x00,0x03,0x3C,0x07,0x00,0x07,0x3C,0x03,0x00,//W 55
0x08,0x18,0x68,0x80,0x80,0x68,0x18,0x08,0x20,0x30,0x2C,0x03,0x03,0x2C,0x30,0x20,//X 56
0x08,0x38,0xC8,0x00,0xC8,0x38,0x08,0x00,0x00,0x00,0x20,0x3F,0x20,0x00,0x00,0x00,//Y 57
0x10,0x08,0x08,0x08,0xC8,0x38,0x08,0x00,0x20,0x38,0x26,0x21,0x20,0x20,0x18,0x00,//Z 58
0x00,0x00,0x00,0xFE,0x02,0x02,0x02,0x00,0x00,0x00,0x00,0x7F,0x40,0x40,0x40,0x00,//[ 59
0x00,0x0C,0x30,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x06,0x38,0xC0,0x00,//\ 60
0x00,0x02,0x02,0x02,0xFE,0x00,0x00,0x00,0x00,0x40,0x40,0x40,0x7F,0x00,0x00,0x00,//] 61
0x00,0x00,0x04,0x02,0x02,0x02,0x04,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,//^ 62
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,//_ 63
0x00,0x02,0x02,0x04,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,//` 64
0x00,0x00,0x80,0x80,0x80,0x80,0x00,0x00,0x00,0x19,0x24,0x22,0x22,0x22,0x3F,0x20,//a 65
0x08,0xF8,0x00,0x80,0x80,0x00,0x00,0x00,0x00,0x3F,0x11,0x20,0x20,0x11,0x0E,0x00,//b 66
0x00,0x00,0x00,0x80,0x80,0x80,0x00,0x00,0x00,0x0E,0x11,0x20,0x20,0x20,0x11,0x00,//c 67
0x00,0x00,0x00,0x80,0x80,0x88,0xF8,0x00,0x00,0x0E,0x11,0x20,0x20,0x10,0x3F,0x20,//d 68
0x00,0x00,0x80,0x80,0x80,0x80,0x00,0x00,0x00,0x1F,0x22,0x22,0x22,0x22,0x13,0x00,//e 69
0x00,0x80,0x80,0xF0,0x88,0x88,0x88,0x18,0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00,//f 70
0x00,0x00,0x80,0x80,0x80,0x80,0x80,0x00,0x00,0x6B,0x94,0x94,0x94,0x93,0x60,0x00,//g 71
0x08,0xF8,0x00,0x80,0x80,0x80,0x00,0x00,0x20,0x3F,0x21,0x00,0x00,0x20,0x3F,0x20,//h 72
0x00,0x80,0x98,0x98,0x00,0x00,0x00,0x00,0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00,//i 73
0x00,0x00,0x00,0x80,0x98,0x98,0x00,0x00,0x00,0xC0,0x80,0x80,0x80,0x7F,0x00,0x00,//j 74
0x08,0xF8,0x00,0x00,0x80,0x80,0x80,0x00,0x20,0x3F,0x24,0x02,0x2D,0x30,0x20,0x00,//k 75
0x00,0x08,0x08,0xF8,0x00,0x00,0x00,0x00,0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00,//l 76
0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x00,0x20,0x3F,0x20,0x00,0x3F,0x20,0x00,0x3F,//m 77
0x80,0x80,0x00,0x80,0x80,0x80,0x00,0x00,0x20,0x3F,0x21,0x00,0x00,0x20,0x3F,0x20,//n 78
0x00,0x00,0x80,0x80,0x80,0x80,0x00,0x00,0x00,0x1F,0x20,0x20,0x20,0x20,0x1F,0x00,//o 79
0x80,0x80,0x00,0x80,0x80,0x00,0x00,0x00,0x80,0xFF,0xA1,0x20,0x20,0x11,0x0E,0x00,//p 80
0x00,0x00,0x00,0x80,0x80,0x80,0x80,0x00,0x00,0x0E,0x11,0x20,0x20,0xA0,0xFF,0x80,//q 81
0x80,0x80,0x80,0x00,0x80,0x80,0x80,0x00,0x20,0x20,0x3F,0x21,0x20,0x00,0x01,0x00,//r 82
0x00,0x00,0x80,0x80,0x80,0x80,0x80,0x00,0x00,0x33,0x24,0x24,0x24,0x24,0x19,0x00,//s 83
0x00,0x80,0x80,0xE0,0x80,0x80,0x00,0x00,0x00,0x00,0x00,0x1F,0x20,0x20,0x00,0x00,//t 84
0x80,0x80,0x00,0x00,0x00,0x80,0x80,0x00,0x00,0x1F,0x20,0x20,0x20,0x10,0x3F,0x20,//u 85
0x80,0x80,0x80,0x00,0x00,0x80,0x80,0x80,0x00,0x01,0x0E,0x30,0x08,0x06,0x01,0x00,//v 86
0x80,0x80,0x00,0x80,0x00,0x80,0x80,0x80,0x0F,0x30,0x0C,0x03,0x0C,0x30,0x0F,0x00,//w 87
0x00,0x80,0x80,0x00,0x80,0x80,0x80,0x00,0x00,0x20,0x31,0x2E,0x0E,0x31,0x20,0x00,//x 88
0x80,0x80,0x80,0x00,0x00,0x80,0x80,0x80,0x80,0x81,0x8E,0x70,0x18,0x06,0x01,0x00,//y 89
0x00,0x80,0x80,0x80,0x80,0x80,0x80,0x00,0x00,0x21,0x30,0x2C,0x22,0x21,0x30,0x00,//z 90
0x00,0x00,0x00,0x00,0x80,0x7C,0x02,0x02,0x00,0x00,0x00,0x00,0x00,0x3F,0x40,0x40,//{ 91
0x00,0x00,0x00,0x00,0xFF,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0x00,0x00,0x00,//| 92
0x00,0x02,0x02,0x7C,0x80,0x00,0x00,0x00,0x00,0x40,0x40,0x3F,0x00,0x00,0x00,0x00,//} 93
0x00,0x06,0x01,0x01,0x02,0x02,0x04,0x04,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,//~ 94
};
const u8 Hzk[][16]={
{0x04,0x04,0x44,0xC4,0x4F,0x44,0x44,0xC4,0x24,0x24,0x2F,0xB4,0x24,0x04,0x04,0x00},
{0x40,0x44,0x24,0x24,0x15,0x0C,0x04,0xFE,0x04,0x0C,0x15,0x24,0x24,0x44,0x40,0x00},/*"菜",0*/
{0x00,0x00,0xF8,0x49,0x4A,0x4C,0x48,0xF8,0x48,0x4C,0x4A,0x49,0xF8,0x00,0x00,0x00},
{0x10,0x10,0x13,0x12,0x12,0x12,0x12,0xFF,0x12,0x12,0x12,0x12,0x13,0x10,0x10,0x00},/*"單",1*/
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
{0x00,0x00,0x36,0x36,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},/*":",2*/
{0x10,0x10,0x10,0xFF,0x90,0x20,0x98,0x88,0x88,0xE9,0x8E,0x88,0x88,0xA8,0x98,0x00},
{0x02,0x42,0x81,0x7F,0x00,0x00,0x80,0x84,0x4B,0x28,0x10,0x28,0x47,0x80,0x00,0x00},/*"按",3*/
{0x40,0x30,0xEF,0x24,0x24,0x80,0xE4,0x9C,0x10,0x54,0x54,0xFF,0x54,0x7C,0x10,0x00},
{0x01,0x01,0x7F,0x21,0x51,0x26,0x18,0x27,0x44,0x45,0x45,0x5F,0x45,0x45,0x44,0x00},/*"鍵",4*/
{0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x00},
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},/*"一",5*/
{0x10,0x10,0x10,0xFF,0x90,0x20,0x98,0x88,0x88,0xE9,0x8E,0x88,0x88,0xA8,0x98,0x00},
{0x02,0x42,0x81,0x7F,0x00,0x00,0x80,0x84,0x4B,0x28,0x10,0x28,0x47,0x80,0x00,0x00},/*"按",6*/
{0x40,0x30,0xEF,0x24,0x24,0x80,0xE4,0x9C,0x10,0x54,0x54,0xFF,0x54,0x7C,0x10,0x00},
{0x01,0x01,0x7F,0x21,0x51,0x26,0x18,0x27,0x44,0x45,0x45,0x5F,0x45,0x45,0x44,0x00},/*"鍵",7*/
{0x00,0x00,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x00,0x00,0x00},
{0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x00},/*"二",8*/
{0x04,0x34,0xC4,0x04,0xC4,0x3C,0x00,0x04,0xFC,0x04,0x04,0x04,0xC4,0x3C,0x00,0x00},
{0x40,0x30,0x0C,0x03,0x0C,0x30,0x80,0x40,0x20,0x13,0x0C,0x13,0x20,0x40,0x80,0x00},/*"雙",9*/
{0x10,0x10,0x10,0xFF,0x90,0x20,0x98,0x88,0x88,0xE9,0x8E,0x88,0x88,0xA8,0x98,0x00},
{0x02,0x42,0x81,0x7F,0x00,0x00,0x80,0x84,0x4B,0x28,0x10,0x28,0x47,0x80,0x00,0x00},/*"按",10*/
{0x40,0x30,0xEF,0x24,0x24,0x80,0xE4,0x9C,0x10,0x54,0x54,0xFF,0x54,0x7C,0x10,0x00},
{0x01,0x01,0x7F,0x21,0x51,0x26,0x18,0x27,0x44,0x45,0x45,0x5F,0x45,0x45,0x44,0x00},/*"鍵",11*/
};
void key_Init(void)
{
PD_DDR&=0X00;
PD_CR1=0X18;//PD3,PD4帶上拉的輸入模式
PD_CR2&=0X00;
}
u8 key1_scan(void) //PD3
{
static u8 key1_up=0;
u8 num;
num=PD_IDR;
num=PD_IDR&0x18;
if(num==0x10)
delay_ms(30);
if(num==0x10)
{
key1_up=0;
}
else
{
key1_up=1;
return 1;
}
return 0;
}
u8 key2_scan(void) //PD4
{
static u8 key2_up=0;
u8 num;
num=PD_IDR;
num=PD_IDR&0x18;
if(num==0x08)
delay_ms(30);
if(num==0x08)
{
key2_up=0;
}
else
{
key2_up=1;
return 1;
}
return 0;
}
u8 key_scan(void)
{
u8 key_code;
if(key1_scan()==1)key_code=2;
else if(key2_scan()==1)key_code=3;
else key_code=0;
return key_code;
}
void KeyPressed(u8 cur)
{
u8 flag=0;
OLED_menu(cur);
while(1)
{
if(flag)
{
OLED_menu(cur);
flag=2;
}
switch(key_scan())
{
case 0: flag = 0;
break;
case 3: flag = 1;
if(cur==3)
cur=1;
else
cur++;
OLED_Clear();
break;
}
}
}
void OLED_menu(u8 cur)
{
void OLED_String(u8 x,u8 y,u8 *chr);
void OLED_ShowChinese(u8 x,u8 y,u8 no);
switch(cur)
{
case 1:
OLED_ShowString(16,2,"=>");
OLED_ShowChinese(0,0,0);//OLED顯示 菜
OLED_ShowChinese(16,0,1);//OLED顯示 單
OLED_ShowChinese(32,0,2);//OLED顯示 :
OLED_ShowChinese(32,2,3);//OLED顯示 按
OLED_ShowChinese(48,2,4);//OLED顯示 鍵
OLED_ShowChinese(64,2,5);//OLED顯示 一
OLED_ShowChinese(32,4,6);//OLED顯示 按
OLED_ShowChinese(48,4,7);//OLED顯示 鍵
OLED_ShowChinese(64,4,8);//OLED顯示 二
OLED_ShowChinese(32,6,9);//OLED顯示 雙
OLED_ShowChinese(48,6,10);//OLED顯示 按
OLED_ShowChinese(64,6,11);//OLED顯示 鍵
break;
case 2:
OLED_ShowString(16,4,"=>");
OLED_ShowChinese(0,0,0);//OLED顯示 菜
OLED_ShowChinese(16,0,1);//OLED顯示 單
OLED_ShowChinese(32,0,2);//OLED顯示 :
OLED_ShowChinese(32,2,3);//OLED顯示 按
OLED_ShowChinese(48,2,4);//OLED顯示 鍵
OLED_ShowChinese(64,2,5);//OLED顯示 一
OLED_ShowChinese(32,4,6);//OLED顯示 按
OLED_ShowChinese(48,4,7);//OLED顯示 鍵
OLED_ShowChinese(64,4,8);//OLED顯示 二
OLED_ShowChinese(32,6,9);//OLED顯示 雙
OLED_ShowChinese(48,6,10);//OLED顯示 按
OLED_ShowChinese(64,6,11);//OLED顯示 鍵
break;
case 3:
OLED_ShowString(16,6,"=>");
OLED_ShowChinese(0,0,0);//OLED顯示 菜
OLED_ShowChinese(16,0,1);//OLED顯示 單
OLED_ShowChinese(32,0,2);//OLED顯示 :
OLED_ShowChinese(32,2,3);//OLED顯示 按
OLED_ShowChinese(48,2,4);//OLED顯示 鍵
OLED_ShowChinese(64,2,5);//OLED顯示 一
OLED_ShowChinese(32,4,6);//OLED顯示 按
OLED_ShowChinese(48,4,7);//OLED顯示 鍵
OLED_ShowChinese(64,4,8);//OLED顯示 二
OLED_ShowChinese(32,6,9);//OLED顯示 雙
OLED_ShowChinese(48,6,10);//OLED顯示 按
OLED_ShowChinese(64,6,11);//OLED顯示 鍵
break;
}
}
|