打印

在89C51上面可以运行在C8051F347上面就不行了

[复制链接]
3428|13
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
本帖最后由 dccdaa2222 于 2010-12-8 22:52 编辑

高手帮我看看,,我是菜鸟。。。在网上下了一个OLED的驱动程序。正好公司有用新华龙的单片机。手上刚好有块OLED的屏。想把他点亮。没想到却编都编不过。。晕
     顺便说明一下。单片机是:C8051F347  OLED屏的型号是TOD9M0041-G。
有知道的高手指点一下。
代码如下:
include <c8051F340.h>
//#include <stdio.h>
//#include <stdlib.h>
#include "intrins.h"
#include <string.h>
void Sysclk_Init (void);
void Port_Init (void);
#define NOP _nop_();_nop_();_nop_();_nop_()
#define Woled_Data P1;
sbit  Woled_CS  =P2^3;
sbit  Woled_RES =P2^2;
sbit  Woled_A0  =P2^1;//SSD1303_DC//
sbit  Woled_WR  =P2^0;
sbit  Woled_RD  =P0^5;
unsigned char code matrix1[128]={ //王,32*32
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x10,0x00,0x00,
0x00,0x18,0x04,0x00,0x00,0x18,0x06,0x00,0x00,0x18,
0x06,0x00,0x80,0x18,0x06,0x01,0x80,0x18,0x06,0x01,
0x80,0x18,0x06,0x01,0x80,0x18,0x06,0x01,0x80,0x18,
0x06,0x01,0x80,0x18,0x06,0x01,0x80,0x18,0x06,0x01,
0x80,0x18,0x06,0x01,0x80,0x18,0x06,0x01,0x80,0x18,
0x07,0xFF,0xFF,0xF8,0x07,0xFF,0xFF,0xF8,0x07,0xFF,
0xFF,0xF8,0x06,0x01,0x80,0x18,0x06,0x01,0x80,0x18,
0x06,0x01,0x80,0x18,0x06,0x01,0x80,0x18,0x06,0x01,
0x80,0x18,0x06,0x01,0x80,0x18,0x06,0x01,0x80,0x18,
0x0E,0x03,0x80,0x18,0x0E,0x01,0x80,0x18,0x0E,0x00,
0x80,0x38,0x06,0x00,0x00,0x78,0x00,0x00,0x00,0x38,
0x00,0x00,0x00,0x18,0x00,0x00,0x00,0x00
};
unsigned char code matrix2[128]={ //利,32*32
0x00,0x00,0x00,0x00,0x00,0x10,0x00,0xC0,0x00,0x18,
0x01,0xC0,0x04,0x18,0x03,0x80,0x04,0x10,0x07,0x00,
0x0C,0x10,0x1E,0x00,0x0C,0x10,0x7C,0x00,0x0C,0x10,
0xF0,0x00,0x0C,0x17,0xE0,0x00,0x0C,0x1F,0xC0,0x00,
0x1F,0xFF,0xFF,0xFE,0x1F,0xFF,0xFF,0xFE,0x1F,0xFF,
0xFF,0xFC,0x38,0x11,0x80,0x00,0x38,0x11,0xC0,0x00,
0x78,0x10,0xF0,0x00,0x78,0x30,0xF8,0x00,0x38,0x70,
0x78,0x00,0x10,0x30,0x38,0x00,0x00,0x10,0x00,0x00,
0x07,0xFF,0xFF,0x00,0x07,0xFF,0xFF,0x18,0x03,0xFF,
0xFE,0x18,0x02,0x00,0x00,0x18,0x00,0x00,0x00,0x1C,
0x00,0x00,0x00,0x1E,0x00,0x00,0x00,0x1E,0x7F,0xFF,
0xFF,0xFE,0x7F,0xFF,0xFF,0xFC,0x3F,0xFF,0xFF,0xF0,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
};
unsigned char code matrix3[128]={ //明,32*32
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x3F,0xFF,0xFF,0xF8,0x3F,0xFF,0xFF,0xFC,
0x1F,0xFF,0xFF,0xFE,0x18,0x60,0x80,0x38,0x18,0x60,
0x80,0x38,0x18,0x60,0x80,0x70,0x18,0x60,0x80,0x60,
0x18,0x60,0x80,0xE0,0x18,0x60,0x80,0xC0,0x18,0x60,
0x80,0x80,0x18,0x7F,0x81,0x80,0x18,0x7F,0xE0,0x00,
0x18,0x7F,0xFC,0x00,0x18,0x60,0xFF,0x00,0x18,0x60,
0x8F,0x80,0x18,0x60,0x83,0xE0,0x18,0x60,0x81,0xE0,
0x18,0x60,0x80,0xF0,0x18,0x60,0x80,0x78,0x3F,0xF8,
0x80,0x3C,0x3F,0xF8,0x80,0x1C,0x1F,0xF0,0x80,0x1C,
0x00,0x01,0x80,0x1E,0x00,0x03,0x80,0xFE,0x00,0x01,
0x83,0xFE,0x00,0x00,0x80,0x0E,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
};
void Delay_us(unsigned char times)
{
unsigned char i,j;
for(i=0;i<times;i++){
    for(j=0;j<24;j++)
   _nop_();
   }
}
void System_Init (void)
{
   PCA0MD &= ~0x40;                    // Disable Watchdog timer
   PCA0MD  = 0x00;
   Sysclk_Init ();                     // initialize system clock
   Port_Init ();                    // configure cross bar
}
void Sysclk_Init (void)
{
//24MHz
    int i = 0;
    CLKMUL    = 0x80;
    for (i = 0; i < 20; i++);    // Wait 5us for initialization
    CLKMUL    |= 0xC0;
    while ((CLKMUL & 0x20) == 0);
    CLKSEL    = 0x02;
    OSCICN    = 0x83;
}
void Port_Init()
{
    XBR0      = 0x04;
    XBR1      = 0xC0;
}
void Woled_init(void)
{
Woled_RES=0;
Delay_us(30);
Woled_RES=1;
Delay_us(20);
Woled_Command(0xAE); //DOT MARTIX DISPLAY OFF
Woled_Command(0x40); //SET DISPLAY START LINE(40H-7FH)
Woled_Command(0xA1); //SET SEGMENT RE-MAP(0A0H-0A1H)
Woled_Command(0xA4); //ENTIRE DISPLAY OFF(0A4H-0A5H)
Woled_Command(0xA6); //SET NORMAL DISPLAY(0A6H-0A7H)
Woled_Command(0xC8); //COM SCAN COM1-COM64(0C8H,0C0H)
Woled_Command(0xA8); //SET MULTIPLEX RATIO 64
Woled_Command(0x3F);
Woled_Command(0xD3); //SET DISPLAY OFFSET(OOH-3FH)
Woled_Command(0x00);
Woled_Command(0xD5); //SET FRAME FREQUENCY
Woled_Command(0x50); //100Hz
Woled_Command(0xD9); //SET DIS-/PRE-_CHARGE PERIOD
Woled_Command(0x23);
Woled_Command(0xDA); //COM PIN CONFIGURATION(02H,12H)
Woled_Command(0x12);
Woled_Command(0xDB); //SET VCOM DESELECT LEVEL(035H)
Woled_Command(0x35);
Woled_Command(0x81); //CONTARST CONTROL(00H-0FFH)
Woled_Command(0x4F);
Woled_Command(0xAD); //SET DC/DC BOOSTER(8AH=OFF,8BH=ON)
Woled_Command(0x8A);
Woled_Command(0xAF); //DSPLAY ON
}
void Woled_Command(unsigned char command)
{
Woled_A0=0;
_nop_();
Woled_CS=0;
_nop_();
Woled_RD=1;
Woled_WR=0;
_nop_();
Woled_Data=command;
Delay_us(1);
Woled_WR=1;
_nop_();
Woled_CS=1;
}
void Woled_Data(unsigned char dat)
{
Woled_A0=1;
_nop_();
Woled_CS=0;
_nop_();
Woled_RD=1;
Woled_WR=0;
_nop_();
P1=dat;
_nop_();
Woled_WR=1;
_nop_();
Woled_CS=1;
}
unsigned char ByteInvert(unsigned char chSrc)
{
unsigned chDst=0;
if (chSrc & 0x80) chDst |= 0x01;
if (chSrc & 0x40) chDst |= 0x02;
if (chSrc & 0x20) chDst |= 0x04;
if (chSrc & 0x10) chDst |= 0x08;
if (chSrc & 0x08) chDst |= 0x10;
if (chSrc & 0x04) chDst |= 0x20;
if (chSrc & 0x02) chDst |= 0x40;
if (chSrc & 0x01) chDst |= 0x80;
return(chDst);
}

void Woled_Character(unsigned char x,unsigned char y,unsigned char *character)
{
unsigned char i,j;
for(i=0;i<32;i++)
{
   for(j=0;j<4;j++)
   {
   Woled_Command(0xb0+y+j);
   Woled_Command((x+i+31) & 0xf);
   Woled_Command(0x10+((x+i+31)>>4));
   Woled_Data(ByteInvert(*(i*4+j+character)));
   }
}
}
void main(void)
{
unsigned char i;
System_Init();
Woled_init();
Woled_Character(1,1,matrix1);
Woled_Character(33,1,matrix2);
Woled_Character(65,1,matrix3);
while(1);
}

附上工程文件,和资料

qw.jpg (60.63 KB )

qw.jpg

Oled.rar

21.55 KB

SH1101A.pdf

832.31 KB

TOD9M0041-G-E_REV0[1].0.pdf

747.08 KB

C8051F34x中文版.pdf

3.9 MB

相关帖子

沙发
xwj| | 2010-12-8 23:49 | 只看该作者
先要声明函数原型:
void Woled_Command(unsigned char command);
void Woled_Data(unsigned char dat);
....

使用特权

评论回复
板凳
shell.albert| | 2010-12-9 08:49 | 只看该作者
最大的问题可能是时钟的问题,如果使用C8051F的片内振荡的话,时钟是24.5MHz,比传统的8051的外接晶振22.1184MHz或是12MHz要高出很多,这样可能导致信号建立、保持时间太短。

