📄 ssd1852(ref).c
字号:
/* Prog: 1852ta2_0.c
Device: SSD1852T2
Descp: 1852T2 Demo for EVM89c52-1-a2
Panel Size: 128x128
Page Order: F 0 7 8 9 A B C 1 2 3 4 5 6 D E
written by: Vanessa Tang
Date: 20020306
Structure: A) Hardware Interface
B) Command Table per device
C) Global Variables Definition
D) Function Prototypes
E) Main Function
Notes: S3-Pause S4-Inc Contrast
S5-Dec Contrast S6-Display On/Off */
/****************************************************
* A) Hardware Interface *
****************************************************/
#include "reg51.h"
#define dataport P1
#define PORT_SELECT P3
/****************************************************
* B) Command Table per device *
****************************************************/
#define PORT_A 0x8F
#define PORT_B 0x9F
#define PORT_C 0xAF
#define CNTL_PORT 0xBF
#define delay_time 40
int irsvalue = 7; // Valid range: 0 to 7
int contrast = 0x30; // Valid range: 0 to 63 (2A,30)
/****************************************************
* C) Global Variable Definition *
****************************************************/
unsigned char page = 16;
unsigned char SW_counter[4] = {0x00, 0x00, 0x00, 0x00};
/* Samll Solomon logo with text*/
unsigned char code Logo_SSL[ ]={0xFF, 0xFF, ………………, 0x00, 0x00};
unsigned char code Contrast_LVL[ ]={0x00, 0x00, ………………, 0x00, 0x00} ;
unsigned char code C_remap[ ]={0x00, 0x00, ………………, 0x00, 0x00} ;
unsigned char code S_remap[ ]={0x00, 0x00, ………………, 0x00, 0x00} ;
/* Large Solomon Logo */
unsigned char code pattern0[ ]={0x00, 0x00, ………………, 0x00, 0x00} ;
Solomon Systech Aug 2002 P 4 Rev 0.2 SSD1852T2
/* Chinese Solomon Logo */
unsigned char code title0[]={0x00, 0x00, ………………, 0x00, 0x00};
/* SSD1852 device name */
unsigned char code title1[]={0x00, 0x00, ………………, 0x00, 0x00};
unsigned char code L_CHK[ ]={0xff, 0xff, ………………, 0x00, 0x00} ;
/* Resoluation 128SEG x 128COM +1 ICOM */
unsigned char code resol[ ]={0x00, 0x00, ………………, 0x00, 0x00} ;
unsigned char code pack[ ]={0x00, 0x00, ………………, 0x00, 0x00} ;
unsigned char code web[ ]={0x00, 0x00, ………………, 0x00, 0x00};
unsigned char code thank[]={0x00, 0x00, ………………, 0x00, 0x00};
unsigned char code star[]={0x00, 0x00, ………………, 0x00, 0x41} ;
/****************************************************
* D) Function Prototypes*
****************************************************/
void delay(unsigned int n);
void init_lcd(void);
void comm_out(char command1);
void data_out(char data1);
void write_demo1();
void write_logo(void);
void write_level(void);
void write_cmap(void);
void write_smap(void);
void write_lvlbar(int);
void con_inc(int i);
void con_dec(int i);
void color_inc(void);
void color_dec(void);
void blink(char);
/****************************************************
* delay Function*
****************************************************/
void delay(unsigned int n)/* wait n seconds*/
{
unsigned int i, j, k;
unsigned char key;
for (k=0;k<n;k++)
{
key = 0;
key = PORT_SELECT & 0x08;
if (key==0)
{
SW_counter[1]++;
if((SW_counter[1]%2)!=0)
{
Comm_out(0xAE);
Comm_out(0xA6);
}
else
{
Comm_out(0xAF);
Comm_out(0xA6);
}
for (i=0;i<500;i++)
for (j=0;j<200;j++) {;}
}
key = 0;
key = PORT_SELECT & 0x04;
if (SW_counter[2]==0)
if ((key==0)&&(contrast<63))
{
Comm_out(0x81);
Comm_out(++contrast);
}
key = 0;
key = PORT_SELECT & 0x02;
if (SW_counter[3]==0)
if ((key==0)&&(contrast>1))
{
Comm_out(0x81);
Comm_out(--contrast);
}
key = 0;
key = PORT_SELECT & 0x01;
if (key==0)
{
for (i=0;i<500;i++)
for (j=0;j<200;j++) {;}
key = PORT_SELECT & 0x01;
do
{
key = PORT_SELECT & 0x01;
} while(key!=0);
for (i=0;i<500;i++)
for (j=0;j<200;j++) {;}
}
for (i=0;i<40;i++)
for (j=0;j<70;j++) {;}
}
}
/****************************************************
* outport Function*
****************************************************/
void outport(int address, int data1)
{dataport = data1;
PORT_SELECT = 0xFF;
PORT_SELECT = address;
PORT_SELECT = 0xFF;
}
/****************************************************
* initial Function*
****************************************************/
void init_lcd()
{
comm_out(0xab); // start build in oscillator
comm_out(0xe0); // set modify-read mode
comm_out(0x96); // set FRC and PWM mode; 4 phase, 15 level
comm_out(0x88); //set white mode and 1st/2nd frame, set pulse width
comm_out(0x00);
comm_out(0x89); //set white mode and 3rd/4th frame, set pulse width
comm_out(0x00);
comm_out(0x8a); //set light gray mode and 1st/2nd frame, set pulse width
comm_out(0x09);
comm_out(0x8b); //set light gray mode and 3rd/4th frame, set pulse width
comm_out(0x00);
comm_out(0x8c); //set dark gray mode and 1st/2nd frame, set pulse width
comm_out(0x99);
comm_out(0x8d); //set dark gray mode and 3rd/4th frame, set pulse width
comm_out(0x00);
comm_out(0x8e); //set dark mode and 1st/2nd frame, set pulse width
comm_out(0x99);
comm_out(0x8f); //set dark mode and 3rd/4th frame, set pulse width
comm_out(0x99);
comm_out(0x40); //set initial display line register
comm_out(0x06);
comm_out(0x44); //set initial COM0 register
comm_out(0x8e);
comm_out(0x48); //set partial display duty ratio (mux ratio)
comm_out(0x80);
comm_out(0x4c); //set N-line inversion
comm_out(0x00);
comm_out(0xa6); // Normal display;
comm_out(0xa4); //entire display off;
comm_out(0x2f); //enable booster, divider and output op-amp
comm_out(0x67); //6x dc-dc
comm_out(0x27); //set contrast
comm_out(0x81); //select contrast level
comm_out(contrast);
comm_out(0x57); //select LCD bias 1/12
comm_out(0xc8); // reverse direction (COM)
comm_out(0xaf); //display on
}
/****************************************************
* comm_out Function*
****************************************************/
void comm_out(char command1)
{
outport(PORT_B, command1);
outport(PORT_A, 0x1D); //rw:0 rs:0 e:0 res:1 x x x cs:1
outport(PORT_A, 0x3f); //rw:0 rs:0 e:1 res:1 x x x cs:1
outport(PORT_A, 0x3e); //rw:0 rs:0 e:1 res:1 x x x cs:0
outport(PORT_A, 0x3f); //rw:0 rs:0 e:1 res:1 x x x cs:1
outport(PORT_A, 0x1D); //rw:0 rs:0 e:0 res:1 x x x cs:1
outport(PORT_B, 0xfD);
}
/****************************************************
* data_out Function*
****************************************************/
void data_out(char data1)
{
outport(PORT_B, data1);
outport(PORT_A, 0x5D);//rw:0 rs:1 e:0 res:1 x x x cs:1
outport(PORT_A, 0x7f);//rw:0 rs:1 e:1 res:1 x x x cs:1
outport(PORT_A, 0x7e);//rw:0 rs:1 e:1 res:1 x x x cs:0
outport(PORT_A, 0x7f);//rw:0 rs:1 e:1 res:1 x x x cs:1
outport(PORT_A, 0x5D);//rw:0 rs:1 e:0 res:1 x x x cs:1
outport(PORT_B, 0xff);
}
/****************************************************
* write_logo Function*
****************************************************/
void write_logo(void)
{
int i, j;
for(i=0;i<page;i++)
{
comm_out(0xB0+i); // Set page address
comm_out(0x00); // Lower col address = 0000
comm_out(0x10); // Higher col address = 0000
for(j=0;j<256;j++)
data_out(pattern0[i*256+j]);
}
}
/****************************************************
* write_resol Function*
****************************************************/
void write_resol(void)
{
int i, j;
for(i=0;i<page;i++)
{
comm_out(0xB0+i); // Set page address
comm_out(0x00); // Lower col address = 0000
comm_out(0x10); // Higher col address = 0000
for(j=0;j<256;j++)
data_out(resol[i*256+j]);
}
}
/****************************************************
* write_lchk Function*
****************************************************/
void write_lchk(void)
{
int i, j;
f
or (i=0;i<page;i++)
{
comm_out(0xb0+i);
comm_out(0x10);
comm_out(0x00);
for(j=0;j<256;j++)
data_out(L_CHK[i*256+j]);
}
}
/****************************************************
* write_level Function*
****************************************************/
void write_level(void)
{
int i, j, k;
write_demo1();
for(i=0;i<=3;i++)
{
comm_out(0xB3+i);
comm_out(0x00); // Lower col address = 0000
comm_out(0x10); // Higher col address = 0000
for(j=0;j<256;j++)
data_out(Contrast_LVL[i*256+j]);
}
comm_out(0xBD);
comm_out(0x00); // Lower col address = 0000
comm_out(0x10); // Higher col address = 0000
for(j=0;j<256;j++)
data_out(Contrast_LVL[i*256+j]);
blink(3);
k=contrast;
write_lvlbar(k);
delay(delay_time);
for(i=contrast;i>=8;i--)
{
con_dec(i);
write_lvlbar(i);
}
for(i=0;i<=k;i++)
{
con_inc(i);
write_lvlbar(i);
}
delay(delay_time);
comm_out(0xBE);
comm_out(0x00); // Lower col address = 0000
comm_out(0x10); // Higher col address = 0000
for(j=0;j<256;j++)
{
data_out(0x00);
data_out(0x00);
}
}
/****************************************************
* write_lvlbar Function*
****************************************************/
void write_lvlbar(int i)
{
int j;
comm_out(0xBE);
comm_out(0x00); // Lower col address = 0000
comm_out(0x10); // Higher col address = 0000
for(j=0;j<(i*2+26);j++)
{
data_out(0xff);
data_out(0xff);
}
for(j=i*2+26;j<128;j++)
{
data_out(0x00);
data_out(0x00);
}
}
/****************************************************
* write_cmap Function*
****************************************************/
void write_cmap(void)
{
int i, j;
write_demo1();
for(i=0;i<=3;i++)
{
comm_out(0xB3+i);
comm_out(0x00); // Lower col address = 0000
comm_out(0x10); // Higher col address = 0000
for(j=0;j<256;j++)
data_out(C_remap[i*256+j]);
}
comm_out(0xBD);
comm_out(0x00); // Lower col address = 0000
comm_out(0x10); // Higher col address = 0000
for(j=0;j<256;j++)
data_out(C_remap[i*256+j]);
blink(3);
delay(delay_time/2);
comm_out(0xc8);
delay(delay_time/2);
comm_out(0xc0);
delay(delay_time/2);
comm_out(0xc8);
delay(delay_time/2);
comm_out(0xc0);
delay(delay_time/2);
comm_out(0xc8);
delay(delay_time/2);
}
/****************************************************
* write_smap Function*
****************************************************/
void write_smap(void)
{
int i, j, k;
write_demo1();
for(i=0;i<=3;i++)
{
comm_out(0xB3+i);
comm_out(0x00); // Lower col address = 0000
comm_out(0x10); // Higher col address = 0000
for(j=0;j<256;j++)
data_out(S_remap[i*256+j]);
}
comm_out(0xBD);
comm_out(0x00); // Lower col address = 0000
comm_out(0x10); // Higher col address = 0000
for(j=0;j<256;j++)
data_out(S_remap[i*256+j]);
blink(3);
delay(delay_time/2);
for(k=1;k<=2;k++)
{
comm_out(0xA1);
write_demo1();
for(i=0;i<=3;i++)
{
comm_out(0xB3+i);
comm_out(0x00); // Lower col address = 0000
comm_out(0x10); // Higher col address = 0000
for(j=0;j<256;j++)
data_out(S_remap[i*256+j]);
}
comm_out(0xBD);
comm_out(0x00); // Lower col address = 0000
comm_out(0x10); // Higher col address = 0000
for(j=0;j<256;j++)
data_out(S_remap[i*256+j]);
delay(delay_time/2);
comm_out(0xA0);
write_demo1();
for(i=0;i<=3;i++)
{
comm_out(0xB3+i);
comm_out(0x00); // Lower col address = 0000
comm_out(0x10); // Higher col address = 0000
for(j=0;j<256;j++)
data_out(S_remap[i*256+j]);
}
comm_out(0xBD);
comm_out(0x00); // Lower col address = 0000
comm_out(0x10); // Higher col address = 0000
for(j=0;j<256;j++)
data_out(S_remap[i*256+j]);
delay(delay_time/2);
}
}
/****************************************************
* con_inc Function*
****************************************************/
void con_inc(int i)
{
if (++i > 63)
i = 63;
comm_out(0x81);// Set contrast 1
comm_out(0x00+i); // Set contrast 2
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -