#include<reg51.h>
#include<intrins.h>
typedef unsigned int u16; //对系统默认数据类型进行重定义
typedef unsigned char u8;
#define uchar unsigned char
#define uint unsigned int
sbit ds1 = P2^1;
sbit sh_cp1 = P2^0;
sbit st_cp1 = P2^2;
sbit ds2 = P2^6;
sbit sh_cp2 = P2^5;
sbit st_cp2 = P2^7;
sbit OE = P2^3;
sbit e = P2^4;
void Delay_ms(u16 ms)
{
u16 i,j;
for(i=ms;i>0;i--)
for(j=110;j>0;j--);
}
uchar code dat[][16] = {
{0x00,0x00,0x0F,0x08,0x08,0x08,0x08,0xFF,0x08,0x08,0x08,0x08,0x0F,0x00,0x00,0x00},
{0x00,0x00,0xF0,0x20,0x20,0x20,0x20,0xFF,0x20,0x20,0x20,0x20,0xF0,0x00,0x00,0x00},
{0x00,0x7F,0x40,0x48,0x49,0x49,0x49,0x4F,0x49,0x49,0x49,0x48,0x40,0x7F,0x00,0x00},
{0x00,0xFF,0x02,0x12,0x12,0x12,0x12,0xF2,0x12,0x52,0x32,0x12,0x02,0xFF,0x00,0x00},
{0x04,0x08,0x32,0xE2,0x2A,0x2A,0x2A,0x2A,0x2A,0x2A,0x2A,0x2B,0x20,0x20,0x00,0x00},
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xF0,0x0C,0x02,0x0F,0x00},
{0x08,0x10,0x3E,0x52,0xD2,0x53,0x57,0x5A,0x52,0x52,0x72,0x12,0x1E,0x00,0x00,0x00},
{0x02,0x52,0x52,0x94,0xA4,0x28,0x4A,0x91,0x7E,0x20,0x50,0x88,0x04,0x02,0x02,0x00},
{0x10,0x12,0x11,0x10,0x13,0x1C,0x00,0x7F,0x40,0x40,0x4F,0x40,0x40,0x7F,0x00,0x00},
{0x04,0x08,0x30,0xC0,0x20,0x19,0x02,0xC4,0x18,0x60,0x80,0x7E,0x01,0xC1,0x07,0x00},
{0x02,0x02,0x42,0x42,0x42,0x42,0x43,0x42,0x42,0x42,0x42,0x42,0x42,0x02,0x02,0x00},
{0x00,0x04,0x0E,0x14,0x24,0xC4,0x04,0x04,0x04,0x24,0x14,0x0C,0x07,0x00,0x00,0x00},
{0x08,0x06,0x40,0x31,0x00,0x7F,0x40,0x4F,0x40,0x7F,0x00,0x1F,0x00,0xFF,0x00,0x00},
{0x20,0x20,0x7E,0x80,0x01,0xE2,0x0C,0xF0,0x08,0xE4,0x00,0xE2,0x01,0xFE,0x00,0x00},
{0x02,0x02,0x42,0x42,0x42,0x42,0x42,0x7F,0x42,0x42,0x42,0x42,0x42,0x02,0x02,0x00},
{0x01,0x01,0x02,0x04,0x08,0x30,0xC0,0x00,0xC0,0x30,0x08,0x04,0x02,0x01,0x01,0x00},
};
void dat595(uchar as,uchar bs) //向HC595传入数据
{
uchar i,b;
e = 1;
b = bs; //先写第二个参数,即取模的时候汉字字模的第二排数据(共16个),写到16*16点阵的下面2个8*8点阵
for(i = 0; i < 8; i++)
{
ds1 = b & 0x01; //写参数2的最低位
sh_cp1 = 0;
_nop_();_nop_();_nop_(); //空操作,
sh_cp1 = 1;
b >>= 1; //右移一位
}
b = as;
for(i = 0; i < 8; i++)
{
ds1 = b&0x01;
sh_cp1 = 0;
_nop_();_nop_();_nop_();
sh_cp1 = 1;
b >>= 1;
}
}
void shuchu() //HC595输出数据
{
st_cp2 = 0;
st_cp1 = 0;
st_cp2 = 1; //在时钟上升沿输出数据
st_cp1 = 1; //在时钟上升沿输出数据
}
void suocun() //HC595锁存数据
{
sh_cp2 = 0; //在时钟上升沿写入数据
sh_cp2 = 1;
ds2 = 1;
}
void OLED_ShowCHinese(uchar f)
{
uchar j;
OE = 0 ;
ds2= 0 ;
for(j =0; j < 16; j++)
{
dat595(dat[3*f+f][j],dat[3*f+f+1][j]);
suocun();
shuchu();
}
for(j = 0; j < 16; j++)
{
dat595(dat[3*f+f+2][j],dat[3*f+f+3][j]);
suocun();
shuchu();
}
}
void timer0_isr() interrupt 1
{
static uchar index = 0;
static uint cp2;
TH0=0XFC; //给定时器赋初值,定时1ms
TL0=0X18;
cp2++;
if(cp2 == 100)
{
cp2 =0;
index++;
if(index >=4)
index = 0;
}OLED_ShowCHinese(index);
}
void init_timer0()
{
TMOD|=0X01;//选择为定时器0模式,工作方式1
TH0=0XFC; //给定时器赋初值,定时1ms
TL0=0X18;
ET0=1;//打开定时器0中断允许
EA=1;//打开总中断
TR0=1;//打开定时器
}
void main(void)
{
init_timer0();
while(1)
{
}
}
仿真图都确,也能正常显示,就是想弄成循环显示的时候,OLED_ShowCHinese放if里面就无法正常显示,放外面能显示但是时间延迟较长,无法调整。有没有大佬知道怎么回事的!!!!!
|