Monochrome LCD 320x240 Driver SED13700/S1D13700/SED1335 Epson (Raystar RG320240A6-FHW-M-000) + MCU PIC18F4550 (PICDEM FSUSB Microchip)
Figure 1. Video Monochrome LCD 320x240 Driver SED13700/S1D13700/SED1335 Epson
Figure 2. Schematic Monochrome LCD 320x240 Driver SED13700/S1D13700/SED1335 Epson
Downloads Project LCD SED13700/S1D13700/SED1335 Epson
MAIN
/*
Set the clock source to the inernal oscillator and turn off the watch dog timer. the
following line is specific to PIC18 and PIC18F2455/2550/4455/4550
*/
#pragma config FOSC = INTOSCIO_EC, FCMEN=ON, WDT=OFF, BOR = OFF, VREGEN = OFF, LVP = OFF
#include <p18cxxx.h>
#include "sed1335.h"
#include "graphic.h"
#include "ebaylogo.h"
#include "oops.h"
void pixel_test(void);
void logo_test(void);
void logo_oops(void);
void line_test(void);
void circle_test(void);
void main(void)
{
/*
Set the internal oscillator to 8Mhz by setting all three IRCF bits to 1.
this is specific to PIC18F2455/2550/4455/4550.
*/
OSCCON |= (7 << 4);
UCONbits.USBEN = 0; //disable USB module
UCFGbits.UTRDIS = 1; //disable USB transciever
/* Start stability test */
delay_ms(100);
GLCD_Initialize();
while(1)
{
logo_test();
delay_ms(1500);
logo_oops();
delay_ms(1500);
pixel_test();
delay_ms(1500);
line_test();
delay_ms(1500);
circle_test();
delay_ms(1500);
}
while(1);
}
void logo_test(void)
{
char buf[] = "Shkkh,jg";
GLCD_ClearText();
GLCD_ClearGraphic();
GLCD_TextGoTo(0,0);
GLCD_WriteText(buf);
GLCD_TextGoTo(26,29);
GLCD_WriteText(buf);
GLCD_Bitmap((rom const unsigned char *) ebaylogo, 0, 0, 320, 240);
}
void logo_oops(void)
{
char buf[] = "Stability Test";
GLCD_ClearText();
GLCD_ClearGraphic();
GLCD_TextGoTo(0,0);
GLCD_WriteText(buf);
GLCD_TextGoTo(26,29);
GLCD_WriteText(buf);
// GLCD_Bitmap((rom const unsigned char *) oops, 0, 0, 320, 240);
}
void pixel_test(void)
{
int x;
int y;
unsigned char c;
GLCD_ClearText();
GLCD_ClearGraphic();
c = 0;
for (y = 0; y < 240; y+=2)
{
c = !c;
for (x = 0; x < 320; x+=2)
{
c = !c;
GLCD_SetPixel(x,y,c);
}
}
}
void line_test(void)
{
int x1;
int y1;
int x2;
int y2;
int i;
GLCD_ClearText();
GLCD_ClearGraphic();
x1 = 0; y1 = 0; x2 = 319; y2 = 239;
for (i = 0; i < 160; i++)
{
GLCD_Line(x1, y1,x2,y2);
x1+=2;
x2-=2;
}
x1 = 0; y1 = 0; x2 = 319; y2 = 239;
for (i = 0; i < 120; i++)
{
GLCD_Line(x1, y1,x2,y2);
y1+=2;
y2-=2;
}
}
void circle_test(void)
{
int x1;
int y1;
int r;
int i;
x1 = 160; y1 = 120; r = 10;
GLCD_ClearText();
GLCD_ClearGraphic();
for (i = 0; i < 50; i++)
{
GLCD_Circle(x1,y1,r);
r += 2;
}
}
Graphic.c
extern void GLCD_SetPixel(int x, int y, int color);
const unsigned char color = 1;
void GLCD_Rectangle(unsigned int x, unsigned int y, unsigned int b, unsigned int a)
{
unsigned int j;
for (j = 0; j < a; j++) {
GLCD_SetPixel(x, y + j, color);
GLCD_SetPixel(x + b - 1, y + j, color);
}
// rysowanie linii poziomych (podstawy)
for (j = 0; j < b; j++) {
GLCD_SetPixel(x + j, y, color);
GLCD_SetPixel(x + j, y + a - 1, color);
}
}
void GLCD_Circle(unsigned int cx, unsigned int cy ,unsigned int radius)
{
int x, y, xchange, ychange, radiusError;
x = radius;
y = 0;
xchange = 1 - 2 * radius;
ychange = 1;
radiusError = 0;
while(x >= y)
{
GLCD_SetPixel(cx+x, cy+y, color);
GLCD_SetPixel(cx-x, cy+y, color);
GLCD_SetPixel(cx-x, cy-y, color);
GLCD_SetPixel(cx+x, cy-y, color);
GLCD_SetPixel(cx+y, cy+x, color);
GLCD_SetPixel(cx-y, cy+x, color);
GLCD_SetPixel(cx-y, cy-x, color);
GLCD_SetPixel(cx+y, cy-x, color);
y++;
radiusError += ychange;
ychange += 2;
if ( 2*radiusError + xchange > 0 )
{
x--;
radiusError += xchange;
xchange += 2;
}
}
}
void GLCD_Line(int X1, int Y1,int X2,int Y2)
{
int CurrentX, CurrentY, Xinc, Yinc,
Dx, Dy, TwoDx, TwoDy,
TwoDxAccumulatedError, TwoDyAccumulatedError;
Dx = (X2-X1);
Dy = (Y2-Y1);
TwoDx = Dx + Dx;
TwoDy = Dy + Dy;
CurrentX = X1; // X1
CurrentY = Y1; // Y1
Xinc = 1;
Yinc = 1;
if(Dx < 0)
{
Xinc = -1;
Dx = -Dx;
TwoDx = -TwoDx;
}
if (Dy < 0)
{
Yinc = -1;
Dy = -Dy;
TwoDy = -TwoDy;
}
GLCD_SetPixel(X1,Y1, color);
if ((Dx != 0) || (Dy != 0))
{
if (Dy <= Dx)
{
TwoDxAccumulatedError = 0;
do // ruszamy w drogк
{
CurrentX += Xinc;
TwoDxAccumulatedError += TwoDy;
if(TwoDxAccumulatedError > Dx)
{
CurrentY += Yinc;
TwoDxAccumulatedError -= TwoDx;
}
GLCD_SetPixel(CurrentX,CurrentY, color);/
}while (CurrentX != X2);
}
else // w przeciwnym razie idziemy "po igrekach"
{
TwoDyAccumulatedError = 0;
do
{
CurrentY += Yinc;
TwoDyAccumulatedError += TwoDx;
if(TwoDyAccumulatedError>Dy)
{
CurrentX += Xinc;
TwoDyAccumulatedError -= TwoDy;
}
GLCD_SetPixel(CurrentX,CurrentY, color);
}while (CurrentY != Y2);
}
}
}
Gprphic.h
void GLCD_Rectangle(unsigned int x, unsigned int y, unsigned int b, unsigned int a);
void GLCD_Circle(unsigned int cx, unsigned int cy ,unsigned int radius);
void GLCD_Line(int X1, int Y1,int X2,int Y2);
SED1335.c (SED13700)
#include <p18cxxx.h>
#include "sed1335.h"
extern void GLCD_InitializePorts(void);
void delay_ms(unsigned int ms)
{
while(ms--)
{
__delay_1ms();
}
}
void delay_14usx(unsigned int us)
{
while(us--)
{
__delay_10us();
}
}
void GLCD_Initialize(void)
{
GLCD_InitializePorts();
GLCD_HardReset();
GLCD_WriteCommand(SED1335_SYSTEM_SET);
GLCD_WriteData(SED1335_SYS_P1);
GLCD_WriteData(SED1335_SYS_P2);
GLCD_WriteData(SED1335_FY);
GLCD_WriteData(SED1335_CR);
GLCD_WriteData(SED1335_TCR);
GLCD_WriteData(SED1335_LF);
GLCD_WriteData(SED1335_APL);
GLCD_WriteData(SED1335_APH);
GLCD_WriteCommand(SED1335_SCROLL);
GLCD_WriteData(SED1335_SAD1L); // Уст. стартовый адрес для 1-го эранного блока 0000h
GLCD_WriteData(SED1335_SAD1H);
GLCD_WriteData(SED1335_SL1); // Установить номер для линий дисплея 1-го эранного блока
GLCD_WriteData(SED1335_SAD2L);
GLCD_WriteData(SED1335_SAD2H);
GLCD_WriteData(SED1335_SL2);
GLCD_WriteData(SED1335_SAD3L);
GLCD_WriteData(SED1335_SAD3H);
GLCD_WriteData(SED1335_SAD4L);
GLCD_WriteData(SED1335_SAD4H);
GLCD_WriteCommand(SED1335_CSRFORM);
GLCD_WriteData(SED1335_CRX);
GLCD_WriteData(SED1335_CSRF_P2);
GLCD_WriteCommand(SED1335_CGRAM_ADR);
GLCD_WriteData(SED1335_SAGL);
GLCD_WriteData(SED1335_SAGH);
GLCD_WriteCommand(SED1335_CSRDIR_R);
GLCD_WriteCommand(SED1335_HDOT_SCR);
GLCD_WriteData(SED1335_SCRD);
GLCD_WriteCommand(SED1335_OVLAY);
GLCD_WriteData(SED1335_OVLAY_P1);
GLCD_WriteCommand(SED1335_DISP_ON); // Включить Дисплей
GLCD_WriteData(SED1335_FLASH);
GLCD_ClearGraphic(); // затереть экрна перед работой
GLCD_ClearText(); // затереть экрна перед работой
GLCD_WriteCommand(0x46);
GLCD_WriteData(0x88);
GLCD_WriteData(0x04);
GLCD_WriteCommand(0x42);
GLCD_WriteData('S');
GLCD_WriteData('o');
GLCD_WriteData('n');
GLCD_WriteData('y');
Nop();
}
//-------------------------------------------------------------------------------------------------
// Функция заполнения пикселями
//-------------------------------------------------------------------------------------------------
void GLCD_SetPixel(unsigned int x,unsigned int y, int color)
{
unsigned char tmp = 0;
unsigned int address = SED1335_GRAPHICSTART + (40 * y) + (x/8);
GLCD_SetCursorAddress(address);
GLCD_WriteCommand(SED1335_MREAD);
tmp = GLCD_ReadData();
if(color)
tmp |= (1 << (SED1335_FX - (x % 8)));
else
tmp &= ~(1 << (SED1335_FX - (x % 8)));
GLCD_SetCursorAddress(address);
GLCD_WriteCommand(SED1335_MWRITE);
GLCD_WriteData(tmp);
}
//-------------------------------------------------------------------------------------------------
// Функция выведения текста
//-------------------------------------------------------------------------------------------------
void GLCD_WriteText(char * tekst)
{
GLCD_WriteCommand(SED1335_MWRITE);
while(*tekst)
GLCD_WriteData(*tekst++);
}
//-------------------------------------------------------------------------------------------------
// Funkcja wyњwietlaj№ca tekst z pamiкci programu (AVR)
//-------------------------------------------------------------------------------------------------
void GLCD_WriteTextP(rom const unsigned char * tekst)
{
GLCD_WriteCommand(SED1335_MWRITE);
while(GLCD_ReadByteFromROMMemory(tekst))
GLCD_WriteData(GLCD_ReadByteFromROMMemory(tekst++));
}
//-------------------------------------------------------------------------------------------------
// Устновление адреса курсора
//-------------------------------------------------------------------------------------------------
void GLCD_SetCursorAddress(unsigned int address)
{
GLCD_WriteCommand(SED1335_CSRW);
GLCD_WriteData((unsigned char)(address & 0xFF));
GLCD_WriteData((unsigned char)(address >> 8));
}
//-------------------------------------------------------------------------------------------------
//-------------------------------------------------------------------------------------------------
void GLCD_TextGoTo(unsigned char x, unsigned char y)
{
GLCD_SetCursorAddress((y * 40) + x);
}
//-------------------------------------------------------------------------------------------------
//-------------------------------------------------------------------------------------------------
void GLCD_GraphicGoTo(unsigned int x, unsigned int y)
{
GLCD_SetCursorAddress(SED1335_GRAPHICSTART + (y * 40) + x/8); // было SED1335_GRAPHICSTART
}
//-------------------------------------------------------------------------------------------------
//-------------------------------------------------------------------------------------------------
void GLCD_ClearText(void)
{
int i;
GLCD_TextGoTo(0,0);
GLCD_WriteCommand(SED1335_MWRITE);
for(i = 0; i < 1200; i++)
GLCD_WriteData(' ');
}
//-------------------------------------------------------------------------------------------------
//-------------------------------------------------------------------------------------------------
void GLCD_ClearGraphic(void)
{
unsigned int i;
GLCD_SetCursorAddress(SED1335_GRAPHICSTART);//было GLCD_SetCursorAddress(SED1335_GRAPHICSTART)
GLCD_WriteCommand(SED1335_MWRITE);
for(i = 0; i < (40 * 240); i++)
GLCD_WriteData(0x00);
}
//-------------------------------------------------------------------------------------------------
//-------------------------------------------------------------------------------------------------
void GLCD_Bitmap(rom const unsigned char * bmp, int x, int y, int width, int height)
{
unsigned int i, j;
for(i = 0; i < height ; i++)
{
GLCD_GraphicGoTo(x, y+i);
GLCD_WriteCommand(SED1335_MWRITE);
for(j = 0; j < width/8; j++)
GLCD_WriteData(GLCD_ReadByteFromROMMemory(bmp+j+(40*i)));
}
}
SED1335.h (SED13700)
#include <delays.h>
/*Change this to match the FOSC*/
#define CPU_CLOCK 8000000
#define __delay_1ms() Delay1KTCYx(CPU_CLOCK/4000000)
#define __delay_10us() Delay10TCYx(CPU_CLOCK/4000000)
void delay_ms(unsigned int ms);
void delay_14usx(unsigned int us);
#define
SED1335_SYSTEM_SET
0x40
#define
SED1335_SLEEP_IN
0x53
#define
SED1335_DISP_OFF
0x58
#define
SED1335_DISP_ON
0x59
#define
SED1335_SCROLL
0x44
#define
SED1335_CSRFORM
0x5d
#define
SED1335_CGRAM_ADR
0x5c
#define
SED1335_CSRDIR_U
0x4e
#define
SED1335_CSRDIR_D
0x4f
#define
SED1335_CSRDIR_L
0x4d
#define
SED1335_CSRDIR_R
0x4c
#define
SED1335_HDOT_SCR
0x5a
#define
SED1335_OVLAY
0x5b
#define
SED1335_CSRW
0x46
#define
SED1335_CSRR
0x47
#define
SED1335_MWRITE
0x42
#define
SED1335_MREAD
0x43
#define
SED1335_SCR_WIDTH
319
#define
SED1335_M0
0
#define
SED1335_M1
0
#define
SED1335_M2
0
#define
SED1335_WS
0
#define
SED1335_IV
1
#define
SED1335_FX
7 // кол-во точек по для Х директории
#define
SED1335_FY
7 // кол-во точек по веритикали для Y директории
#define
SED1335_WF
1 // Выбор свечния жижкоскристаичкой точки экран
#define
SED1335_CR
39 // количесво Х директория для дисплея
#define
SED1335_TCR
90
#define
SED1335_LF
239
#define
SED1335_APL
40 // определение номера адресной памяти для Х дириктори -вирутального экран
#define
SED1335_APH
0
#define
SED1335_LINES
30
#define
SED1335_SAD1L
0x00
#define
SED1335_SAD1H
0x00
#define
SED1335_SL1
0xEF
#define
SED1335_SAD2L
0x00B0 // Было 0xB0
#define
SED1335_SAD2H
0x0004 // Было 0x04
#define
SED1335_SL2
0xEF
#define
SED1335_SAD3L
0x00
#define
SED1335_SAD3H
0x00
#define
SED1335_SAD4L
0x00
#define
SED1335_SAD4H
0x00
#define
SED1335_CRX
0x04
#define
SED1335_CRY
0x07
#define
SED1335_CM
0
#define
SED1335_MX0
1
#define
SED1335_MX1
0
#define
SED1335_DM1
0
#define
SED1335_DM2
0
#define
SED1335_OV
0
#define
SED1335_SAGL
0
#define
SED1335_SAGH
0x70
#define
SED1335_SCRD
0
#define
SED1335_FLASH
0x16
#define
SED1335_TEXTSIZE
((SED1335_SAD2H << 8) + SED1335_SAD2L)
#define
SED1335_GRAPHICSTART
1200 //((SED1335_SAD2H << 8) | SED1335_SAD2L) ЭТА СТРОКА ВТУПУЮ НЕРАБОТАЕТ!
#define
SED1335_GRAPHICSIZE
((SED1335_SL2+1) * (SED1335_SCR_WIDTH+1))>>3
#define
SED1335_MEM_END
10800
#define
SED1335_SYS_P1
0x10 | (SED1335_IV << 5) | (SED1335_WS << 3) | (SED1335_M2 << 2) | (SED1335_M1 << 1) | SED1335_M0
#define
SED1335_SYS_P2
0x00 | (SED1335_WF << 7) | SED1335_FX
#define
SED1335_CSRF_P2
0x00 | (SED1335_CM << 7) | SED1335_CRY
#define
SED1335_OVLAY_P1
0x00 | (SED1335_OV << 4) | (SED1335_DM2 << 3) | (SED1335_DM1 << 2) | (SED1335_MX1 << 1) | SED1335_MX0
//-----------------------------------------------------------------------------
void GLCD_Initialize(void);
void GLCD_HardReset(void);
void GLCD_WriteCommand(unsigned char);
void GLCD_WriteData(unsigned char);
unsigned char GLCD_ReadData(void);
unsigned char GLCD_ReadByteFromROMMemory(rom const unsigned char *);
void GLCD_ClearText(void);
void GLCD_ClearGraphic(void);
void GLCD_TextGoTo(unsigned char, unsigned char);
void GLCD_WriteText(char *);
void GLCD_SetPixel(unsigned int x,unsigned int y, int color);
void GLCD_SetCursorAddress(unsigned int address);
void GLCD_Bitmap(rom const unsigned char * bmp, int x, int y, int dx, int dy);
sed1335-pic18.c
#include <p18cxxx.h>
#include "sed1335.h"
#define SED1335_DATA_PORT
LATD
#define SED1335_DATA_DIR
TRISD
#define SED1335_DATA_PIN
PORTD
#define SED1335_CONTROL_PORT
LATC
#define SED1335_CONTROL_DIR
TRISC
#define
SED1335_CONTROL_PIN
PORTC
#define SED1335_A0
(1 << 6)
#define SED1335_WR
(1 << 1)
#define SED1335_RD
(1 << 0)
#define SED1335_CS
(1 << 7)
#define SED1335_RES
(1 << 2)
//-------------------------------------------------------------------------------------------------
//-------------------------------------------------------------------------------------------------
/*************************************/
/*Uncomment this line for over 32Mhz */
/*************************************/
//#define READDELAY(); Nop();Nop();Nop();Nop();Nop();Nop();Nop();Nop();Nop();Nop();
/*************************************/
/*Uncomment this line for 16-32MHz */
/*************************************/
//#define READDELAY(); Nop();Nop();Nop();Nop();Nop();Nop();
/*************************************/
/*Uncomment this line for 8-16MHz */
/*************************************/
#define READDELAY(); Nop();Nop();
/*************************************/
/*Uncomment this line for 4MHz */
/*************************************/
//#define READDELAY(); Nop();
void GLCD_InitializePorts(void)
{
SED1335_DATA_DIR = 0x00;
SED1335_CONTROL_DIR &= ~(SED1335_A0 | SED1335_WR | SED1335_RD | SED1335_CS | SED1335_RES); // помен¤л местами
SED1335_CONTROL_PORT |= (SED1335_A0 | SED1335_WR | SED1335_RD | SED1335_CS | SED1335_RES);
}
void GLCD_HardReset(void)
{
//
SED1335_CONTROL_DIR &= ~(SED1335_RES); // ЅџЋќ
//
delay_ms(3);
//
SED1335_CONTROL_DIR |= (SED1335_RES);
//
delay_ms(10);
//
SED1335_DATA_DIR = 0x00; // настоить на выход
//
SED1335_DATA_PORT = 0xFF; // уст. все 11111111
SED1335_CONTROL_PORT &= ~(SED1335_RES); // √–»Ўј
delay_ms(3);
SED1335_CONTROL_PORT |= (SED1335_RES);
delay_ms(10);
}
//-------------------------------------------------------------------------------------------------
//-------------------------------------------------------------------------------------------------
void GLCD_WriteData(unsigned char dataToWrite)
{
SED1335_DATA_PORT = dataToWrite;
SED1335_DATA_DIR = 0;
SED1335_CONTROL_PORT &= ~(SED1335_CS);
SED1335_CONTROL_PORT &= ~(SED1335_A0 | SED1335_WR);
SED1335_CONTROL_PORT |= (SED1335_CS);
SED1335_CONTROL_PORT |= (SED1335_A0 | SED1335_WR);
}
//-------------------------------------------------------------------------------------------------
//-------------------------------------------------------------------------------------------------
void GLCD_WriteCommand(unsigned char commandToWrite)
{
SED1335_DATA_PORT = commandToWrite;
SED1335_DATA_DIR = 0;
SED1335_CONTROL_PORT &= ~(SED1335_WR);
SED1335_CONTROL_PORT &= ~SED1335_CS;
SED1335_CONTROL_PORT |= (SED1335_WR);
SED1335_CONTROL_PORT |= SED1335_CS;
}
//-------------------------------------------------------------------------------------------------
//-------------------------------------------------------------------------------------------------
unsigned char GLCD_ReadData(void)
{
unsigned char tmp;
SED1335_CONTROL_PORT &= ~(SED1335_CS);
SED1335_DATA_DIR = 0xFF;
SED1335_CONTROL_PORT &= ~(SED1335_RD);
READDELAY();
tmp = SED1335_DATA_PIN;
SED1335_CONTROL_PORT |= (SED1335_CS);
SED1335_CONTROL_PORT |= (SED1335_RD);
return tmp;
}
//-------------------------------------------------------------------------------------------------
//-------------------------------------------------------------------------------------------------
unsigned char GLCD_ReadByteFromROMMemory(rom const unsigned char * ptr)
{
return *ptr;
}