⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ssd1303.c

📁 freescale hc08 T6963 160*80 LCD驱动
💻 C
字号:
#define uchar unsigned char
#define uint unsigned int

#define SSD1303_DATA  PTA

#define C_RES    P3_0
#define C_RD     P3_1
#define C_INT0   P3_2
#define C_INT1   P3_3
#define C_DC     P3_4
#define C_CS     P3_5
#define C_WR     P3_6

void init_oled();
write_data(uchar Data);
write_user_data(uchar xp,uchar ep,uchar xa,uchar ea,uchar Data);
write_picdata(uchar xp,uchar ep,uchar xa,uchar ea,uint Data);
void delay(int de);
void comm_out2(uchar xCmd);
void data_out2(uchar xData);
void pic_scroll();


void main(void)
{
C_RES=0;
delay(5);
C_RES=1;
delay(5);
C_RD=1;
init_oled();
delay(10);
while(1)
{
write_data(0xFF);
while(C_INT0);
while(!C_INT0);
write_data(0xAA);
while(C_INT0);
while(!C_INT0);
write_data(0x55);
while(C_INT0);
while(!C_INT0);
write_data(0xCC);
while(C_INT0);
while(!C_INT0);
write_data(0x33);
while(C_INT0);
while(!C_INT0);
write_data(0x0F);
while(C_INT0);
while(!C_INT0);
write_data(0xF0);
while(C_INT0);
while(!C_INT0);
write_picdata(0,5,8,87,0x0400);
pic_scroll();
write_picdata(0,5,8,87,0x0800);
pic_scroll();
write_user_data(0,5,8,87,0); //Clear window
write_user_data(0,0,8,87,0x01); //Draw square start
write_user_data(5,5,8,87,0x80); //
write_user_data(0,5,8,8,0xFF); //
write_user_data(0,5,87,87,0xFF);//Draw square end
while(C_INT0);
while(!C_INT0);
}
}

void pic_scroll() //Up-Down scrolling
{
int i;
while(C_INT0)
{
for(i=0;i<=64;i++)
{
comm_out2(0xD3);
if(i<47)
{
comm_out2(0x10+i);
}
else
{
comm_out2(i-48);
}
if(C_INT0==0) break;
delay(100);
}
for(i=63;i>=0;i--)
{
comm_out2(0xD3);
if(i>=48)
{
comm_out2(0x10-(64-i));
}
else
{
comm_out2(0x10+i);
}
if(C_INT0==0) break;
delay(100);
}
comm_out2(0xD3); //Set COM offset
comm_out2(0x10); //second byte
}
}

void init_oled() //P09702Initial code
{
comm_out2(0xAE); //Display off
comm_out2(0xAD); //Internal DC-DC off
comm_out2(0x8A); // Second byte
comm_out2(0xA8); //MUX Ratio
comm_out2(0x3F); //64 duty
comm_out2(0xD3); //Display offset
comm_out2(0x00); //Second byte
comm_out2(0x40); //Start line
comm_out2(0xA1); //Segment remap
comm_out2(0xC8); //COM remap
comm_out2(0xA6); //Set normal/inverse display (0xA6:Normal display)
comm_out2(0xA4); //Set entire display on/off (0xA4:Normal display)
comm_out2(0x81); //Contrast setting
comm_out2(0x5C); //Second byte
comm_out2(0xD5); //Frame rate
comm_out2(0x60); // 85 Hz
comm_out2(0xD8); //Mode setting
comm_out2(0x00); //Mono mode
comm_out2(0xD9); //Set Pre-charge period
comm_out2(0x84); // Second byte
comm_out2(0xAF); //Display on
}

write_data(uchar Data)
{
int j, i;
for(i=0;i<6;i++)
{
comm_out2(0xB0+i); //set page
comm_out2(0x08); // Lower col address
comm_out2(0x10); // Higher col address
for(j=0;j<80;j++) //out data
data_out2(Data);
}
}

write_user_data(uchar xp,uchar ep,uchar xa,uchar ea,uchar Data)
{
int j, i;
for(i=xp;i<=ep;i++)
{
comm_out2(0xB0+i); //set page
comm_out2(0x0F&xa); // Lower col address
comm_out2(((xa&0xF0)>>4)|0x10); // Higher col address
for(j=xa;j<=ea;j++) //out data
data_out2(Data);
}
}

write_picdata(uchar xp,uchar ep,uchar xa,uchar ea,uint Data)
{
int i,j;
for(j=xa;j<=ea;j++)
{
for(i=ep;i>=xp;i--)
{
comm_out2(0x0F&j); // Lower col address
comm_out2(((j&0xF0)>>4)|0x10); // Higher col address
comm_out2(0xB0+i); //set page
data_out2(CBYTE[Data++]);
//delay(10);
}
Data++;
Data++;
}

}

void delay(uint de)
{
de *=100;
while(de--);
}

void comm_out2(uchar xCmd)
{
C_CS=0;
C_DC=0;
C_WR=0;
//P3=P3 & 0x8F;
P1=xCmd;
//P3=P3 | 0x60;
C_WR=1;
C_CS=1;
}

void data_out2(uchar xData)
{
C_CS=0;
C_DC=1;
C_WR=0;
//P3=P3 & 0x9F;
P1=xData;
//P3=P3 | 0x60;
C_WR=1;
C_CS=1;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -