各位大神帮帮忙,程序的时序没有问题,硬件方面参考手册,现在贴上c文件,
#include "reg51.h"
#include "absacc.h"
#define unchar unsigned char
#define unint unsigned int
//--------------------------------------------------------- 4线SPI接口 驱动
sbit RSTB =P1^3;
sbit SDI =P1^0;
sbit SCL =P2^0;
sbit CS0 =P1^4;
sbit A0 =P1^2;
sbit KEY =P1^5;
//sbit LED =P2^0;
unchar code graphic1[]=
{
/*-- 宽度x高度=128x64 --*/
0xFF,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,
0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,
0x01,0x01,0x01,0x01,0x01,0x81,0xC1,0x41,0x41,0x41,0x01,0x01,0x01,0x01,0x01,0x01,
0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,
0x01,0x01,0x81,0x01,0x01,0x81,0x81,0xC1,0x01,0x81,0xC1,0x81,0x81,0xC1,0xC1,0x01,
0x81,0x81,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,
0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,
0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0xFF,
0xFF,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0xE0,0xBC,0x84,0xC4,0x74,0x10,0x18,0x08,0x08,0x08,0x60,0xF0,0xB0,
0xD0,0xF0,0xF8,0xFC,0xFE,0xFF,0xE7,0xF3,0xFD,0xF8,0xFC,0xFE,0xFE,0xFF,0xFD,0xFC,
0xFC,0xFE,0xF6,0xF2,0xD0,0x80,0x00,0x00,0x80,0x00,0xE0,0xC0,0xF0,0xF8,0xFE,0xFC,
0xFE,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x7F,0x7F,0x7F,0x7F,0x7F,0xFF,0xFF,
0xFF,0xFE,0xFE,0xFF,0xF9,0xFC,0xF4,0x60,0x40,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x80,0xC0,0xE0,0xF0,0xF0,0xF8,0xF8,0xFC,0xF8,0xFC,0xFC,0xFE,0xFE,
0xFA,0xFA,0x68,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,
0xFF,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x02,0x47,0xC7,0xCF,0xDF,0xEF,0xEE,0xEE,0xEF,0xF7,0x77,0x7F,0x7F,
0x3F,0x1F,0x1F,0x3F,0x3F,0x3F,0xFF,0xDF,0xD7,0xD7,0xD5,0xC5,0xE5,0xF1,0xFF,0xFF,
0xFF,0xFF,0xFF,0x7F,0xFF,0xD9,0xFD,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x7F,
0xBF,0xDF,0x4F,0x77,0x83,0x03,0x01,0x00,0x00,0xC0,0xC0,0xF0,0xF8,0xFC,0xFE,0xFF,
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x3F,0x3F,0x72,0x00,0x00,0x00,0x00,0x00,0x00,0xC0,
0xF0,0xFC,0xFF,0xFF,0xFF,0xFF,0xFF,0x03,0x01,0x00,0x01,0x01,0x03,0x03,0x07,0x07,
0x05,0x05,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,
0xFF,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x80,0x80,0x81,0xC1,0x43,0xC7,0xC3,0x07,0x03,0x02,0x00,
0x00,0xFC,0xFE,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xEF,0xE7,0xF7,0xFF,0xFF,0xF7,
0xFB,0xFF,0xFE,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xDF,0xCF,0xC7,0x85,0x86,0x87,
0x8F,0x8F,0x1D,0x19,0x3D,0x3C,0x3C,0x7C,0x7D,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
0xFF,0xFE,0xF7,0xFB,0xF8,0xFC,0xF8,0xF8,0xFC,0xFE,0xF8,0xFC,0xFE,0xFC,0xFF,0xFF,
0xFF,0xFF,0x7F,0x7F,0x3F,0x0F,0x03,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,
0xFF,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0xE0,0xC0,0x67,0x7C,0x3F,0x3B,0x39,0x1C,0x1C,0x0E,0x0F,
0x0F,0x0F,0x07,0x07,0x07,0x0F,0x0F,0x0F,0x1F,0x1F,0x1F,0x1F,0x1F,0x1F,0x1F,0x1F,
0x1F,0x0F,0x0F,0x0F,0x07,0x07,0x03,0x03,0x03,0x03,0x03,0x01,0x21,0x71,0x59,0x9B,
0xEF,0x7F,0x3F,0x03,0x03,0x01,0x01,0x03,0x00,0x00,0x03,0x07,0x07,0x03,0x07,0x07,
0x0F,0x07,0x07,0x0F,0x07,0x0F,0x0F,0x0F,0x1F,0x9F,0x9F,0xDF,0xFB,0xFB,0x79,0x39,
0x19,0x18,0x08,0x18,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,
0xFF,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0x80,0x00,0x00,0x00,0x80,0x80,0x80,0x80,
0x80,0x80,0x00,0x00,0x00,0x00,0x00,0x80,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0xC0,
0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x40,0xC0,0x80,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0x80,0x80,0x00,0x00,0xC0,0xC0,0x00,0x00,
0x00,0x01,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0x80,0x80,0x80,0x80,0x00,0x00,
0x00,0x00,0x00,0x80,0x80,0x00,0x00,0x00,0x01,0x01,0x80,0x80,0x00,0x01,0x01,0x00,
0x00,0x00,0x00,0x00,0x80,0x80,0x80,0x00,0x00,0xC0,0xC0,0x00,0x00,0x00,0x00,0x00,
0x00,0xC0,0xC0,0x00,0x00,0x00,0xC0,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,
0xFF,0x00,0x00,0x00,0x00,0x00,0x84,0xEC,0x79,0x93,0xD7,0x77,0xFF,0xFD,0x6B,0xCB,
0x89,0x80,0x80,0x00,0x00,0x40,0x48,0x7F,0x3F,0xA4,0xE4,0x7F,0x3F,0x7F,0x7F,0xFF,
0xFF,0x00,0x00,0x00,0x00,0x02,0x02,0x7A,0x7A,0xFE,0xFF,0x25,0x7D,0x7D,0x01,0x01,
0x00,0x00,0x00,0x48,0x69,0x39,0xFF,0xFF,0x14,0x24,0x25,0x35,0xFF,0xFF,0x10,0x10,
0x00,0x00,0x00,0x3E,0x3F,0x25,0x3F,0xBF,0xFF,0x7F,0x14,0x14,0xFF,0xFF,0x00,0x00,
0x00,0x08,0x2C,0xFF,0xFB,0xEA,0xC2,0xFD,0x7F,0xF3,0xFF,0x0E,0xC0,0xC0,0x00,0x00,
0x48,0x69,0x39,0xFF,0xFF,0x14,0x24,0x25,0x35,0xFF,0xFF,0x10,0x10,0x00,0x00,0x44,
0x64,0xFF,0xFF,0x0A,0x12,0xB2,0xFF,0xFF,0xB9,0x81,0x00,0x00,0x00,0x00,0x00,0xFF,
0xFF,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x81,0x81,0x80,0x80,0x83,0x83,0x80,0x80,
0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x81,0x81,0x80,0x80,0x80,0x80,0x80,0x83,
0x83,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x83,0x83,0x80,0x80,0x80,0x80,0x80,
0x80,0x80,0x80,0x80,0x80,0x80,0x81,0x81,0x80,0x80,0x80,0x80,0x83,0x83,0x80,0x80,
0x80,0x80,0x80,0x80,0x80,0x82,0x83,0x81,0x80,0x80,0x81,0x83,0x83,0x81,0x80,0x80,
0x80,0x80,0x80,0x81,0x81,0x81,0x81,0x80,0x80,0x80,0x81,0x81,0x81,0x81,0x80,0x80,
0x80,0x80,0x80,0x81,0x81,0x80,0x80,0x80,0x80,0x83,0x83,0x80,0x80,0x80,0x80,0x80,
0x81,0x83,0x83,0x81,0x81,0x81,0x80,0x80,0x81,0x81,0x81,0x81,0x80,0x80,0x80,0xFF,
};
void Init_ST7567();
void Write_ST7567_COM(unchar COMDADA_4SPI);
void Write_ST7567_DISPLAY_DATA_serial_4SPI(unchar DADA_4SPI);
void Delay_ms(unsigned long value);
void HDReset();
void Keypress(void);
void clear_screen(unchar xx);
void Display_pic1();
void main()
{
// Write_ST7567_COM(0xe2);
// SCL=1;
Init_ST7567();
while(1)
{
// clear_screen(0x33);
// Keypress();
// clear_screen(0xff);
// Keypress();
// clear_screen(0x55);
// Keypress();
// clear_screen(0xaa);
// Keypress();
// Display_pic1();
// Keypress();
// Write_ST7567_COM(0xa7); // //0xa6正向显示,0xa7反向显示
Display_pic1();
Keypress();
}
}
//--------------------------------------------------------------------------
void Init_ST7567()
{
HDReset();
Delay_ms(100);
Write_ST7567_COM(0xe2); //SOFT RESET//寄存器复位
Write_ST7567_COM(0xaf); //0xaf显示器开
Write_ST7567_COM(0x2f); //0x2f升压电路,电压管理电路,
Write_ST7567_COM(0x25); //0x20-0x27为V5电压内部电阻调整设置
Write_ST7567_COM(0x81); // SET EV 调对比度
Write_ST7567_COM(0x1F); //0x01-0x3f电量寄存器设置模式
Write_ST7567_COM(0xa0); //0xa0为Segment正向,0xa1 为Segment反向
Write_ST7567_COM(0xc8); //0xc0正向扫描,0xc8反射扫描
Write_ST7567_COM(0xa6); // //0xa6正向显示,0xa7反向显示
Write_ST7567_COM(0xa4); // //0xa4正常显示,0xa5全屏点亮
// Write_ST7567_COM(0xac); //
// Write_ST7567_COM(0x00);
Write_ST7567_COM(0xf8); // //背压比设置
Write_ST7567_COM(0x00); //00--10
}
void clear_screen(unchar xx)
{
unchar i,j;
for(i=0;i<8;i++)
{
CS0=0;
Write_ST7567_COM(0xb0+i); //SET PAGE 0---8
Write_ST7567_COM(0x10); //SET COLUMN MSB
Write_ST7567_COM(0x00); //SET CLUMN LSB
for(j=0;j<128;j++)
{
Write_ST7567_DISPLAY_DATA_serial_4SPI(xx);
}
}
}
void Display_pic1()
{
unint i,j,adressd=0;
for(i=0;i<8;i++)
{
CS0=0;
Write_ST7567_COM(0xb0+i);
Write_ST7567_COM(0x10);
Write_ST7567_COM(0x00);
for(j=0;j<128;j++)
{
Write_ST7567_DISPLAY_DATA_serial_4SPI(graphic1[adressd]);
adressd++;
}
}
}
//***************************************************************************SPI4
void Write_ST7567_COM(unchar COMDADA_4SPI)
{
unchar bit8;
A0=0;
CS0=0;
for(bit8=0;bit8<8;bit8++)
{
Delay_ms(10);
SCL=0;
Delay_ms(10);
if((COMDADA_4SPI&0x80)==0x80)
SDI=1;
else
SDI=0;
Delay_ms(10);
SCL=1;
Delay_ms(10);
COMDADA_4SPI=(COMDADA_4SPI<<1);
}
CS0=1;
}
void Write_ST7567_DISPLAY_DATA_serial_4SPI(unchar DADA_4SPI)
{
unchar bit8;
A0=1;
CS0=0;
for(bit8=0;bit8<8;bit8++)
{
Delay_ms(10);
SCL=0;
Delay_ms(10);
if((DADA_4SPI&0x80)==0x80)
SDI=1;
else
SDI=0;
Delay_ms(10);
SCL=1;
DADA_4SPI=(DADA_4SPI<<1);
}
CS0=1;
}
void Delay_ms(unsigned long value)
{
unint i,j;
for (i=0;i<value;i++)
for (j=0;j<500;j++);
}
void HDReset()
{
RSTB=0;
Delay_ms(2);
RSTB=1;
Delay_ms(4);
}
void Keypress()
{
while(KEY)
Delay_ms(10);
}
|