320 x 240 GLCD S1D13700 sürücü kodlarıdır.
Hala 320x240 Lcd çalıştıramayanlar için
Site orjinal kodlarıdır.
{
********************************************************************************
* Name : S1D13700.BAS *
* Author : S Wright *
* Notice : Copyright (c) 2007 J Smith, S Wright *
* : All Rights Reserved *
* Date : 27/01/2007 *
* Version : 1.0 *
* Notes : Library for a 320 x 240 graphic LCD with S1D13700 controller *
* : working in 6800 or 8080 mode *
********************************************************************************
}
Module S1D13700
// import the graphics module...
#define GLCD_PIXEL_08
#define GLCD_COLOR_01
#define GLCD_XY_16
Include "Graphics.bas"
Include "System.bas"
Include "Utils.bas"
// default module options - user options can override these values...
#option GLCD_MODE = 8080 // GLCD interface mode - 6800 or 8080
#option GLCD_DATA = PORTD // data port
#option GLCD_EN = PORTB.0 // EN pin - 6800 mode
#option GLCD_RD = PORTB.0 // RD pin - 8080 mode
#option GLCD_RW = PORTB.1 // RW pin - 6800 mode
#option GLCD_WR = PORTB.1 // WR pin - 8080 mode
#option GLCD_A0 = PORTB.2 // A0 pin
#option GLCD_CS = PORTB.3 // chip select
#option GLCD_RES = PORTB.5 // reset pin
#option GLCD_ASPECT_RATIO = 100 // aspect ratio, smaller number will squeeze y for GLCD circles and box
#option GLCD_INIT_DELAY = 100 // initialisation delay (ms)
#if Not (GLCD_MODE in (6800, 8080))
#error GLCD_MODE, "Invalid option. GLCD mode not recognized."
#endif
// validate data port...
#if IsOption(GLCD_DATA)
#if Not IsValidPort(GLCD_DATA)
#error GLCD_DATA, "Invalid option. DATA must be a valid port name."
#endif
#ifdef GLCD_DATA@ Then
#error GLCD_DATA@, "Invalid option. DATA port cannot be a single bit value."
#endif
#endif
// validate EN pin...
#if IsOption(GLCD_EN) And Not IsValidPortPin(GLCD_EN)
#error GLCD_EN, "Invalid option. EN must be a valid port pin."
#endif
// validate RD pin...
#if IsOption(GLCD_RD) And Not IsValidPortPin(GLCD_RD)
#error GLCD_RD, "Invalid option. RD must be a valid port pin."
#endif
// validate RW pin...
#if IsOption(GLCD_RW) And Not IsValidPortPin(GLCD_RW)
#error GLCD_RW, "Invalid option. RW must be a valid port pin."
#endif
// validate WR pin...
#if IsOption(GLCD_WR) And Not IsValidPortPin(GLCD_WR)
#error GLCD_WR, "Invalid option. WR must be a valid port pin."
#endif
// validate A0 pin...
#if IsOption(GLCD_A0) And Not IsValidPortPin(GLCD_A0)
#error GLCD_A0, "Invalid option. A0 must be a valid port pin."
#endif
// validate CS pin...
#if IsOption(GLCD_CS) And Not IsValidPortPin(GLCD_CS)
#error GLCD_CS, "Invalid option. CS must be a valid port pin."
#endif
// validate RES pin...
#if IsOption(GLCD_RES) And Not IsValidPortPin(GLCD_RES)
#error GLCD_RES, "Invalid option. RES must be a valid port pin."
#endif
// validate initialisation delay...
#if IsOption(GLCD_INIT_DELAY)
#if Not (GLCD_INIT_DELAY in (0 to 1000))
#error GLCD_INIT_DELAY, "Invalid option. GLCD initialize delay must be between 0 and 1000 (ms)."
#endif
#endif
// now create Data TRIS...
#option _GLCD_DATA_TRIS = GetTRIS(GLCD_DATA)
// GLCD width and height...
Public Const
GLCDWidth = 320,
GLCDHeight = 240
// x, y position structure...
Public Structure TPositionS1D13700
x As TXY
y As Byte
End Structure
// x, y position...
Public Dim
Pos As TPositionS1D13700
// S1D13700 commands...
Const
cmdSystem = $40, // general system settings
cmdSleep = $53, // enter into standy mode
cmdDisplayOff = $58, // turn the display off
cmdDisplayOn = $59, // turn the display on
cmdScroll = $44, // setup text and graphics address regions
cmdCsrForm = $5D, // set cursor size
cmdCsrDirRight = $4C, // cursor moves right after write to display memory
cmdCsrDirLeft = $4D, // cursor moves left after write to display memory
cmdCsrDirUp = $4E, // cursor moves up after write to display memory
cmdCsrDirDown = $4F, // cursor moves down after write to display memory
cmdCGRAMAddress = $5C, // configure character generator RAM address
cmdHDotScroll = $5A, // set horizontal scroll rate
cmdOverlay = $5B, // configure how layers overlay
cmdSetCsrAddress = $46, // set the cursor address
cmdGetCsrAddress = $47, // read the cursor address
cmdDisplayWrite = $42, // write to display memory
cmdDisplayRead = $43, // read from display memory
GLCDDelay = GLCD_INIT_DELAY
// port and pin settings, these are brought into
// the program by using the above options...
Dim
Data As GLCD_DATA, // data in (PORT)
TRISData As _GLCD_DATA_TRIS, // data TRIS
EN As GLCD_EN.GLCD_EN@, // EN pin - enable (serves as a strobe) - 6800 mode
RD As GLCD_RD.GLCD_RD@, // RD pin - read when L - 8080 mode
RW As GLCD_RW.GLCD_RW@, // RW pin - read or write (0 = write, 1 = read) - 6800 mode
WR As GLCD_WR.GLCD_WR@, // WR pin - write when L - 8080 mode
A0 As GLCD_A0.GLCD_A0@, // A0 pin - sets data destination: 1 = command, 0 = data
CS As GLCD_CS.GLCD_CS@, // chip select - 0 = selected, 1 = disabled
RES As GLCD_RES.GLCD_RES@ // RES pin - normally RES = 1 but pull to 0 for initialization
Dim
Layers As Byte, // layers 1 - 3 on/off
Layer1 As Layers.Booleans(2),
Layer2 As Layers.Booleans(4),
Layer3 As Layers.Booleans(6),
CurrentLayer As Byte, // current drawing layer
CurrentLayerMemPos As Word
{
********************************************************************************
* Name : SetData (PRIVATE) *
* Purpose : Write a data byte to GLCD *
********************************************************************************
}
Sub SetData(pData As Byte)
#if GLCD_MODE = 6800
A0 = 0 // access display RAM data
RW = 0 // write mode
TRISData = $00 // set data bus to output
Data = pData // write to the bus
CS = 0
EN = 1 // write to GLCD
DelayUS(1)
EN = 0
CS = 1
DelayUS(1) // prevent further write/read immediately
#elseif GLCD_MODE = 8080
A0 = 0 // setup for data write
RD = 1 // RD high for writing
TRISData = $00 // set data bus to output
Data = pData // write to the bus
CS = 0
WR = 0 // write low starts write sequence
DelayUS(1) // keep WR low to allow command to register
WR = 1 // de-assert write
CS = 1
DelayUS(1) // prevent further write/read immediately
#endif
End Sub
{
********************************************************************************
* Name : GetData (PRIVATE) *
* Purpose : Read byte from GLCD *
********************************************************************************
}
Function GetData() As Byte
#if GLCD_MODE = 6800
A0 = 1 // access display RAM data
RW = 1 // read mode
TRISData = $FF // set data bus to input
CS = 0
EN = 1 // read from GLCD
DelayUS(2)
Result = Data // read from the bus
EN = 0
CS = 1
DelayUS(1) // prevent further write/read immediately
#elseif GLCD_MODE = 8080
A0 = 1 // setup for data read
WR = 1 // WR high for reading
TRISData = $FF // set data bus to input
CS = 0
RD = 0 // read low starts read sequence
DelayUS(2) // keep RD low to allow data to be read
Result = Data // read from the bus
RD = 1 // de-assert read
CS = 1
DelayUS(1) // prevent further write/read immediately
#endif
End Function
{
********************************************************************************
* Name : Command (PRIVATE) *
* Purpose : Write a command byte to GLCD *
********************************************************************************
}
Sub Command(pCommand As Byte)
#if GLCD_MODE = 6800
A0 = 1 // instruction mode
RW = 0 // write mode
TRISData = $00 // set data bus to output
Data = pCommand // write to the bus
CS = 0
EN = 1 // write to GLCD
DelayUS(1)
EN = 0
CS = 1
DelayUS(1) // prevent further write/read immediately
#elseif GLCD_MODE = 8080
A0 = 1 // setup for command
RD = 1 // RD high for writing
TRISData = $00 // set data bus to output
Data = pCommand // write to the bus
CS = 0
WR = 0 // write low starts write sequence
DelayUS(1) // keep WR low to allow command to register
WR = 1 // de-assert write
CS = 1
DelayUS(1) // prevent further write/read immediately
#endif
End Sub
{
********************************************************************************
* Name : CsrMemPosition *
* Purpose : Positions cursor in graphics memory *
********************************************************************************
}
Sub CsrMemPosition(pMemStart As Word)
Command(cmdSetCsrAddress) // command - next two bytes are low & high bytes of memory start
SetData(pMemStart.Byte0) // low byte
SetData(pMemStart.Byte1) // high byte
End Sub
{
********************************************************************************
* Name : SetPosition (PRIVATE) *
* Purpose : Set GLCD x and y positions *
********************************************************************************
}
Sub SetPosition()
Dim MemPos As Word
MemPos = CurrentLayerMemPos + Pos.x + (40 * Pos.y) // find position in graphics
// memory (40 bytes across 320 pixel screen)
CsrMemPosition(MemPos)
End Sub
{
********************************************************************************
* Name : WriteByte *
* Purpose : Write a byte *
********************************************************************************
}
Public Sub WriteByte(pValue As Byte)
SetPosition
Command(cmdDisplayWrite)
SetData(pValue)
End Sub
{
********************************************************************************
* Name : ReadByte *
* Purpose : Read a byte *
********************************************************************************
}
Public Function ReadByte() As Byte
SetPosition
Command(cmdDisplayRead)
ReadByte = GetData
End Function
{
********************************************************************************
* Name : SetPixel *
* Purpose : Set pixel at pixel location x,y *
********************************************************************************
}
Public Sub SetPixel(pX, pY As TXY)
Dim XBit As Byte
Dim Pixel As Byte
Dim LastPosX As TXY
If (pX < GLCDWidth) And (pY < GLCDHeight) Then
LastPosX = Pos.x
XBit = %10000000 >> (pX Mod 8)
Pos.y = pY
Pos.x = pX / 8
SetPosition
Command(cmdDisplayRead)
Pixel = GetData
// pen is white...
If Pen.Color = 0 Then
If Pen.Mode = pmCopy Then
XBit = Not XBit
Pixel = Pixel And XBit
EndIf
// pen is black...
Else
// pen copy or merge...
If Pen.Mode <> pmXOR Then
Pixel = Pixel Or XBit
// pen XOR
Else
If (Pixel And XBit) = 0 Then
Pixel = Pixel Or XBit
Else
XBit = Not XBit
Pixel = Pixel And XBit
EndIf
EndIf
EndIf
SetPosition
Command(cmdDisplayWrite)
SetData(Pixel)
Pos.x = LastPosX
EndIf
End Sub
{
********************************************************************************
* Name : GetPixel *
* Purpose : Return pixel colour at pixel position x, y *
********************************************************************************
}
Public Function GetPixel(pX, pY As TXY) As TColor
Dim Pixel As Byte
Pos.y = pY
Pos.x = pX / 8
SetPosition
Command(cmdDisplayRead)
Pixel = GetData << (pX Mod 8)
Result = Pixel.7
End Function
{
********************************************************************************
* Name : Cls *
* Purpose : Clear one of the three graphic screens *
********************************************************************************
}
Public Sub Cls(pLayer As Byte)
Dim MemStart, MemPos As Word
MemStart = (pLayer - 1) * 9600
CsrMemPosition(MemStart) // move to start of graphic memory for layer
Command(cmdDisplayWrite) // set to write to display memory
MemPos = 0
Repeat
SetData($00)
Inc(MemPos)
Until MemPos = 9600
CsrMemPosition(MemStart) // move to start of graphic memory for layer
Command(cmdDisplayOn) // command for screen on to remove cursor
SetData(Layers) // sets layers 1 - 3, cursor off
End Sub
{
********************************************************************************
* Name : ApplyLine (PRIVATE) *
* Purpose : Applies mask to line *
********************************************************************************
}
Private Function ApplyLine(pLine, pMask As Byte) As Byte
If Brush.Color = 0 Then // brush is white...
ApplyLine = pLine And (Not pMask)
Else // brush is black...
ApplyLine = pLine Or pMask
EndIf
End Function
{
********************************************************************************
* Name : Fill *
* Purpose : Fast fill screen area with brush color. *
* : Assumes pX1 < pX2 and pY1 < pY2 *
********************************************************************************
}
Public Sub Fill(pX1, pY1, pX2, pY2 As TXY)
Dim LastPosX As Word
Dim MaskL, MaskR As Byte
Dim Line As Byte
LastPosX = Pos.x
MaskL = $FF >> (pX1 Mod 8)
MaskR = $FF << (7 - pX2 Mod 8)
Pos.y = pY1
Repeat
Pos.x = pX1 / 8
Line = ReadByte()
If pX2 / 8 = pX1 / 8 Then // start & end of rectangle in same byte
WriteByte(ApplyLine(Line, MaskL And MaskR))
Else
WriteByte(ApplyLine(Line, MaskL))
Inc(Pos.x)
SetPosition()
Command(cmdDisplayWrite) // set to write to display memory
While Pos.x < pX2 / 8
If Brush.Color = 0 Then // brush is white...
SetData($00)
Else // brush is black...
SetData($FF)
EndIf
Inc(Pos.x)
Wend
Line = ReadByte() // right side of rectangle
WriteByte(ApplyLine(Line,MaskR))
EndIf
Inc(Pos.y)
Until Pos.y > pY2
End Sub
{
********************************************************************************
* Name : WriteImageByte (PRIVATE) *
* Purpose : Write an image byte to GLCD at pixel position x, y *
********************************************************************************
}
#define GLCD_SETIMAGE
Sub WriteImageByte(pX As Word, pY As Byte, pValue As Byte)
Dim Line, ShiftValue, XBit, XBitReverse As Byte
Dim LastPosX As Word
LastPosX = Pos.x // save x position
XBit = pX Mod 8 // offset
XBitReverse = 8 - XBit // reverse offset
Pos.x = pX / 8 // align to page
Pos.y = pY // save y
// get first byte...
Line = ReadByte
// mask, if needed...
If Pen.Mode = pmCopy Then
Line = Line >> XBitReverse
Line = Line << XBitReverse
EndIf
// merge then write data...
ShiftValue = pValue >> XBit
If Pen.Mode = pmXOR Then
Line = Line Xor ShiftValue
Else
Line = Line Or ShiftValue
EndIf
WriteByte(Line)
// get next byte...
If XBit <> 0 Then
Inc(Pos.x)
Line = ReadByte
// mask, if needed...
If Pen.Mode = pmCopy Then
Line = Line << XBit
Line = Line >> XBit
EndIf
// merge then write data...
ShiftValue = pValue << XBitReverse
If Pen.Mode = pmXOR Then
Line = Line Xor ShiftValue
Else
Line = Line Or ShiftValue
EndIf
WriteByte(Line)
EndIf
// restore x position...
Pos.x = LastPosX
End Sub
{
********************************************************************************
* Name : ReadImageByte (PRIVATE) *
* Purpose : Read an image byte *
********************************************************************************
}
Function ReadImageByte() As Byte
ASM-
TBLRD *+
movff TABLAT, result
End ASM
End Function
{
********************************************************************************
* Name : SetImage *
* Purpose : BitBlit image to GLCD at pixel location x, y. *
* : NOTE - This subroutine only supports $01 (monochrome) bitmaps. *
* : It requires images drawn with bytes in the x-direction. *
********************************************************************************
}
Public Sub SetImage(pX, pY As TXY, pImageAdr As Word, pMode As Byte = cmCopy)
Dim Image As TImage
Dim x,Width As Word
Dim y,Height As Byte
Dim Line As Byte
Dim LastPen As TPen
// get bitmap ID, width and height...
TABLEPTR = pImageAdr
Image.Header = ReadImageByte
Image.Width = ReadImageByte
Image.Height = ReadImageByte
Inc(TABLEPTR)
LastPen = Pen
Pen.Mode = pMode
// byte aligned bit blit...
x = pX
Width = Image.Width / 8
While Width > 0
y = pY
Height = Image.Height
While Height > 0
WriteImageByte(x,y,ReadImageByte)
Inc(y)
Dec(Height)
Wend
Inc(x, 8)
Dec(Width)
Wend
// non byte aligned bit blit...
pX = x
Image.Width = Image.Width Mod 8
If Image.Width > 0 Then
y = pY
Height = Image.Height
While Height > 0
Line = ReadImageByte
Width = Image.Width
x = pX
While Width > 0
Pen.Color = Line.7
SetPixel(x,y)
Line = Line << 1
Dec(Width)
Inc(x)
Wend
Dec(Height)
Inc(y)
Wend
EndIf
Pen = LastPen
End Sub
{
********************************************************************************
* Name : SetImage *
* Purpose : BitBlit image To GLCD at pixel location x, y. *
* : NOTE - This subroutine only supports $01 (monochrome) bitmaps. *
* : It requires images drawn with bytes in the x-direction. *
********************************************************************************
}
Public Sub SetImage(pX, pY As TXY, ByRefConst pImage() As Byte, pMode As Byte = cmCopy)
SetImage(pX, pY, @pImage, pMode)
End Sub
{
********************************************************************************
* Name : ShowLayer (Public) *
* Purpose : Turns on/off graphic layers *
********************************************************************************
}
Public Sub ShowLayer(pLayer As Byte, pOn As Boolean)
Layers.Bits(2 * pLayer) = Bit(pOn)
Command(cmdDisplayOn) // command for screen on
SetData(Layers) // sets layers 1 - 3, cursor off
End Sub
{
********************************************************************************
* Name : SwitchLayer (Public) *
* Purpose : Switches current drawing layer *
********************************************************************************
}
Public Sub SwitchLayer(pLayer As Byte)
CurrentLayer = pLayer
CurrentLayerMemPos = 9600 * (CurrentLayer - 1)
End Sub
{
********************************************************************************
* Name : Initialize *
* Purpose : Configure the GLCD before use. *
* : Set up ports for I/O and perform RESET on LCD *
********************************************************************************
}
Sub Initialize()
Dim i As Word
SetAllDigital()
Pos.x = 0
Pos.y = 0
#if GLCD_MODE = 6800
Output(EN) // enable
Output(RW) // read/write
#elseif GLCD_MODE = 8080
Output(RD) // read
Output(WR) // write
#endif
Output(A0) // data or instruction
Output(CS) // chip select
Output(RES) // reset
#if GLCD_MODE = 6800
DelayMS(GLCDDelay) // start up delay, allow GLCD to settle
RES = 0 // RES = 0 to reset
EN = 0 // start with EN = 0
A0 = 0
Data = 0
CS = 0
DelayMS(5)
RES = 1
DelayMS(10) // time for reset to finish
#elseif GLCD_MODE = 8080
RES = 1
RD = 1
WR = 1
A0 = 0
CS = 1
DelayMS(GLCDDelay) // start up delay, allow GLCD to settle
RES = 0 // RST = 0 to reset
DelayMS(5) // 1 ms minimum, 5ms for safety
RES = 1
DelayMS(5) // 3 ms minimum, 5ms for safety
CS = 1
#endif
Command(cmdSystem) // execute 'system set' instruction
DelayMS(1)
SetData($30) // control byte sets internal char gen (see DS)
SetData($87) // FX - horizontal char size - 1 (see DS)
SetData($07) // FY - vertical char size - 1
SetData($27) // C/R - bytes per line horizintally - 1
SetData($42) // TC/R - provides overscan idle time (see DS)
SetData($EF) // LF - height of frame in lines - 1 ($EF = 239)
SetData($28) // AP[L] - low byte of AP (horizontal address of virtual screen)
SetData($00) // AP[H] - high byte of AP (horizontal address of virtual screen)
Command(cmdScroll) // sets scroll address and lines per scroll block
SetData($00) // graphics layer 1 start[L] ($0000)
SetData($00) // graphics layer 1 start[H]
SetData($EF) // graphics layer 1 lines per block - 1 ($EF = 239)
SetData($80) // graphics layer 2 start[L] ($2580 = 9600 = 320 x 240 / 8)
SetData($25) // graphics layer 2 start[H]
SetData($EF) // graphics layer 2 lines per block - 1 ($EF = 239)
SetData($00) // graphics layer 3 start[L] ($4B00 = 19200 = 9600 + 320 x 240 / 8)
SetData($4B) // graphics layer 3 start[H]
SetData($00) // no graphics layer 4
SetData($00)
Command(cmdHDotScroll) // allow screen to scroll by pixels
SetData($00) // set to zero pixels
Command(cmdOverlay) // controls how graphics layers are combined
SetData($1C) // set to priority OR L1 > L2 > L3, all graphics layers
Command(cmdDisplayOff) // command for screen off...
SetData($54) // but sets screens 1 - 3 for turning on later
Command(cmdCsrForm) // select cursor size and shape
SetData($00) // cursor width - 1
SetData($80) // cursor height - 1 (plus block style)
Command(cmdCsrDirRight) // set cursor to increment to right
CsrMemPosition(0) // cursor at start of graphics layer 1
Command(cmdDisplayWrite) // set to write to display memory
For i = 1 To 28800 // clear layers 1 - 3 of display memory
SetData($00)
Next
CsrMemPosition(0) // cursor at start of graphics layer 1
Command(cmdDisplayOn) // command for screen on...
SetData($54) // for screens 1 - 3
Layers = %01010100 // default to all three graphics layers on (1 - 3)
SwitchLayer(1) // start with layer 1 as drawing layer
End Sub
(http://www.sfcompiler.co.uk/wiki/uploads/StevenWright/S1D13700_01.gif)
Hocam çok teşekkürler,
Bu kodların PICC için olanı mevcut mudur acaba ?
Saygılarımla,
Sitede her türlü kod var basic, ccs, swordfish gerisi sana kalmış arama yaptınızmı?
evet S1D13700 ve SED13700 olarak arama yaptım ama CCS için S1D13700 driver'ı henüz bulamadım .. CCS forumda yaptım aynı aramayı , orada bi arkadaş bi kod vermiş ama compile yapınca CCS kilitleniyor. ondan da cevap bekliyorum. CCS Forumdan aldığım kod aşağıda..
bir yandan da kendi donanımım ile ilgili bir problem mi var acaba diyorum .. DB0 - DB7 'yi portD'ye bağladım pin to pin.. diğerleri standart zaten.
/////////////////////////////////////////////////////////////////////////
//// SED13700.C ////
//// ////
/////////////////////////////////////////////////////////////////////////
#ifndef SED13700
#define SED13700
#ifndef GLCD_WIDTH
#define GLCD_WIDTH 320
#define LARGE_LCD
#else
#if GLCD_WIDTH>256
#define LARGE_LCD
#endif
#endif
#ifndef GLCD_HEIGHT
#define GLCD_HEIGHT 240
#else
#if GLCD_WIDTH>256
#ifndef LARGE_LCD
#define LARGE_LCD
#endif
#endif
#endif
#ifndef GLCD_CHAR_WIDTH
#define GLCD_CHAR_WIDTH 8
#endif
#ifndef GLCD_CHAR_HEIGHT
#define GLCD_CHAR_HEIGHT 8
#endif
#ifndef GLCD_RST
#define GLCD_RST PIN_C2
#endif
#ifndef set_tris_lcd
#define set_tris_lcd set_tris_d
#endif
#ifndef input_lcd
#define input_lcd input_d
#endif
#ifndef output_lcd
#define output_lcd output_d
#endif
#ifndef GLCD_RD
#define GLCD_RD PIN_E0
#endif
#ifndef GLCD_WR
#define GLCD_WR PIN_E1
#endif
#ifndef GLCD_CS
#define GLCD_CS PIN_C3
#endif
#ifndef GLCD_A0
#define GLCD_A0 PIN_E2
#endif
#ifndef ON
#define ON 1
#endif
#ifndef OFF
#define OFF 0
#endif
#define _t1 1
#define _t2 2
/////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////
// The following defines setup the memory used by different regions
// Currenty one text area is defined at the beginning of memory
// and a graphics area follows immediately after
/////////////////////////////////////////////////////////////////////////
#define GLCD_TEXT_ADDR 0x0000
#define GLCD_GRAPHICS_ADDR GLCD_WIDTH * GLCD_HEIGHT / 64
#define GLCD_GRAPHICS_ADDR_END GLCD_GRAPHICS_ADDR + (GLCD_WIDTH * GLCD_HEIGHT / 8)
/////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////
#if GLCD_CHAR_WIDTH < 9
#define GLCD_CR (GLCD_WIDTH/8 - 1)
#else
#define GLCD_CR (GLCD_WIDTH/4 - 2)
#endif
/////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////
#define TGLCD_COMMAND output_high(GLCD_A0);
#define TGLCD_DATA output_low(GLCD_A0);
/////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////
int8 glcd_readByte();
void glcd_sendByte(int8 data);
void glcd_fillScreen(int1 color);
void glcd_fillScreenText(char c);
void setCursorAddress(int16 addr);
void glcd_pixel(int16 x, int16 y, int1 color);
void glcd_sendCMD(int8 cmd);
int16 getCursorAddress();
int8 getData(int16 addr);
int8 getStatus();
/////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////
void glcd_systemSetup();
void glcd_scrollSetup();
void glcd_overlaySetup();
void glcd_power(int1 mode);
void glcd_cursorDirection(int8 dir);
void glcd_cursorForm(int8 width, int8 height);
void setData(int16 addr, int8 data);
/////////////////////////////////////////////////////////////////////////
#define GLCD_CMD_SYSTEM 0x40 // General system settings
#define GLCD_CMD_SLEEP 0x53 // Enter into standy mode
#define GLCD_CMD_DISP_OFF 0x58 // Turn the display off
#define GLCD_CMD_DISP_ON 0x59 // Turn the display on
#define GLCD_CMD_SCROLL 0x44 // Setup text and graphics address regions
#define GLCD_CMD_CSR_FORM 0x5D // Set cursor size
#define GLCD_CMD_CSRDIR_RIGHT 0x4C // Cursor moves right after write to display memory
#define GLCD_CMD_CSRDIR_LEFT 0x4D // Cursor moves left after write to display memory
#define GLCD_CMD_CSRDIR_UP 0x4E // Cursor moves up after write to display memory
#define GLCD_CMD_CSRDIR_DN 0x4F // Cursor moves down after write to display memory
#define GLCD_CMD_CGRAM_ADDR 0x5C // Configure character generator RAM address
#define GLCD_CMD_HDOT_SCR 0x5A // Set horizontal scroll rate
#define GLCD_CMD_OVERLAY 0x5B // Configure how layers overlay
#define GLCD_CMD_SET_CSR_ADDR 0x46 // Set the cursor address
#define GLCD_CMD_GET_CSR_ADDR 0x47 // Read the cursor address
#define GLCD_CMD_DISPLAY_WRITE 0x42 // Write to display memory
#define GLCD_CMD_DISPLAY_READ 0x43 // Read from display memory
// Purpose: Initialize the controller
// Inputs: The initialization mode
// OFF - Turns the LCD off
// ON - Turns the LCD on
void glcd_init(int1 mode)
{
// Initialze some pins
#ifdef GLCD_RST //Sup?e que o dispositivo ja foi resetado
output_high(GLCD_RST);
#endif
output_high(GLCD_CS);
output_high(GLCD_RD);
output_high(GLCD_WR);
glcd_systemSetup();
glcd_scrollSetup();
glcd_overlaySetup();
glcd_power(OFF);
glcd_cursorForm(4, 6);
glcd_fillScreen(OFF);
glcd_fillScreenText(' ');
glcd_power(mode);
glcd_cursorDirection(GLCD_CMD_CSRDIR_RIGHT);
}
// Purpose: Turn a pixel on a graphic LCD on or off
// Inputs: x - the x coordinate of the pixel
// y - the y coordinate of the pixel
// color - ON or OFF
void glcd_pixel(int16 x, int16 y, int1 color)
{
int8 data;
int16 addr;
// Calculate the byte address containing the pixel
addr = GLCD_GRAPHICS_ADDR + (GLCD_WIDTH/8 * y + x/8);
// Read the byte of data at the address
data = getData(addr);
// Turn the pixel on or off
if(color == ON)
bit_set(data, 7 - x%8);
else
bit_clear(data, 7 - x%8);
/* setData(0x0000, 49);
setData(0x0001, 50);
setData(0x0002, 51); uuuuuuuuuuuuuu
setData(0x0003, 52);
setData(0x0100, 49);
setData(0x0101, 50);
setData(0x0102, 51);
setData(0x0103, 52); */
// addr = getCursorAddress(); //hehe
// data = getData(0x0103);
// Write the new data byte to display memory
setData(addr, data);
}
// Purpose: Initialize the display environment
void glcd_systemSetup()
{
glcd_sendCMD(GLCD_CMD_SYSTEM); // Setup the system
TGLCD_DATA // Set for data
glcd_sendByte(0x30); // No offset
glcd_sendByte(0x7F + GLCD_CHAR_WIDTH); // Set character width
glcd_sendByte(GLCD_CHAR_HEIGHT - 1); // Set character height
glcd_sendByte(GLCD_CR); // Display line address range
glcd_sendByte(0x2F); // TC/R
glcd_sendByte(GLCD_HEIGHT - 1); // Number of lines per frame
glcd_sendByte(GLCD_CR + 1); // Horizontal address range LSB (APL)
glcd_sendByte((GLCD_CR + 1) / 0xFF); // Horizontal address range MSB (APH)
}
// Purpose: Set the scroll start address and
// the size of a scroll block
void glcd_scrollSetup()
{
// Currently setup for a text and graphics layer
glcd_sendCMD(GLCD_CMD_SCROLL); // Setup scrolling
TGLCD_DATA // Set for data
glcd_sendByte(GLCD_TEXT_ADDR); // SAD1L
glcd_sendByte(GLCD_TEXT_ADDR / 0xFF); // SAD1H
glcd_sendByte(GLCD_HEIGHT - 1); // SL1
glcd_sendByte(GLCD_GRAPHICS_ADDR); // SAD2L
glcd_sendByte(GLCD_GRAPHICS_ADDR / 0xFF); // SAD2H
glcd_sendByte(GLCD_HEIGHT - 1); // SL2
glcd_sendByte(0x00); // SAD3L
glcd_sendByte(0x00); // SAD3H
glcd_sendByte(0x00); // SAD4L
glcd_sendByte(0x00); // SAD4H
glcd_sendCMD(GLCD_CMD_HDOT_SCR); // Horizontal scroll rate
TGLCD_DATA // Set for data
glcd_sendByte(0x00); // Horizontal pixel shift is 0
}
// Purpose: Setup the overlay functionality for combining
// layers of text and graphics, or multiple
// graphics layers
void glcd_overlaySetup()
{
// Currently setup for a single graphics layer
glcd_sendCMD(GLCD_CMD_OVERLAY); // Text / graphic overlay mode
TGLCD_DATA // Set for data
glcd_sendByte(0x09); // Area 1 text, others graphics
// Text XOR Graphics
}
// Purpose: Turn the display on or off
// Inputs: ON to turn on or OFF to turn off
void glcd_power(int1 mode)
{
if(mode == ON)
{
glcd_sendCMD(GLCD_CMD_DISP_ON); // Turn the display on
}
else
{
glcd_sendCMD(GLCD_CMD_DISP_OFF); // Turn the display off
}
TGLCD_DATA // Set for data
glcd_sendByte(0x14);
}
// Purpose: Set the direction the cursor moves after
// writing to dispaly memory
// Inputs: Use one of the following to set the direction:
// GLCD_CMD_CSRDIR_RIGHT
// GLCD_CMD_CSRDIR_LEFT
// GLCD_CMD_CSRDIR_UP
// GLCD_CMD_CSRDIR_DOWN
void glcd_cursorDirection(int8 dir)
{
glcd_sendCMD(dir);
}
// Purpose: Set the size of the cursor
// Inputs: 1) The width in pixels - 1 Valid numbers: (0 - 15)
// 2) The height in pixels - 1 Valid numbers: (1 - 15)
void glcd_cursorForm(int8 width, int8 height)
{
glcd_sendCMD(GLCD_CMD_CSR_FORM); // Cursor form and size
TGLCD_DATA // Set for data
glcd_sendByte(width);
glcd_sendByte(0x80 + height);
}
// Purpose: Fill a graphics layer passed in color
// Works much faster than drawing a rectangle to fill the screen
// Inputs: ON - turn all the pixels on
// OFF - turn all the pixels off
void glcd_fillScreen(int1 color)
{
int16 i;
setCursorAddress(GLCD_GRAPHICS_ADDR);
glcd_sendCMD(GLCD_CMD_DISPLAY_WRITE);
TGLCD_DATA
for(i = GLCD_GRAPHICS_ADDR; i < GLCD_GRAPHICS_ADDR_END; ++i)
{
glcd_sendByte(0xFF * color);
}
}
// Purpose: Fill a text layer with a the passed in character
// Works much faster than drawing a rectangle to fill the screen
// Inputs: ON - turn all the pixels on
// OFF - turn all the pixels off
void glcd_fillScreenText(char c)
{
int16 i;
setCursorAddress(GLCD_TEXT_ADDR);
glcd_sendCMD(GLCD_CMD_DISPLAY_WRITE);
TGLCD_DATA
for(i = GLCD_TEXT_ADDR; i < GLCD_GRAPHICS_ADDR; ++i)
{
glcd_sendByte(c);
}
}
// Purpose: Write a byte of data
// Inputs: The byte of data to write
void glcd_sendByte(byte data)
{
output_lcd((data));
output_low(GLCD_CS);
delay_cycles(_t1);
output_low(GLCD_WR);
delay_cycles(_t2);
output_high(GLCD_WR);
output_high(GLCD_CS);
}
// Purpose: Read a byte of data
// Outputs: The byte of data
int8 glcd_readByte()
{
byte data;
set_tris_lcd(0xFF);
output_low(GLCD_CS);
delay_cycles(_t1);
output_low(GLCD_RD);
delay_cycles(_t2);
data = input_lcd();
output_high(GLCD_RD);
output_high(GLCD_CS);
return data;
}
// Purpose: Get the status
// Outputs: The status in an 8 bit integer
int8 getStatus()
{
int8 status;
TGLCD_DATA
output_low(GLCD_CS);
output_low(GLCD_RD);
delay_us(_t1);
status = input_lcd();
output_high(GLCD_RD);
output_high(GLCD_CS);
return status;
}
// Purpose: Get the current address of the cursor
// Outputs: A 16 bit integer containing the cursor address
int16 getCursorAddress()
{
int16 addr;
glcd_sendCMD(GLCD_CMD_GET_CSR_ADDR);
TGLCD_COMMAND //CORRECAO - MODIFIED LINE
// TGLCD_DATA; //CORRECAO
*(int8*)(&addr ) = glcd_readByte(); // Read low part
*(int8*)(&addr + 1) = glcd_readByte(); // Read high part
return addr;
}
// Purpose: Set the cursor address
// Inputs: A 16 bit integer containing the new cursor address
void setCursorAddress(int16 addr)
{
glcd_sendCMD(GLCD_CMD_SET_CSR_ADDR);
TGLCD_DATA
glcd_sendByte(*(int8*)(&addr ));
glcd_sendByte(*(int8*)(&addr + 1));
}
// Purpose: Get a byte of data from the display at the address
// Inputs: A 16 bit integer containing the address
// Outputs: An 8 bit integer with the read data
int8 getData(int16 addr)
{
setCursorAddress(addr);
glcd_sendCMD(GLCD_CMD_DISPLAY_READ);
TGLCD_COMMAND //CORRECAO - MODIFIED LINE
// TGLCD_DATA //CORRECAO
return glcd_readByte();
}
// Purpose: Set a byte of display data at an address
// Inputs: 1) A 16 bit address
// 2) 8 bits worth
void setData(int16 addr, int8 data)
{
setCursorAddress(addr);
glcd_sendCMD(GLCD_CMD_DISPLAY_WRITE);
TGLCD_DATA
glcd_sendByte(data);
}
// Purpose: Send an 8 bit command
// Inputs: The command to send
void glcd_sendCMD(int8 cmd)
{
TGLCD_COMMAND
glcd_sendByte(cmd);
}
#endif
Şimdilik ben düzelteyim.Sonraki kodlarını code tag'ları arasına alırsan daha iyi olur!
Kodlar çok fazla yer kaplıyor diye senin kodlarda düzelttim.
Hocam,
bugün sizin başka bir yerde verdiğiniz sinus egrisi kodunu compile ettim. SED1335 driver'ı olmasına ragmen görüntü alabildim. biraz bozukluklar var ama en azından lcdnin ve donanımımın çalıştığını anlamış oldum .
şimdi düzeltiğiniz driver ile deneyeceğim .
saygılarımla
murat
Ahmet Bey,
sinus egrisi kodundaki SED1335.C include dosyası yerine yeni driver'ı include ettim.
çalışıtırdığımda, ekrandaki pixeller düzenli olarak sönüyor ve yarıyarıya düzensiz olarak yanıyor (karıncalanma şeklinde) . bu bir döngü halinde devam ediyor.
saygılar,
Murat
320*240 SED1335 (RA8835) orijinli chiplerle çalışılırken en çok bocalamaya sebep olan konulardan birisi, bu çiplerin SEL1 pinlerinin kullanılan 8080 veya 6800 tipi sürücü kodlara uygun olarak datasheetine göre bağlanıp bağlanmadığıdır.Hazır gelen modüllerde bu 0OHM bir atlama direnciyle bağlı olur çoğu kez ve hangi seviyeye (1 veya 0)bağlı kontrol edilmez.Eğer bilhassa LCDden hatalı okuma problemleri var ise bu pinin durumunu veya pozisyonuna uygun olan kodların kullanılıp kullanılmadığını kontrol etmek gerekir...Mesela winstar WG320240 LCD ler modül olarak SEL1 pinleri VDD ye bağlıdır. Bu modülde 8080 e göre kodlarla çalışırsanız okuma sırasında b'00000000' olması gereken bytelar b'11000000' olarak okunur.......
Hocam Teşekkürler ,
Hemen dediklerinizi kontrol ediyorum ..
Saygılar,
Murat
SEL'leri de denedim .. olmadı malesef.
sanırım bende init problemi var.
ekranı ilk açtığımda hiç bir şey çıkmıyor. PIC'in MCLR'sinden reset verdiğimde bir kaç kez herhangi bir resette LCD ekranındaki pixellerin bazıları (karışık bir şekilde yarıyarıya) ON oluyor. Ama ilginç olan her defasında aynı pixellerin ON olması.
çalışmaya devam . acemilik başka türlü atılmıyor.. :)
benim de bir glcd projem olsun istedim amacım ve malzemeler aşağıdadır
winstar wg320*240c0-tmı-vzn bi mavi renkli beyaz karakter yazan glcd ile uğraşıyorum. Buradaki pinler öğrendiğim kadarıyla farklı hatta yukardada yazmışsınız hocam, ben bu konuda değil ama pbp da yazmaya çalışıyorum ete hocamızın verdiği bi projeye bakarak ve feyz alarak değişiklikler yaptım ve programım çalışı fakat 128*64 tü aynı kodlarla olacağını sanarak ben 320*240 ta yazar gibi satır satır yazdım hexleri sonuç bayadır araştırıyorum bu iş nasıl oluyor diye satın aldığım yerin tavsiyesi üzerine bu işi yapan biriyle konuştum bana bendekinden daha gelişmiş bi datasheet gönderdi. sonuç olarak :D hepten kafa gitti bu arada 1 adet cs olduğundan dolayı bile 3-4 gün araştırmayla geçti "know how " hocam sorum micro code studio plus ile yazabilirmiyim proton derseniz hangi protonla birsürü var bi çoğu da açılmıyor zaten. En son olarak 18f4520 kullanmayı düşünürken ne olu ne olmaz diye kodu kısaltıp 16f877a ya döndüm kodumu buraya eklesem bakabilirmisiniz saygılar
TrisD=0
Trisc=0
TRISB=0
trise=0
X var Byte
Y var Byte
EK VAR Byte
BAS VAR Byte
SON VAR Byte
SATIR VAR Byte '
SUTUN VAR Byte
INS CON 63
YAD CON 183'SATIR BAŞLANGIC ADRESİ
XAD con 64 'SUTUN BAŞLANGIÇ ADRESİ
Symbol ENBL=PORTC.0
Symbol CS1 =PORTE.0
'SYMBOL CS2 =PORTB.2
Symbol RW =PORTC.2
Symbol DI =PORTC.1
'ISIS de AMPIRE 128x64 LCD kullanıldı.
'ENABLE Port.C0 da
'R/W Port.C1 de
'RS (D/I) Port.C2 de
'CS1 Port.C7 Da
'CS2 Port.C6 De
'Data D0-D7 PortD ye bağlı
Low PORTC.5
BASLA: EK=3
ENBL=0 'ENABLE 0 YAPILDI
CS1=0 'CS1 SEÇİLDİ
'CS2=0 'CS2 SEÇİLDİ
RW=0 'RW LOW YAPILDI YANİ YAZMA MODU
DI=0 'D/I BACAĞI LOW YAPILDI YANİ INSTRUCTION
PORTD=INS 'DİSPLAY ON YAPILDI
GoSub ONAY
PORTD=(YAD+0) 'X=0 nolu satırda
GoSub ONAY
PORTD=(XAD+0)'Y=80 NOLU SIRADA
GoSub ONAY
'-------------EKRAN SIFIRLAMA ---YANİ EKRANA SIFIR YAZMA-----------------------
SATIR=0:DI=1
PORTD=0
For X=0 To 1
For Y=0 To 255
PORTD=0
GoSub ONAY
Next Y
PORTD=(YAD+4):DI=0:GoSub ONAY:DI=1
Next X
'________________________________________________________________________________
' SATIR=0:SUTUN=0:CS2=1:GOSUB YOL 'CS2=1 YAPILINCA İKİNCİ CHIP KAPATILDI :
'________________________________________________________________________________
'1.SATIR,SOL
SATIR=0:CS1=0:GoSub YOL
For X=0 To 160
LookUp X,[$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00_
,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00_
,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00_
,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00_
,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00_
,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00_
,$00,$00,$80,$80,$C0,$C0,$C0,$C0,$C0,$C0,$E0,$E0,$E0,$F0,$F0,$F0,$F0,$F0,$F0,$F0_
,$F0,$F0,$F0,$F0,$F0,$F0,$F0,$F0,$F0,$F0,$F0,$70,$70,$70,$70,$70,$70,$70,$70,$70],PORTD
GoSub ONAY:Next X
'____________
'1.SATIR,SAĞ
SATIR=0:CS1=1:GoSub YOL
For X=0 To 160
LookUp X,[$70,$70,$F0,$E0,$E0,$E0,$E0,$C0,$C0,$C0,$C0,$C0,$80,$80,$80,$00,$00,$00,$00,$00_
,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00_
,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00_
,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00_
,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00_
,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00_
,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00_
,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00],PORTD
GoSub ONAY:Next X
'--------------------ALT PROGRAMLAR -----------------------------------
ONAY:
ENBL=1:PAUSEUS 10:ENBL=0
Return
YOL: DI=0:PORTD=(YAD+SATIR):GoSub ONAY
PORTD=(XAD+SUTUN):GoSub ONAY:DI=1
Return
SIL:
For X=3 To 4
DI=0:PORTD=(YAD+X):GoSub ONAY
PORTD=(XAD+BAS):GoSub ONAY:DI=1
For Y=BAS To SON
PORTD=0:GoSub ONAY
Next Y
Next X
Return
YAZ:
For X=3 To 4
DI=0:PORTD=(YAD+X):GoSub ONAY
PORTD=(XAD+BAS):GoSub ONAY:DI=1
For Y=BAS To SON
PORTD=255:GoSub ONAY
Next Y
Next X
Return
yardımcı olursanız inanın çok sevinirim sitede gördüm herkez sen daha öğrenmedin mi falan diyo kaçırırsam hiç öğrenemiyeceğim şimdiden yardımlarınız için teşekkür ederim
sonbişey daha programda 'ete hocanın' programında cs1 ve cs2 mevcuttu winstar da 1 adet cs olduğu için ben kaldırım denedim ama tabii ki başaramadım .. iyi çalışmalar tekrar elinize saağlık
merhaba uzun zamandır glcd ile çalışmıyordum derken tekrar iş ile ilgili mecburen glcd de proje hazırlamam lazım diye ama bazı şeyleri unutmuşum araştırırken aa bi baktım aynı yerdeyim.
neyse 2009 daki projede yazdıklarım yolun basındayken bilmeden yazmısım.kısa süre sonra işi halletmiştim.
aslında 320*240 t6963c kullanıyorum şu an da protonda yazıyorum yardım isteyenler özelden mesaj atabilirler.
umarım ben de birine faydalı olurum. iyi çalışmalar...
Alıntı yapılan: oooben - 05 Ocak 2015, 03:17:26
yardım isteyenler özelden mesaj atabilirler.
umarım ben de birine faydalı olurum. iyi çalışmalar...
Faydalı olmak için bir forumu kullanırız ÖM değil..
ne demek istediginizi tam olarak anlamadim ama niyetim kotu degil sanirim siz biraz gerginsiniz
sorarsaniz bilgim dahilinde bu konuda burda yazarim zaten amac bu degil mi
Niçin gerginlik olsun,
Arkadaşlara hatırlatıyoruz. Forumun amacı yardımlaşmak ise, bilgi aktarımı ÖM ile değil, herkese açık paylaşım ile olabilir..
pardon ya cepten swiftkey le yaziyorum tamamliyo
ya o ya jben ozel yazmisim burdan yazicaktim anladim simdi bende niye tepkili davrandiniz anlayakamistim
tekrar pardon