⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 glcd.c

📁 Samsung S65 LCD Library
💻 C
字号:
/*
 Port&Copyright:      Mark de Jong, mail to mark at mdejong.de
 Port&Copyright:      Christian Kranz, mail to cnkz at yahoo.com
 Original Copyright:  Hagen Reddmann  mailto HaReddmann at T-Online dot de
 Author:              Hagen Reddmann
 Remarks:             this Copyright must be included
 known Problems:      none
 Version:             0.1. 2005
 Description:         Graphic Library for Siemens S65, M65, CX65 and RX65 Display
*/

#include "SPI_driver_if.h"
#include "glcd.h"

#ifdef __C166__
const uint16_t INIT1[] = {
                            0xEF00, 0xEE04, 0x1B04, 0xFEFE, 0xFEFE, 0xEF90, 0x4A04,
                            0x7F3F, 0xEE04, 0x4306 
                         };

const uint16_t INIT2[] = {
                            0xEF90,  0x0983,  0x0800,  0x0BAF,  0x0A00,  0x0500,  0x0600,
                            0x0700,  0xEF00,  0xEE0C,  0xEF90,  0x0080,  0xEFB0,  0x4902, 
                            0xEF00,  0x7F01,  0xE181,  0xE202,  0xE276,  0xE183
                         };

const uint16_t INIT3[] = { 
                            0xE202,  0xE276,  0xE183
                         };

const uint16_t INIT4[] = {
                            0x8001
                         };
#endif

uint8_t         glcd_MemCtrl;  // display RAM access and degree of rotation
glcdFlags_t     glcd_Flags;    // glcd lib flags
glcdColor_t     glcd_Colors[1 << COLOR_TABLE_BITS];

#ifdef USE_CLIPPING
glcdRect_t      glcd_Clip;            // clipping coordinates, only paint operation in this rect are visible
#endif

glcdRect_t      glcdScreen;           // physical dimensions of the screen

glcdPoint_t     glcd_Cursor;          // current cursor for painting characters
glcdRect_t      glcd_Window;          // text output window, AutoLineFeed checks this
uint8_t            glcd_FontFirstChar;   // first defined character in selected font
uint8_t            glcd_FontLastChar;    // last defined character in selected font
uint8_t         glcd_FontWidth;       // character width for fixed pitch of selected font
uint8_t         glcd_FontHeight;      // character height of selected font
uint8_t         glcd_FontBitsPixel;   // color depth of selected font, if MSB is set the font is compressed
uint16_t        glcd_FontSize;          // Font size
glcdFontFunc_t              glcd_FontRead;        // User definierte Readcallback f黵 die Fontdaten
glcdFontData_t  *glcd_FontData;        // pointer to font data, a read callback can store own values here
                                             // the lib access trough this pointer ONLY if glcd_FontRead == NULL to flash
                                             // otherwise this value is a paramter to the user callback

void glcdDisplayByte(uint8_t cmd) // send a byte to display
{
    SPI_driver_send_byte( cmd );
}

void glcdDisplayWord(uint16_t cmd) // send a word to display
{
    SPI_driver_send_word( cmd );
}

void glcdDisplayCommand(uint16_t cmd) // send a command to display
{
    io_reset_io( S65_IO_CS );
    io_set_io( S65_IO_RS );
    SPI_driver_send_word( cmd );
    io_set_io( S65_IO_CS );
}

void glcdDisplayData(uint16_t data)   // send data to display
{
    io_reset_io( S65_IO_CS );
    io_reset_io( S65_IO_RS );
    SPI_driver_send_word( data );
    io_set_io( S65_IO_CS );
}

void glcdDisplayBufferWord( uint16_t *buffer, uint8_t buffersize, uint8_t flashstored) // send a buffer of words to the display
{
    unsigned int counter;                                                           
    flashstored = flashstored;
    for( counter=0; counter<buffersize; counter++ )
    {
        glcdDisplayWord( *buffer++ );
    }
}

void glcdDisplayBufferByte( uint8_t *buffer, uint8_t buffersize, uint8_t flashstored) // send a buffer of bytes to the display
{
    unsigned int counter;
    flashstored = flashstored;
    for( counter=0; counter<buffersize; counter++ )
    {
        glcdDisplayByte( *buffer++ );
    }
}

void glcdDisplayBufferCommand( uint16_t *buffer, uint8_t buffersize, uint8_t flashstored) // send a buffer of bytes as command to the display
{
    unsigned int counter;
    flashstored = flashstored;
    io_reset_io( S65_IO_CS );
    io_set_io( S65_IO_RS );
    for( counter=0; counter<buffersize; counter++ )
    {
        glcdDisplayWord( *buffer++ );
    }
    io_set_io( S65_IO_CS );
}

void glcdDisplayBufferData( uint16_t *buffer, uint8_t buffersize, uint8_t flashstored) // send a buffer of bytes as data to the display
{
    unsigned int counter;
    flashstored = flashstored;
    io_reset_io( S65_IO_CS );
    io_reset_io( S65_IO_RS );
    for( counter=0; counter<buffersize; counter++ )
    {
        glcdDisplayWord( *buffer++ );
    }
    io_set_io( S65_IO_CS );
}


void glcdDisplayInit(void)           // initialize the display, MUST be normaly NEVER called, it's automaticaly called by the initialization code
{
    // set start-up levels
    io_reset_io( S65_BACKLIGHT_POWER );
    io_reset_io( S65_POWER );
    io_reset_io( S65_IO_RESET );

    io_set_dir_out( S65_POWER );
    io_set_dir_out( S65_IO_RESET );
    io_set_dir_out( S65_BACKLIGHT_POWER );

// power-up of display
    io_set_io( S65_POWER );
    glcdWait( 250 );
    
    io_set_io( S65_IO_CS );
    io_set_io( S65_IO_RS );
    
    // set port directions
    
    io_set_dir_out( S65_IO_RS );
    io_set_dir_out( S65_IO_CS );
    io_set_dir_out( S65_IO_DATA );
    io_set_dir_out( S65_IO_CLK );

    SPI_driver_init( SPI_WORDS );

    io_set_io( S65_IO_DATA );
    io_set_io( S65_IO_CLK );
    glcdWait( 5 );

// start init of display
    io_set_io( S65_IO_RESET );
    glcdWait( 50 );

// Software reset   
    io_reset_io( S65_IO_CS );
    io_set_io( S65_IO_RS );
    glcdDisplayWord( 0xFDFD );
    glcdDisplayWord( 0xFDFD );
    io_set_io( S65_IO_CS );

    glcdWait( 68 );

// init part 1 of display
    glcdDisplayBufferCommand( (uint16_t *)&INIT1, sizeof(INIT1)/2, 0 );
    glcdWait( 8 );

// init part 2 of display
    glcdDisplayBufferCommand( (uint16_t *)&INIT2, sizeof(INIT2)/2, 0 );
    glcdWait( 50 );

// init part 3 of display
    glcdDisplayBufferCommand( (uint16_t *)&INIT4, sizeof(INIT4)/2, 0 );
    glcdWait( 5 );

    io_reset_io( S65_IO_CS );
    io_set_io( S65_IO_RS );
    glcdDisplayWord( 0xEF90 );
    glcdDisplayWord( 0x0000 );
    io_set_io( S65_IO_CS );

    glcdSetOrientation( ORIENTATION_90 );
    glcdSetRect(glcd_Clip, SCREEN_LEFT, SCREEN_TOP, SCREEN_RIGHT, SCREEN_BOTTOM);
#ifdef USE_FONTS
    glcdSetRect(glcd_Window, SCREEN_LEFT, SCREEN_TOP, SCREEN_RIGHT, SCREEN_BOTTOM);
#endif

    glcdSetBkColor(SCREEN_COLOR);     // Hintergrund
    glcdSetFgColor(BLACK);            // Vordergrund
    glcdSetFrColor(GRAY);             // Rahmen
    glcdSetShColor(SILVER);           // Schatten

// clear screen
    glcdClearScreen();

// turn-on backlight
    glcdBackLightOn();
}

void glcdDisplayOn(void)             // switch display on, booster on, sleep out
{
    glcdDisplayCommand( 0x8001 );
}

void glcdDisplayOff(void)            // switch display off, booster off, sleep in
{
    glcdDisplayCommand( 0x8000 );
}

void glcdPowerOn(void)           // switch backlight on
{
    // switch backlight on
    io_set_io( S65_POWER );
}

void glcdPowerOff(void)          // switch backlight off
{
    // switch backlight of
    io_reset_io( S65_POWER );
}

void glcdBackLightOn(void)           // switch backlight on
{
    // switch backlight on
    io_set_io( S65_BACKLIGHT_POWER );
}

void glcdBackLightOff(void)          // switch backlight off
{
    // switch backlight of
    io_reset_io( S65_BACKLIGHT_POWER );
}

void glcdWait(uint16_t ms)           // wait some milliseconds, XTAL must be correct defined
{
    #define MILLSECOND 0x88

    volatile unsigned long counter;
    for( counter=0; counter< (ms*MILLSECOND); counter++);
}

void glcdFillScreen(uint16_t color)
{
    unsigned int counter;

    io_reset_io( S65_IO_CS );
    io_set_io( S65_IO_RS );
    glcdDisplayWord( 0xEF90 );
    if( glcd_MemCtrl & (1 << MEM_90) )
    {
        glcdDisplayWord( 0x0500 );
    }
    else
    {
        glcdDisplayWord( 0x0504 );
    }
    glcdDisplayWord( 0x0600 );
    glcdDisplayWord( 0x0700 );
    glcdDisplayWord( 0x0800 );
    glcdDisplayWord( 0x0900 + SCREEN_WIDTH -1 );
    glcdDisplayWord( 0x0A00 );
    glcdDisplayWord( 0x0B00 + SCREEN_HEIGHT -1 );
    io_reset_io( S65_IO_RS );
    for( counter=0; counter<(SCREEN_WIDTH*SCREEN_HEIGHT); counter++ )
    {
        glcdDisplayWord( color );
    }
    io_set_io( S65_IO_CS );

}

void glcdSetOrientation(uint8_t orientation) // degree 0

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -