//=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
//
// UG-2864ASYDT01 (2864-27E)
// UG-2864ASYDT02 (2864-28E)
// UG-2864ASYDT03 (2864-31E)
// UG-2864ASYDT04 (2864-32E)
// UG-2864ASYDT05 (2864-33E)
// UG-2864ALBDT05 (2864-34E) Reference Code
//
// Dot Matrix: 128*64
// Driver IC : SSD1325 (Solomon Systech)
// Interface : 8-bit 68XX/80XX Parallel, 4-wire SPI
// Revision :
// Date : 2007/11/25
// Author :
// Editor : Humphrey Lin
//
// Copyright (c) Univision Technology Inc.
//
//=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
#include <at89x51.h>
//#define M68 // 8-bit 68XX Parallel
// BS1=0; BS2=1
#define I80 // 8-bit 80XX Parallel
// BS1=1; BS2=1
//#define SPI // 4-wire SPI
// BS1=0; BS2=0
// The unused pins should be connected with VSS mostly or floating (D2).
// Please refer to the SSD1329 specification for detail.
//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
// Pin Definition
//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
#define xData P1 // Parallel Data Input
#define SCLK P1_0 // Serial Clock Input
#define SDIN P1_1 // Serial Data Input
#define RES P3_3 // Reset
#define CS P3_4 // Chip Select
#define DC P3_2 // Data/Command Control
#define E P3_0 // Read/Write Enable
#define RW P3_1 // Read/Write Select
#define RD P3_0 // Read Signal
#define WR P3_1 // Write Signal
//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
// Delay Time
//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
void uDelay(unsigned char l)
{
while(l--);
}
void Delay(unsigned char n)
{
unsigned char i,j,k;
for(k=0;k<n;k++)
{
for(i=0;i<131;i++)
{
for(j=0;j<15;j++)
{
uDelay(203);
}
}
}
}
//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
// Read/Write Sequence
//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
#ifdef M68 // 8-bit 68XX Parallel
void Write_Command(unsigned char Data)
{
DC=0;
CS=0;
RW=0;
E=1;
xData=Data;
E=0;
RW=1;
CS=1;
DC=1;
}
void Write_Data(unsigned char Data)
{
DC=1;
CS=0;
RW=0;
E=1;
xData=Data;
E=0;
RW=1;
CS=1;
DC=1;
}
#endif
#ifdef I80
void Write_Command(unsigned char Data)
{
DC=0;
CS=0;
WR=0;
xData=Data;
WR=1;
CS=1;
DC=1;
}
void Write_Data(unsigned char Data)
{
DC=1;
CS=0;
WR=0;
xData=Data;
WR=1;
CS=1;
DC=1;
}
#endif
#ifdef SPI
void Write_Command(unsigned char Data)
{
unsigned char i;
CS=0;
DC=0;
for (i=0; i<8; i++)
{
SCLK=0;
SDIN=(Data&0x80)>>7;
Data = Data << 1;
// uDelay(1);
SCLK=1;
// uDelay(1);
}
// SCLK=0;
DC=1;
CS=1;
}
void Write_Data(unsigned char Data)
{
unsigned char i;
CS=0;
DC=1;
for (i=0; i<8; i++)
{
SCLK=0;
SDIN=(Data&0x80)>>7;
Data = Data << 1;
// uDelay(1);
SCLK=1;
// uDelay(1);
}
// SCLK=0;
DC=1;
CS=1;
}
#endif
//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
// Instruction Setting
//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
void Set_Column_Address(unsigned char a, unsigned char b)
{
Write_Command(0x15); // Set Column Address
Write_Command(a); // Default => 0x00
Write_Command(b); // Default => 0x3F (Total Columns Devided by 2)
}
void Set_Row_Address(unsigned char a, unsigned char b)
{
Write_Command(0x75); // Set Row Address
Write_Command(a); // Default => 0x00
Write_Command(b); // Default => 0x4F
}
void Set_Contrast_Current(unsigned char d)
{
Write_Command(0x81); // Set Contrast Value
Write_Command(d); // Default => 0x40
}
void Set_Current_Range(unsigned char d)
{
Write_Command(0x84|d); // Set Current Range
// Default => 0x84
// 0x84 (0x00) => Quarter Current Range
// 0x85 (0x01) => Half Current Range
// 0x86 (0x02) => Full Current Range
}
void Set_Remap_Format(unsigned char d)
{
Write_Command(0xA0); // Set Re-Map & Data Format
Write_Command(d); // Default => 0x00
// Column Address 0 Mapped to SEG0
// Disable Nibble Re-Map
// Horizontal Address Increment
// Scan from COM0 to COM[N-1]
// Disable COM Split Odd Even
}
void Set_Start_Line(unsigned char d)
{
Write_Command(0xA1); // Set Display Start Line
Write_Command(d); // Default => 0x00
}
void Set_Display_Offset(unsigned char d)
{
Write_Command(0xA2); // Set Display Offset
Write_Command(d); // Default => 0x00
}
void Set_Display_Mode(unsigned char d)
{
Write_Command(0xA4|d); // Set Display Mode
// Default => 0xA4
// 0xA4 (0x00) => Normal Display
// 0xA5 (0x01) => Entire Display On, All Pixels Turn On at GS Level 15
// 0xA6 (0x02) => Entire Display Off, All Pixels Turn Off
// 0xA7 (0x03) => Inverse Display
}
void Set_Multiplex_Ratio(unsigned char d)
{
Write_Command(0xA8); // Set Multiplex Ratio
Write_Command(d); // Default => 0x5F
}
void Set_Master_Config(unsigned char d)
{
Write_Command(0xAD); // Set Master Configuration
Write_Command(0x02|d); // Default => 0x03
// 0x02 (0x00) => Select External VCC Supply
// 0x03 (0x01) => Select Internal DC/DC Voltage Converter
}
void Set_Display_On_Off(unsigned char d)
{
Write_Command(0xAE|d); // Set Display On/Off
// Default => 0xAE
// 0xAE (0x00) => Display Off
// 0xAF (0x01) => Display On
}
void Set_Phase_Length(unsigned char d)
{
Write_Command(0xB1); // Phase 1 & 2 Period Adjustment
Write_Command(d); // Default => 0x53 (5 Display Clocks [Phase 2] / 3 Display Clocks [Phase 1])
// D[3:0] => Phase 1 Period in 1~15 Display Clocks
// D[7:4] => Phase 2 Period in 1~15 Display Clocks
}
void Set_Frame_Frequency(unsigned char d)
{
Write_Command(0xB2); // Set Frame Frequency (Row Period)
Write_Command(d); // Default => 0x25 (37 Display Clocks)
}
void Set_Display_Clock(unsigned char d)
{
Write_Command(0xB3); // Display Clock Divider/Osciallator Frequency
Write_Command(d); // Default => 0x41
// D[3:0] => Display Clock Divider
// D[7:4] => Oscillator Frequency
}
void Set_Precharge_Compensation(unsigned char a, unsigned char b)
{
Write_Command(0xB4); // Set Pre-Charge Compensation Level
Write_Command(b); // Default => 0x00 (No Compensation)
if(a == 0x20)
{
Write_Command(0xB0); // Set Pre-Charge Compensation Enable
Write_Command(0x08|a); // Default => 0x08
// 0x08 (0x00) => Disable Pre-Charge Compensation
// 0x28 (0x20) => Enable Pre-Charge Compensation
}
}
void Set_Precharge_Voltage(unsigned char d)
{
Write_Command(0xBC); // Set Pre-Charge Voltage Level
Write_Command(d); // Default => 0x10 (Connect to VCOMH)
}
void Set_VCOMH(unsigned char d)
{
Write_Command(0xBE); // Set Output Level High Voltage for COM Signal
Write_Command(d); // Default => 0x1D (0.81*VREF)
}
void Set_VSL(unsigned char d)
{
Write_Command(0xBF); // Set Segment Low Voltage Level
Write_Command(0x02|d); // Default => 0x0E
// 0x02 (0x00) => Keep VSL Pin Floating
// 0x0E (0x0C) => Connect a Capacitor between VSL Pin & VSS
}
void Set_NOP()
{
Write_Command(0xE3); // Command for No Operation
}
//=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
// Global Variables
//=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
#define Max