اطلاعیه

Collapse
No announcement yet.

حرکت متن یاتصویر روی glcd

Collapse
X
 
  • فیلتر
  • زمان
  • Show
Clear All
new posts

    حرکت متن یاتصویر روی glcd

    سلام بااستفاده کتابخانه موجود درسایت، glcd ks0108رو راه اندازی کردیم
    حال می خواهیم تابعی به این کتابخانه اضافه کنیم که با آن بتوانیم تصاویریا نوشته هارا به حرکت درآوریم
    مثلا تصویری روی glcdقرار گرفته می خواهیم با شیفت تصویر موجود، تصویر جدیدرا وارد کنیم راهنمایی کنید

    این کتابخانه مورد استفاده قرار گرفته
    /*
    Graphic Lcd KS0108 controller Library
    */

    #include <delay.h>
    #include <font_e.h>
    #include <font_f.h>
    //------------------------------------ Definitions ------------------------------------
    #ifndef GLCDTYPE
    #define GLCDTYPE KS0108 // Graphic Lcd Controller type
    #endif
    // Default Port definition
    #ifndef RS
    #define RS PORTD.2
    #endif
    ///*
    #ifndef RW
    #define RW PORTD.3
    #endif
    //*/
    #ifndef EN
    #define EN PORTD.7
    #endif
    #ifndef CS1
    #define CS1 PORTD.6
    #endif
    #ifndef CS2
    #define CS2 PORTD.5
    #endif
    /*
    #ifndef RST
    #define RST PORTD.4
    #endif
    */
    #ifndef DATA
    #define DATA PORTC
    #endif
    //---------------------------------------------------------------------------------------


    //------------------------------------ Functions ------------------------------------
    // Initialize Graphic LCD
    void glcd_Init()
    {
    int i=0,com[4] = {0xc0,0xb8, 0x40, 0x3f};

    RS = 0;
    while(i<4)
    {
    write_left(com[i]);
    i++;
    }
    i=0;
    while(i<4)
    {
    write_right(com[i]);
    i++;
    }
    }

    // Clear Lcd screen
    void glcd_Clear()
    {
    unsigned char page[8]={0xb8,0xb9,0xba,0xbb,0xbc,0xbd,0xbe,0xbf };
    int i=0,j=0,index=0;
    while(index<1024)
    {
    address_left(page[i],0x40);
    RS=1;
    for(j=0;j<64;j++)
    {
    write_left(0);
    index++;
    }
    address_right(page[i],0x40);
    RS=1;
    for(j=0;j<64;j++)
    {
    write_right(0);
    index++;
    }
    i++;
    }
    }

    // Write a byte in Row x{0..7} and Column y{0..127}
    void glcd_WriteByte(unsigned char x, unsigned char y, unsigned char data)
    {
    //unsigned char j;

    if(y<64) // Left
    {
    address_left(((x|0b10111000)&0b10111111)
    ,((y|0b01000000)&0b01111111));
    RS = 1;
    write_left(data);
    }
    else // Right
    {
    y -= 64;
    address_right(((x|0b10111000)&0b10111111)
    ,((y|0b01000000)&0b01111111));
    RS = 1;
    write_right(data);
    }
    }

    // Drawing a pattern that is stored in FLASH memory
    void glcd_DrawF(flash unsigned char Pat[])
    {
    unsigned char i,j;
    unsigned int k=0;

    for( i= 0; i<8; i++)
    for( j =0; j<128; j++)
    glcd_WriteByte(i,j,Pat[k++]);
    }

    // Drawing a pattern that is stored in SRAM memory
    void glcd_Draw(unsigned char Pat[])
    {
    unsigned char i,j;
    unsigned int k=0;

    for( i= 0; i<8; i++)
    for( j =0; j<128; j++)
    glcd_WriteByte(i,j,Pat[k++]);
    }

    // Drawing a pattern that is stored in FLASH memory from dot[x,y] until width w and Height h
    void glcd_DrawBmpF(flash unsigned char Pat[],
    unsigned char x, unsigned char y,
    unsigned char h,unsigned char w)
    {
    unsigned char i,j;
    unsigned int k=0;
    h--;
    for( i= x ; i<x+h+1; i++)
    for( j =y ; j<y+w+1; j++)
    {
    k = (unsigned int)(i-x)*(w+1)+(unsigned int)(j-y);
    glcd_WriteByte(i,j,Pat[k]);
    }
    }

    // Drawing a pattern that is stored in SRAM memory with start point[x,y] until width w and Height h
    void glcd_DrawBmp(unsigned char Pat[],
    unsigned char x, unsigned char y,
    unsigned char h,unsigned char w)
    {
    unsigned char i,j;
    unsigned int k=0;
    h--;
    for( i= x ; i<x+h+1; i++)
    for( j =y ; j<y+w+1; j++)
    {
    k = (unsigned int)(i-x)*(w+1)+(unsigned int)(j-y);
    glcd_WriteByte(i,j,Pat[k]);
    }
    }

    // Put a string Text in LCD with start point[x,y]
    void glcd_fprint(unsigned char x, unsigned char y,char* str)
    {
    y=120-y;
    while (*str )
    {

    glcd_Putchare(x,y,*(str++)+91 );

    y-=8;

    }
    }
    //font 16 ***************************************
    void glcd_fprint16(unsigned char x, unsigned char y,char* str)
    {
    y=120-y;
    while (*str )
    {

    glcd_Putcharf(x,y,*(str++) );

    y-=8;

    }
    }
    //**************************
    void glcd_eprint(unsigned char x, unsigned char y,char* str)
    {
    while (*str )
    {

    glcd_Putchare(x,y,*str++ );

    y+=6;
    }
    }
    // Put a charachter in point[x,y]
    void glcd_Putchare(unsigned char x, unsigned char y,unsigned char ch)
    {
    unsigned char i;
    ch-=32;
    for(i=0;i<8;i++)
    {
    glcd_WriteByte(x,y,FontLookup[ch][i]);
    y++;
    };

    }

    // Put a charachter16 in point[x,y]
    void glcd_Putcharf(unsigned char x, unsigned char y,unsigned char ch)
    {
    unsigned char i;
    unsigned char z;
    ch-=32;

    // for(i=0;i<16;i++)


    do{


    glcd_WriteByte(x,y,Font16Lookup[ch][i]);
    y++;
    i++;
    }while(i<8);
    do{


    glcd_WriteByte(x+1,y-8,Font16Lookup[ch][i]);
    y++;
    i++;
    }while(i<16);


    }
    //---------------------------------------------------------------------------------------

    void shiftdown()
    { char i,j;
    for(i=64;i>0;i--){
    for(j=0;j<2;j++)
    {
    CS1=~CS1;
    CS2=~CS1;
    RS=0;
    RW=0;
    DATA=0xC0 | i;
    delay_us(7);
    EN=1;
    delay_us(7);
    EN=0;
    }
    delay_ms(50);
    }
    }
    //-----------------------
    void shiftup()
    { char i,j;
    for(i=0;i<=64;i++){
    for(j=0;j<2;j++){
    CS1=~CS1;
    CS2=~CS1;
    RS=0;
    //RW=0;
    DATA=0xC0 | i;
    delay_us(7);
    EN=1;
    delay_us(7);
    EN=0;
    }
    delay_ms(50);
    }
    }

    //-----------------------

    //---------------------------------- LCD's methods ---------------------------------


    inline void address_right(int x,int y)
    {
    RS = 0;
    write_right(x);
    write_right(y);
    }


    inline void address_left(int x,int y)
    {
    RS = 0;
    write_left(x);
    write_left(y);
    }

    inline void write_right(unsigned char x )
    {
    CS1 = 0;
    CS2 = 1;
    delay_us(10);
    DATA = x;
    EN = 1;
    delay_us (10);
    EN = 0;
    CS1 = 0;
    CS2 = 0;
    }

    inline void write_left(unsigned char x)
    {
    CS1 = 1;
    CS2 = 0;
    delay_us(10);
    DATA = x;
    EN = 1;
    delay_us (10);
    EN = 0;
    CS1 = 0;
    CS2 = 0;
    }

    //---------------------------------------------------------------------------------------



لطفا صبر کنید...
X