typedef unsigned char U08;
typedef unsigned int U16;
#define Control_Bus PORTA
#define Data_Upper PORTC
#define Data_Lower PORTF
#define MAX_PIXEL 96000
#define X_MAX_PIXEL 400
#define Y_MAX_PIXEL 240
#define BLACK 0x0000
#define WHITE 0xFFFF
#define YELLOW 0xFFE0
#define RED 0xF800
#define GREEN 0x07E0
#define BLUE 0x001F
#define CYAN 0x07FF
#define MAGENTA 0xF81F
#define CSB_HIGH (Control_Bus |= 0x01)
#define CSB_LOW (Control_Bus &= 0xFE)
#define RS_HIGH (Control_Bus |= 0x02)
#define RS_LOW (Control_Bus &= 0xFD)
#define WRB_HIGH (Control_Bus |= 0x04)
#define WRB_LOW (Control_Bus &= 0xFB)
#define RDB_HIGH (Control_Bus |= 0x08)
#define RDB_LOW (Control_Bus &= 0xF7)
#define RESETB_HIGH (Control_Bus |= 0x10)
#define RESETB_LOW (Control_Bus &= 0xEF)
void delay_us(U16 Data_us) {
register unsigned char i;
for(i=0; i<Data_us; i++) { // 4Cycle+
asm volatile(" PUSH R0 "); // 2Cycle+
asm volatile(" POP R0 "); // 2Cycle+
asm volatile(" PUSH R0 "); // 2Cycle+
asm volatile(" POP R0 "); // 2Cycle+
asm volatile(" PUSH R0 "); // 2Cycle+
asm volatile(" POP R0 "); // 2Cycle+ = 16Cycle = 1us, 16MHz
}
}
void delay_ms(U16 Data_ms) {
register unsigned int i;
for(i=0; i<Data_ms; i++) {
delay_us(250); // 250us+
delay_us(250); // 250us+
delay_us(250); // 250us+
delay_us(250); // 250us * 4 = 1ms
}
}
void MSK2844_Instruction(U16 Data) {
unsigned char data_h, data_l;
RS_LOW; CSB_LOW;
PORTF=(U08)(Data >> 8);
WRB_LOW; WRB_HIGH;
PORTF=(U08)(Data & 0x00FF);
WRB_LOW; WRB_HIGH; CSB_HIGH;
}
void MSK2844_Data(U16 Data) {
unsigned char data_h, data_l;
RS_HIGH; CSB_LOW;
PORTF=(U08)(Data >> 8);
WRB_LOW; WRB_HIGH;
PORTF=(U08)(Data & 0x00FF);
WRB_LOW; WRB_HIGH; CSB_HIGH;
}
U16 MSK2844_Read(void) {
unsigned char Upper_Data, Lower_Data;
unsigned int Read_Data;
RS_HIGH; CSB_LOW; RDB_LOW;
Upper_Data = PORTC;
Lower_Data = PORTF;
RDB_HIGH; CSB_HIGH;
Read_Data = ((unsigned int)Upper_Data << 8) & 0xFF00;
Read_Data += ((unsigned int)Lower_Data & 0x00FF);
return Read_Data;
}
void MSK2844_Power_On_Sequence(void) {
long int i;
RESETB_LOW; delay_ms(5);
RESETB_HIGH; delay_ms(5);
MSK2844_Instruction(0x0111); MSK2844_Data(0x1000);
MSK2844_Instruction(0x0110); MSK2844_Data(0x0100);
delay_ms(1);
MSK2844_Instruction(0x0111); MSK2844_Data(0x000C);
MSK2844_Instruction(0x0110); MSK2844_Data(0x0101);
delay_ms(1);
MSK2844_Instruction(0x0111); MSK2844_Data(0x1000);
MSK2844_Instruction(0x0110); MSK2844_Data(0x0101);
delay_ms(1);
MSK2844_Instruction(0x0111); MSK2844_Data(0x1202);
MSK2844_Instruction(0x0110); MSK2844_Data(0x0102);
delay_ms(1);
MSK2844_Instruction(0x0100); MSK2844_Data(0x4010);
MSK2844_Instruction(0x0111); MSK2844_Data(0x00BC);
MSK2844_Instruction(0x0110); MSK2844_Data(0x0100);
delay_ms(1);
MSK2844_Instruction(0x0111); MSK2844_Data(0x1200);
MSK2844_Instruction(0x0110); MSK2844_Data(0x0100);
delay_ms(1);
MSK2844_Instruction(0x0111); MSK2844_Data(0x001C);
MSK2844_Instruction(0x0110); MSK2844_Data(0x0101);
delay_ms(35);
MSK2844_Instruction(0x0111); MSK2844_Data(0x1A00);
MSK2844_Instruction(0x0110); MSK2844_Data(0x0100);
delay_ms(1);
MSK2844_Instruction(0x0111); MSK2844_Data(0x0200);
MSK2844_Instruction(0x0110); MSK2844_Data(0x0103);
delay_ms(1);
MSK2844_Instruction(0x0111); MSK2844_Data(0x1506);
MSK2844_Instruction(0x0110); MSK2844_Data(0x0103);
delay_ms(1);
MSK2844_Instruction(0x0111); MSK2844_Data(0x0C41);
MSK2844_Instruction(0x0110); MSK2844_Data(0x0104);
delay_ms(75);
MSK2844_Instruction(0x0001); MSK2844_Data(0x0000);
MSK2844_Instruction(0x0002); MSK2844_Data(0x0700);
MSK2844_Instruction(0x0003); MSK2844_Data(0x0030);
MSK2844_Instruction(0x0008); MSK2844_Data(0x0506);
MSK2844_Instruction(0x0009); MSK2844_Data(0x0001);
MSK2844_Instruction(0x000B); MSK2844_Data(0x0000);
MSK2844_Instruction(0x000D); MSK2844_Data(0x0010);
MSK2844_Instruction(0x0012); MSK2844_Data(0x0000);
MSK2844_Instruction(0x0013); MSK2844_Data(0x0002);
MSK2844_Instruction(0x0015); MSK2844_Data(0x0000);
MSK2844_Instruction(0x001B); MSK2844_Data(0x0010);
MSK2844_Instruction(0x001C); MSK2844_Data(0x0000);
delay_ms(1);
MSK2844_Instruction(0x0205); MSK2844_Data(0x0000);
MSK2844_Instruction(0x070A); MSK2844_Data(0x7800);
MSK2844_Instruction(0x070B); MSK2844_Data(0x0000);
MSK2844_Instruction(0x070C); MSK2844_Data(0x0030);
MSK2844_Instruction(0x070D); MSK2844_Data(0x0000);
MSK2844_Instruction(0x070E); MSK2844_Data(0x0000);
MSK2844_Instruction(0x070F); MSK2844_Data(0x2100);
MSK2844_Instruction(0x0710); MSK2844_Data(0x0000);
delay_ms(1);
MSK2844_Instruction(0x0400); MSK2844_Data(0x0031);
MSK2844_Instruction(0x0401); MSK2844_Data(0x0000);
MSK2844_Instruction(0x0402); MSK2844_Data(0x0000);
MSK2844_Instruction(0x0403); MSK2844_Data(0x018F);
MSK2844_Instruction(0x0404); MSK2844_Data(0x0000);
delay_ms(1);
MSK2844_Instruction(0x0300); MSK2844_Data(0x0503);
MSK2844_Instruction(0x0301); MSK2844_Data(0x0403);
MSK2844_Instruction(0x0302); MSK2844_Data(0x0404);
MSK2844_Instruction(0x0303); MSK2844_Data(0x0303);
MSK2844_Instruction(0x0304); MSK2844_Data(0x0302);
MSK2844_Instruction(0x0305); MSK2844_Data(0x0203);
MSK2844_Instruction(0x0306); MSK2844_Data(0x0E14);
MSK2844_Instruction(0x0307); MSK2844_Data(0x0503);
MSK2844_Instruction(0x0308); MSK2844_Data(0x0403);
MSK2844_Instruction(0x0309); MSK2844_Data(0x0404);
MSK2844_Instruction(0x030A); MSK2844_Data(0x0303);
MSK2844_Instruction(0x030B); MSK2844_Data(0x0302);
MSK2844_Instruction(0x030C); MSK2844_Data(0x0203);
MSK2844_Instruction(0x030D); MSK2844_Data(0x1F10);
delay_ms(1);
MSK2844_Instruction(0x0210); MSK2844_Data(0x0000); // Horizontal Start Address, Y = 0
MSK2844_Instruction(0x0211); MSK2844_Data(0x00EF); // Horizontal End Address, Y = 239
MSK2844_Instruction(0x0212); MSK2844_Data(0x0000); // Vertical Start Address, X = 0
MSK2844_Instruction(0x0213); MSK2844_Data(0x018F); // Vertical End Address, X = 399
MSK2844_Instruction(0x0200); MSK2844_Data(0x0000); // Horizontal Address, Y = 0
MSK2844_Instruction(0x0201); MSK2844_Data(0x0000); // Vertical Address, X = 0
delay_ms(1);
MSK2844_Instruction(0x0202);
for(i=0; i<MAX_PIXEL; i++)
MSK2844_Data(YELLOW);
}
void MSK2844_Disp_On_Sequence(void) {
MSK2844_Instruction(0x0100); MSK2844_Data(0x4110);
MSK2844_Instruction(0x0111); MSK2844_Data(0x061C);
MSK2844_Instruction(0x0110); MSK2844_Data(0x0101);
MSK2844_Instruction(0x0007); MSK2844_Data(0x0001);
delay_ms(45);
MSK2844_Instruction(0x0111); MSK2844_Data(0x161B);
MSK2844_Instruction(0x0110); MSK2844_Data(0x0101);
MSK2844_Instruction(0x0007); MSK2844_Data(0x0003);
delay_ms(1);
MSK2844_Instruction(0x0007); MSK2844_Data(0x0113);
}
void MSK2844_Dot(U16 Data) {
MSK2844_Instruction(0x0202); MSK2844_Data(Data);
}
void MSK2844_GoTo_XY(U16 X, U16 Y) {
MSK2844_Instruction(0x0200); MSK2844_Data(Y); // Horizontal Address
MSK2844_Instruction(0x0201); MSK2844_Data(X); // Vertical Address
}
void MSK2844_Pixel(U16 X, U16 Y, U16 Color) {
MSK2844_Instruction(0x0200); MSK2844_Data(Y); // Horizontal Address
MSK2844_Instruction(0x0201); MSK2844_Data(X); // Vertical Address
MSK2844_Instruction(0x0202); MSK2844_Data(Color);
}
void MSK2844_CLS(void) {
long int i;
MSK2844_Instruction(0x0200); MSK2844_Data(0x0000); // Horizontal Address
MSK2844_Instruction(0x0201); MSK2844_Data(0x0000); // Vertical Address
MSK2844_Instruction(0x0202);
for(i=0; i<MAX_PIXEL; i++)
MSK2844_Data(WHITE);
}