使用特权

评论回复
地板
dccdaa2222|  楼主 | 2010-12-9 09:35 | 只看该作者
谢谢楼上的.试一下.等 下看下结果.

使用特权

评论回复
5
dccdaa2222|  楼主 | 2010-12-9 14:48 | 只看该作者
本帖最后由 dccdaa2222 于 2010-12-9 14:50 编辑

有看到二楼说的.加上后又出现在这[样的问题???晕晕,,,,,,还有人知道是怎 么回事吗?
  修改后的源码:
#include <c8051F340.h>
//#include <stdio.h>
//#include <stdlib.h>
#include "intrins.h"
#include <string.h>
void Sysclk_Init (void);
void Port_Init (void);
void Woled_Command(unsigned char command);
void Woled_Data(unsigned char dat);
#define NOP _nop_();_nop_();_nop_();_nop_()
#define Woled_DATA P1;
sbit  Woled_CS  =P2^3;
sbit  Woled_RES =P2^2;
sbit  Woled_A0  =P2^1;//SSD1303_DC//
sbit  Woled_WR  =P2^0;
sbit  Woled_RD  =P0^5;
unsigned char code matrix1[128]={ //王,32*32
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x10,0x00,0x00,
0x00,0x18,0x04,0x00,0x00,0x18,0x06,0x00,0x00,0x18,
0x06,0x00,0x80,0x18,0x06,0x01,0x80,0x18,0x06,0x01,
0x80,0x18,0x06,0x01,0x80,0x18,0x06,0x01,0x80,0x18,
0x06,0x01,0x80,0x18,0x06,0x01,0x80,0x18,0x06,0x01,
0x80,0x18,0x06,0x01,0x80,0x18,0x06,0x01,0x80,0x18,
0x07,0xFF,0xFF,0xF8,0x07,0xFF,0xFF,0xF8,0x07,0xFF,
0xFF,0xF8,0x06,0x01,0x80,0x18,0x06,0x01,0x80,0x18,
0x06,0x01,0x80,0x18,0x06,0x01,0x80,0x18,0x06,0x01,
0x80,0x18,0x06,0x01,0x80,0x18,0x06,0x01,0x80,0x18,
0x0E,0x03,0x80,0x18,0x0E,0x01,0x80,0x18,0x0E,0x00,
0x80,0x38,0x06,0x00,0x00,0x78,0x00,0x00,0x00,0x38,
0x00,0x00,0x00,0x18,0x00,0x00,0x00,0x00
};
unsigned char code matrix2[128]={ //利,32*32
0x00,0x00,0x00,0x00,0x00,0x10,0x00,0xC0,0x00,0x18,
0x01,0xC0,0x04,0x18,0x03,0x80,0x04,0x10,0x07,0x00,
0x0C,0x10,0x1E,0x00,0x0C,0x10,0x7C,0x00,0x0C,0x10,
0xF0,0x00,0x0C,0x17,0xE0,0x00,0x0C,0x1F,0xC0,0x00,
0x1F,0xFF,0xFF,0xFE,0x1F,0xFF,0xFF,0xFE,0x1F,0xFF,
0xFF,0xFC,0x38,0x11,0x80,0x00,0x38,0x11,0xC0,0x00,
0x78,0x10,0xF0,0x00,0x78,0x30,0xF8,0x00,0x38,0x70,
0x78,0x00,0x10,0x30,0x38,0x00,0x00,0x10,0x00,0x00,
0x07,0xFF,0xFF,0x00,0x07,0xFF,0xFF,0x18,0x03,0xFF,
0xFE,0x18,0x02,0x00,0x00,0x18,0x00,0x00,0x00,0x1C,
0x00,0x00,0x00,0x1E,0x00,0x00,0x00,0x1E,0x7F,0xFF,
0xFF,0xFE,0x7F,0xFF,0xFF,0xFC,0x3F,0xFF,0xFF,0xF0,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
};
unsigned char code matrix3[128]={ //明,32*32
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x3F,0xFF,0xFF,0xF8,0x3F,0xFF,0xFF,0xFC,
0x1F,0xFF,0xFF,0xFE,0x18,0x60,0x80,0x38,0x18,0x60,
0x80,0x38,0x18,0x60,0x80,0x70,0x18,0x60,0x80,0x60,
0x18,0x60,0x80,0xE0,0x18,0x60,0x80,0xC0,0x18,0x60,
0x80,0x80,0x18,0x7F,0x81,0x80,0x18,0x7F,0xE0,0x00,
0x18,0x7F,0xFC,0x00,0x18,0x60,0xFF,0x00,0x18,0x60,
0x8F,0x80,0x18,0x60,0x83,0xE0,0x18,0x60,0x81,0xE0,
0x18,0x60,0x80,0xF0,0x18,0x60,0x80,0x78,0x3F,0xF8,
0x80,0x3C,0x3F,0xF8,0x80,0x1C,0x1F,0xF0,0x80,0x1C,
0x00,0x01,0x80,0x1E,0x00,0x03,0x80,0xFE,0x00,0x01,
0x83,0xFE,0x00,0x00,0x80,0x0E,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
};
void Delay_us(unsigned char times)
{
unsigned char i,j;
for(i=0;i<times;i++){
    for(j=0;j<24;j++)
   _nop_();
   }
}
void System_Init (void)
{
   PCA0MD &= ~0x40;                    // Disable Watchdog timer
   PCA0MD  = 0x00;
   Sysclk_Init ();                     // initialize system clock
   Port_Init ();                    // configure cross bar
}
void Sysclk_Init (void)
{
//24MHz
    int i = 0;
    CLKMUL    = 0x80;
    for (i = 0; i < 20; i++);    // Wait 5us for initialization
    CLKMUL    |= 0xC0;
    while ((CLKMUL & 0x20) == 0);
    CLKSEL    = 0x02;
    OSCICN    = 0x83;
}
void Port_Init()
{
    XBR0      = 0x00;
    XBR1      = 0xC0;
}
void Woled_init(void)
{
Woled_RES=0;
Delay_us(30);
Woled_RES=1;
Delay_us(20);
Woled_Command(0xAE); //DOT MARTIX DISPLAY OFF
Woled_Command(0x40); //SET DISPLAY START LINE(40H-7FH)
Woled_Command(0xA1); //SET SEGMENT RE-MAP(0A0H-0A1H)
Woled_Command(0xA4); //ENTIRE DISPLAY OFF(0A4H-0A5H)
Woled_Command(0xA6); //SET NORMAL DISPLAY(0A6H-0A7H)
Woled_Command(0xC8); //COM SCAN COM1-COM64(0C8H,0C0H)
Woled_Command(0xA8); //SET MULTIPLEX RATIO 64
Woled_Command(0x3F);
Woled_Command(0xD3); //SET DISPLAY OFFSET(OOH-3FH)
Woled_Command(0x00);
Woled_Command(0xD5); //SET FRAME FREQUENCY
Woled_Command(0x50); //100Hz
Woled_Command(0xD9); //SET DIS-/PRE-_CHARGE PERIOD
Woled_Command(0x23);
Woled_Command(0xDA); //COM PIN CONFIGURATION(02H,12H)
Woled_Command(0x12);
Woled_Command(0xDB); //SET VCOM DESELECT LEVEL(035H)
Woled_Command(0x35);
Woled_Command(0x81); //CONTARST CONTROL(00H-0FFH)
Woled_Command(0x4F);
Woled_Command(0xAD); //SET DC/DC BOOSTER(8AH=OFF,8BH=ON)
Woled_Command(0x8A);
Woled_Command(0xAF); //DSPLAY ON
}
void Woled_Command(unsigned char command)
{
Woled_A0=0;
_nop_();
Woled_CS=0;
_nop_();
Woled_RD=1;
Woled_WR=0;
_nop_();
Woled_DATA=command;
Delay_us(1);
Woled_WR=1;
_nop_();
Woled_CS=1;
}
void Woled_Data(unsigned char dat)
{
Woled_A0=1;
_nop_();
Woled_CS=0;
_nop_();
Woled_RD=1;
Woled_WR=0;
_nop_();
P1=dat;
_nop_();
Woled_WR=1;
_nop_();
Woled_CS=1;
}
unsigned char ByteInvert(unsigned char chSrc)
{
unsigned chDst=0;
if (chSrc & 0x80) chDst |= 0x01;
if (chSrc & 0x40) chDst |= 0x02;
if (chSrc & 0x20) chDst |= 0x04;
if (chSrc & 0x10) chDst |= 0x08;
if (chSrc & 0x08) chDst |= 0x10;
if (chSrc & 0x04) chDst |= 0x20;
if (chSrc & 0x02) chDst |= 0x40;
if (chSrc & 0x01) chDst |= 0x80;
return(chDst);
}

void Woled_Character(unsigned char x,unsigned char y,unsigned char *character)
{
unsigned char i,j;
for(i=0;i<32;i++)
{
   for(j=0;j<4;j++)
   {
   Woled_Command(0xb0+y+j);
   Woled_Command((x+i+31) & 0xf);
   Woled_Command(0x10+((x+i+31)>>4));
   Woled_Data(ByteInvert(*(i*4+j+character)));
   }
}
}
void main(void)
{
unsigned char i;
System_Init();
Woled_init();
Woled_Character(1,1,matrix1);
Woled_Character(33,1,matrix2);
Woled_Character(65,1,matrix3);
while(1);
}

使用特权

评论回复
6
jtag_ok| | 2010-12-9 17:00 | 只看该作者
网上的代码可能有错!不要完全相信!

把你的普通51代码传上来!

使用特权

评论回复
7
code-03| | 2010-12-9 17:35 | 只看该作者
#define Woled_DATA P1;
后边不用加冒号,

使用特权

评论回复
8
dccdaa2222|  楼主 | 2010-12-9 22:22 | 只看该作者
应6楼的,传上51代的码。。。。。。。。。。。。。请高手们再帮我看看哈。。。。。。。


#include "reg52.h"
#define SSD_DATA P2
sbit SSD_CS=P3^3;
sbit SSD_RES=P3^4;
sbit SSD_DC=P3^5;
sbit SSD_WR=P3^6;
sbit SSD_RD=P3^7;
unsigned char code matrix1[128]={ //王,32*32
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x10,0x00,0x00,
0x00,0x18,0x04,0x00,0x00,0x18,0x06,0x00,0x00,0x18,
0x06,0x00,0x80,0x18,0x06,0x01,0x80,0x18,0x06,0x01,
0x80,0x18,0x06,0x01,0x80,0x18,0x06,0x01,0x80,0x18,
0x06,0x01,0x80,0x18,0x06,0x01,0x80,0x18,0x06,0x01,
0x80,0x18,0x06,0x01,0x80,0x18,0x06,0x01,0x80,0x18,
0x07,0xFF,0xFF,0xF8,0x07,0xFF,0xFF,0xF8,0x07,0xFF,
0xFF,0xF8,0x06,0x01,0x80,0x18,0x06,0x01,0x80,0x18,
0x06,0x01,0x80,0x18,0x06,0x01,0x80,0x18,0x06,0x01,
0x80,0x18,0x06,0x01,0x80,0x18,0x06,0x01,0x80,0x18,
0x0E,0x03,0x80,0x18,0x0E,0x01,0x80,0x18,0x0E,0x00,
0x80,0x38,0x06,0x00,0x00,0x78,0x00,0x00,0x00,0x38,
0x00,0x00,0x00,0x18,0x00,0x00,0x00,0x00
};
unsigned char code matrix2[128]={ //利,32*32
0x00,0x00,0x00,0x00,0x00,0x10,0x00,0xC0,0x00,0x18,
0x01,0xC0,0x04,0x18,0x03,0x80,0x04,0x10,0x07,0x00,
0x0C,0x10,0x1E,0x00,0x0C,0x10,0x7C,0x00,0x0C,0x10,
0xF0,0x00,0x0C,0x17,0xE0,0x00,0x0C,0x1F,0xC0,0x00,
0x1F,0xFF,0xFF,0xFE,0x1F,0xFF,0xFF,0xFE,0x1F,0xFF,
0xFF,0xFC,0x38,0x11,0x80,0x00,0x38,0x11,0xC0,0x00,
0x78,0x10,0xF0,0x00,0x78,0x30,0xF8,0x00,0x38,0x70,
0x78,0x00,0x10,0x30,0x38,0x00,0x00,0x10,0x00,0x00,
0x07,0xFF,0xFF,0x00,0x07,0xFF,0xFF,0x18,0x03,0xFF,
0xFE,0x18,0x02,0x00,0x00,0x18,0x00,0x00,0x00,0x1C,
0x00,0x00,0x00,0x1E,0x00,0x00,0x00,0x1E,0x7F,0xFF,
0xFF,0xFE,0x7F,0xFF,0xFF,0xFC,0x3F,0xFF,0xFF,0xF0,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
};
unsigned char code matrix3[128]={ //明,32*32
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x3F,0xFF,0xFF,0xF8,0x3F,0xFF,0xFF,0xFC,
0x1F,0xFF,0xFF,0xFE,0x18,0x60,0x80,0x38,0x18,0x60,
0x80,0x38,0x18,0x60,0x80,0x70,0x18,0x60,0x80,0x60,
0x18,0x60,0x80,0xE0,0x18,0x60,0x80,0xC0,0x18,0x60,
0x80,0x80,0x18,0x7F,0x81,0x80,0x18,0x7F,0xE0,0x00,
0x18,0x7F,0xFC,0x00,0x18,0x60,0xFF,0x00,0x18,0x60,
0x8F,0x80,0x18,0x60,0x83,0xE0,0x18,0x60,0x81,0xE0,
0x18,0x60,0x80,0xF0,0x18,0x60,0x80,0x78,0x3F,0xF8,
0x80,0x3C,0x3F,0xF8,0x80,0x1C,0x1F,0xF0,0x80,0x1C,
0x00,0x01,0x80,0x1E,0x00,0x03,0x80,0xFE,0x00,0x01,
0x83,0xFE,0x00,0x00,0x80,0x0E,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
};
//DATE:2009-03-19
//SSD1303 8080 parallel interface
#include "main.h"
#include "intrins.h"
void Delay_us(unsigned char times)
{
unsigned char i,j;
for(i=0;i<times;i++){
    for(j=0;j<24;j++)
   _nop_();
   }
}
void Ssd_Command(unsigned char command){
SSD_DC=0;
_nop_();
SSD_CS=0;
_nop_();
SSD_RD=1;
SSD_WR=0;
_nop_();
SSD_DATA=command;
Delay_us(1);
SSD_WR=1;
_nop_();
SSD_CS=1;
}
void Ssd_Data(unsigned char dat){
SSD_DC=1;
_nop_();
SSD_CS=0;
_nop_();
SSD_RD=1;
SSD_WR=0;
_nop_();
P2=dat;
_nop_();
SSD_WR=1;
_nop_();
SSD_CS=1;
}
void Ssd_Init(void){
SSD_RES=0;
Delay_us(30);
SSD_RES=1;
Delay_us(20);
Ssd_Command(0xae); //display off
Ssd_Command(0x41); //display start line 00000
Ssd_Command(0x81); //contrast
Ssd_Command(0x80);
Ssd_Command(0x82); //brightness
Ssd_Command(0x80);
Ssd_Command(0xa0); //no remap
Ssd_Command(0xa4); //intire display off
Ssd_Command(0xa6); //normal display
Ssd_Command(0xa8); //39 mux
Ssd_Command(39);
Ssd_Command(0xad); //DCDC off
Ssd_Command(0x8a);
Ssd_Command(0xc8); //scan from COM[N-1] to COM0
Ssd_Command(0xd3); //row 0->com 62
Ssd_Command(23);
Ssd_Command(0xd8); //mono mode,normal power mode
Ssd_Command(0x00);
Ssd_Command(0xda); //alternative COM pin configuration
Ssd_Command(0x12);
Ssd_Command(0xaf); //display on
}

unsigned char ByteInvert(unsigned char chSrc){
   unsigned chDst=0;
if (chSrc & 0x80) chDst |= 0x01;
if (chSrc & 0x40) chDst |= 0x02;
if (chSrc & 0x20) chDst |= 0x04;
if (chSrc & 0x10) chDst |= 0x08;
if (chSrc & 0x08) chDst |= 0x10;
if (chSrc & 0x04) chDst |= 0x20;
if (chSrc & 0x02) chDst |= 0x40;
if (chSrc & 0x01) chDst |= 0x80;
return(chDst);
}
void Ssd_Character(unsigned char x,unsigned char y,unsigned char *character){
unsigned char i,j;
for(i=0;i<32;i++){
   for(j=0;j<4;j++){
    Ssd_Command(0xb0+y+j);
    Ssd_Command((x+i+31) & 0xf);
    Ssd_Command(0x10+((x+i+31)>>4));
    Ssd_Data(ByteInvert(*(i*4+j+character)));
   }
}
}
void main(void){
unsigned char i;
Ssd_Init();
Ssd_Character(1,1,matrix1);
Ssd_Character(33,1,matrix2);
Ssd_Character(65,1,matrix3);
while(1);
}

使用特权

评论回复
9
huangqi412| | 2010-12-10 08:51 | 只看该作者
有这空,粗看一遍代码,自己都重新敲过了。

使用特权

评论回复
10
kymcu51| | 2010-12-10 10:40 | 只看该作者
把Silicon IDE的INC文件夹里头文件全部拷贝到Keil  C51的INC目录下的Cygnal子目录里重新试试

使用特权

评论回复
11
dccdaa2222|  楼主 | 2010-12-10 16:37 | 只看该作者
刚刚搞好了,,,高兴中....感 谢7楼2楼的哥们...现在是按5楼的代码去掉P1后面的东东就好了....现在编译顺利通过.....
   我怎 样把20分送出去呢?????有谁知道怎 么送吗???

使用特权

评论回复
12
ningling_21| | 2010-12-10 18:51 | 只看该作者
点击标题栏上的“结贴给分”

使用特权

评论回复
13
dccdaa2222|  楼主 | 2010-12-10 21:05 | 只看该作者
真的很高兴。这里有太多热心的人了。谢谢大家了。分数送出去了。。。。谢谢了!!!!

使用特权

评论回复
14
dwp1112| | 2010-12-11 08:21 | 只看该作者
基础知识!!!

使用特权

评论回复
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

11

主题

42

帖子

1

粉丝