#include<myboard.h>
unsigned char code num[][16]={
{0x00,0xE0,0x10,0x08,0x08,0x10,0xE0,0x00,0x00,0x0F,0x10,0x20,0x20,0x10,0x0F,0x00},/*"0",0*/
{0x00,0x00,0x10,0x10,0xF8,0x00,0x00,0x00,0x00,0x00,0x20,0x20,0x3F,0x20,0x20,0x00},/*"1",1*/
{0x00,0x70,0x08,0x08,0x08,0x08,0xF0,0x00,0x00,0x30,0x28,0x24,0x22,0x21,0x30,0x00},/*"2",2*/
{0x00,0x30,0x08,0x08,0x08,0x88,0x70,0x00,0x00,0x18,0x20,0x21,0x21,0x22,0x1C,0x00},/*"3",3*/
{0x00,0x00,0x80,0x40,0x30,0xF8,0x00,0x00,0x00,0x06,0x05,0x24,0x24,0x3F,0x24,0x24},/*"4",4*/
{0x00,0xF8,0x88,0x88,0x88,0x08,0x08,0x00,0x00,0x19,0x20,0x20,0x20,0x11,0x0E,0x00},/*"5",5*/
{0x00,0xE0,0x10,0x88,0x88,0x90,0x00,0x00,0x00,0x0F,0x11,0x20,0x20,0x20,0x1F,0x00},/*"6",6*/
{0x00,0x18,0x08,0x08,0x88,0x68,0x18,0x00,0x00,0x00,0x00,0x3E,0x01,0x00,0x00,0x00},/*"7",7*/
{0x00,0x70,0x88,0x08,0x08,0x88,0x70,0x00,0x00,0x1C,0x22,0x21,0x21,0x22,0x1C,0x00},/*"8",8*/
{0x00,0xF0,0x08,0x08,0x08,0x10,0xE0,0x00,0x00,0x01,0x12,0x22,0x22,0x11,0x0F,0x00},/*"9",9*/
};
/*
numb:显示的数字,0-9
x:坐标:0-127
y:坐标:0-3
flag:0为正显示,1为反显示
*/
void numberx(unsigned char numb, unsigned char x, unsigned char y, unsigned char flag) {
unsigned char i;
for (i = 0; i < 16; i++) {
if (i == 0 || i == 15) {
OLED_Set_Pos(x + i, y + 0);
OLED_WR_Byte(flag ? ~0xFF : 0xFF, OLED_DATA);
OLED_Set_Pos(x + i, y + 1);
OLED_WR_Byte(flag ? ~0xFF : 0xFF, OLED_DATA);
} else if ((i > 0 && i < 4) || (i > 12 && i < 16)) {
OLED_Set_Pos(x + i, y + 0);
OLED_WR_Byte(flag ? ~0x01 : 0x01, OLED_DATA);
OLED_Set_Pos(x + i, y + 1);
OLED_WR_Byte(flag ? ~0x80 : 0x80, OLED_DATA);
} else {
OLED_Set_Pos(x + i, y + 0);
OLED_WR_Byte(flag ? ~(0x01 | num[numb][i - 4]) : (0x01 | num[numb][i - 4]), OLED_DATA);
OLED_Set_Pos(x + i, y + 1);
OLED_WR_Byte(flag ? ~(0x80 | num[numb][i + 4]) : (0x80 | num[numb][i + 4]), OLED_DATA);
}
}
}
void main(void)
{
unsigned char i=0;
char fla=0,tem;
OLED_Init();
OLED_ColorTurn(0);//0正常显示,1 反色显示
OLED_DisplayTurn(0);//0正常显示 1 屏幕翻转显示
OLED_Display_Off();
OLED_Display_On();
for(i=0;i<8;i++)
numberx(i,16*i,0,0);
numberx(fla,16*(fla),0,1);
while(1)
{
if(KEY1==0)
{
tem=fla--;
while(KEY1==0);
numberx(tem,16*(tem),0,0);
if(fla<0) fla=7;
numberx(fla,16*(fla),0,1);
}
if(KEY2==0)
{
tem=fla++;
while(KEY2==0);
numberx(tem,16*(tem),0,0);
if(fla==8) fla=0;
numberx(fla,16*(fla),0,1);
}
}
}
显示效果