C8051F040 端口配置及IIC问题请教

2020-01-20 19:04发布

本帖最后由 wei9098 于 2014-2-23 17:58 编辑

#include "reg52.h"
sbit LCD_SCL=P0^3; //时钟 D0(SCLK)
sbit LCD_SDA=P0^2; //D1(MOSI) 数据
sbit LCD_RST=P1^7; //复位
sbit LCD_DC =P1^6; //数据/命令控制

#define X_WIDTH 128
#define Y_WIDTH 64


void LCD_DLY_ms(unsigned int ms)
{                        
unsigned int a;
while(ms)
{
a=1800;
while(a--);
ms--;
}
return;
}

void LCD_WrDat(unsigned char dat)         
{
unsigned char i;
LCD_DC=1;  
for(i=0;i<8;i++) //发送一个八位数据
{
if((dat << i) & 0x80)
{LCD_SDA  = 1;}
else  LCD_SDA  = 0;
LCD_SCL = 0;
LCD_SCL = 1;
}
}

void LCD_WrCmd(unsigned char cmd)
{
unsigned char i;
LCD_DC=0;
for(i=0;i<8;i++) //发送一个八位数据
{
if((cmd << i) & 0x80)
{LCD_SDA  = 1;}
else  LCD_SDA  = 0;
LCD_SCL = 0;
LCD_SCL = 1;
}
}

/*********************LCD 设置坐标************************************/
void LCD_Set_Pos(unsigned char x, unsigned char y)
{
LCD_WrCmd(0xb0+y);
LCD_WrCmd(((x&0xf0)>>4)|0x10);
LCD_WrCmd((x&0x0f)|0x01);
}

void LCD_Fill(unsigned char bmp_dat)
{
unsigned char y,x;
for(y=0;y<8;y++)
{
LCD_WrCmd(0xb0+y);
LCD_WrCmd(0x01);
LCD_WrCmd(0x10);
for(x=0;x<X_WIDTH;x++)
LCD_WrDat(bmp_dat);
}
}

void LCD_Init(void)     
{  
LCD_SCL=1;
LCD_RST=0;
LCD_DLY_ms(50);
LCD_RST=1;       //从上电到下面开始初始化要有足够的时间,即等待RC复位完毕   
LCD_WrCmd(0xae);//--turn off oled panel
LCD_WrCmd(0x00);//---set low column address
LCD_WrCmd(0x10);//---set high column address
LCD_WrCmd(0x40);//--set start line address  Set Mapping RAM Display Start Line (0x00~0x3F)
LCD_WrCmd(0x81);//--set contrast control register
LCD_WrCmd(0xcf); // Set SEG Output Current Brightness
LCD_WrCmd(0xa1);//--Set SEG/Column Mapping     0xa0左右反置 0xa1正常
LCD_WrCmd(0xc8);//Set COM/Row Scan Direction   0xc0上下反置 0xc8正常
LCD_WrCmd(0xa6);//--set normal display
LCD_WrCmd(0xa8);//--set multiplex ratio(1 to 64)
LCD_WrCmd(0x3f);//--1/64 duty
LCD_WrCmd(0xd3);//-set display offset        Shift Mapping RAM Counter (0x00~0x3F)
LCD_WrCmd(0x00);//-not offset
LCD_WrCmd(0xd5);//--set display clock divide ratio/oscillator frequency
LCD_WrCmd(0x80);//--set divide ratio, Set Clock as 100 Frames/Sec
LCD_WrCmd(0xd9);//--set pre-charge period
LCD_WrCmd(0xf1);//Set Pre-Charge as 15 Clocks & Discharge as 1 Clock
LCD_WrCmd(0xda);//--set com pins hardware configuration
LCD_WrCmd(0x12);
LCD_WrCmd(0xdb);//--set vcomh
LCD_WrCmd(0x40);//Set VCOM Deselect Level
LCD_WrCmd(0x20);//-Set Page Addressing Mode (0x00/0x01/0x02)
LCD_WrCmd(0x02);//
LCD_WrCmd(0x8d);//--set Charge Pump enable/disable
LCD_WrCmd(0x14);//--set(0x10) disable
LCD_WrCmd(0xa4);// Disable Entire Display On (0xa4/0xa5)
LCD_WrCmd(0xa6);// Disable Inverse Display On (0xa6/a7)
LCD_WrCmd(0xaf);//--turn on oled panel
LCD_Fill(0x00);  //初始清屏
LCD_Set_Pos(0,0);        
}


void main(void)
{
        LCD_Init(); //oled 初始化  
        while(1)
{
        LCD_Fill(0xff); //屏全亮

}

}
这是我一个可以再STC51上运行的点亮OLED的程序,4线SPI方式,想移植到C8051F040上,但是没用过,4线SPI方式,按C8051F040数据手册配置I/O口一直点不亮,求大神指点一下,万分感谢!
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。