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

📄 lcd_drv.c

📁 阳初ucosII ADS1.2程序带VGA显示
💻 C
📖 第 1 页 / 共 2 页
字号:
    //
    Sem_LcdDraw = OSSemCreate(1);                   /* 创建1个信号量,初值为1   */
  rLCDCON1 = rLCDCON1 | 1;
}

void Lcd_Switch(int cmd)
{
    if (cmd)
    {
        rLCDCON1 |= 1;
    }
    else
    {
        rLCDCON1 &= (~((unsigned int)1));
    }
}

void Lcd_White(void)
{
    memset((unsigned char *)__LCDFrameBuffer, 0xff, VIDEO_VISIBLE_COLS*VIDEO_VISIBLE_ROWS*VIDEO_PIXEL_SIZE);
}

void Lcd_Cls()
{
    memset((unsigned char *)__LCDFrameBuffer,0,VIDEO_VISIBLE_COLS*VIDEO_VISIBLE_ROWS*VIDEO_PIXEL_SIZE);
}

void Glib_PutPixel(unsigned int x , unsigned int y , unsigned int c)
{
    //unsigned char *fb;
    
        unsigned char rcolor = (c>>16)&0xff;
        unsigned char gcolor = (c>>8)&0xff;
        unsigned char bcolor = c&0xff;

    if( x < VIDEO_VISIBLE_COLS && y < VIDEO_VISIBLE_ROWS )
    {
        *(unsigned short *)(__LCDFrameBuffer + ((y) * VIDEO_VISIBLE_COLS + (x))*VIDEO_PIXEL_SIZE) = //c;
                              (((rcolor>>3)<<11)|((gcolor>>2)<<5)|(bcolor>>3)); // lcd format 5:6:5 for 2440
    }
}

static void Lcd_PutASCII(unsigned int x,unsigned int y,unsigned char ch,unsigned int c,unsigned int bk_c,unsigned int st)
{
    unsigned short int i,j;
    unsigned char *pZK,mask,buf;
    

    pZK = &__VGA[ch*16];
    for( i = 0 ; i < 16 ; i++ )
    {
        mask = 0x80;
        buf = pZK[i];
        for( j = 0 ; j < 8 ; j++ )
        {
            if( buf & mask )
            {
                Glib_PutPixel(x+j,y+i,c);
            }else
            {
                if( !st )
                {
                    Glib_PutPixel(x+j,y+i,bk_c);
                }
            }
            
            mask = mask >> 1;
        }
    }
}


void Lcd_PutHZ(unsigned int x,unsigned int y,unsigned short int QW,unsigned int c,unsigned int bk_c,unsigned int st)
{
    /*This Function is EMPTY now, pls contact with FriendlyARM */
    return ;
}
//----------------------
void Lcd_printf(unsigned int x,unsigned int y,unsigned int c,unsigned int bk_c,unsigned int st,char *fmt,...)
{
    char __LCD_Printf_Buf[256];
    va_list ap;
    unsigned char *pStr = (unsigned char *)__LCD_Printf_Buf;
    unsigned int i = 0;

    va_start(ap,fmt);
    vsprintf(__LCD_Printf_Buf,fmt,ap);
    va_end(ap);
     
    while(*pStr != 0 )
    {
        switch(*pStr)
        {
            case '\n' :
                {
            
                    break;
                }

            default:
                {
                    if( *pStr > 0xA0 & *(pStr+1) > 0xA0 )  //中文输出
                    {
                        Lcd_PutHZ( x , y , (*pStr - 0xA0)*0x0100 + *(pStr+1) - 0xA0 , c , bk_c , st);

                        pStr++;
                        i++;

                        x += 16;
                    }else               //英文输出
                    {
                        Lcd_PutASCII( x , y , *pStr , c , bk_c , st );

                        x += 8;

                    }

                    break;
                }
        }
        
        pStr++;
        i++;        

        if( i > 256 ) break;
    }
}


void Glib_Rectangle(unsigned int x1,unsigned int y1,unsigned int x2,unsigned int y2,unsigned int color)
{
    Glib_Line(x1,y1,x2,y1,color);
    Glib_Line(x2,y1,x2,y2,color);
    Glib_Line(x1,y2,x2,y2,color);
    Glib_Line(x1,y1,x1,y2,color);
}



void Glib_FilledRectangle(unsigned int x1,unsigned int y1,unsigned int x2,unsigned int y2,unsigned int color)
{
    int i;

    for(i=y1;i<=y2;i++)
    Glib_Line(x1,i,x2,i,color);
}



// LCD display is flipped vertically
// But, think the algorithm by mathematics point.
//   3I2
//   4 I 1
//  --+--   <-8 octants  mathematical cordinate
//   5 I 8
//   6I7
void Glib_Line(unsigned int x1,unsigned int y1,unsigned int x2,unsigned int y2,unsigned int color)
{
    int dx,dy,e;
    dx=x2-x1; 
    dy=y2-y1;
    
    if(dx>=0)
    {
        if(dy >= 0) // dy>=0
        {
            if(dx>=dy) // 1/8 octant
            {
                e=dy-dx/2;
                while(x1<=x2)
                {
                    Glib_PutPixel(x1,y1,color);
                    if(e>0){y1+=1;e-=dx;}   
                    x1+=1;
                    e+=dy;
                }
            }
            else        // 2/8 octant
            {
                e=dx-dy/2;
                while(y1<=y2)
                {
                    Glib_PutPixel(x1,y1,color);
                    if(e>0){x1+=1;e-=dy;}   
                    y1+=1;
                    e+=dx;
                }
            }
        }
        else           // dy<0
        {
            dy=-dy;   // dy=abs(dy)

            if(dx>=dy) // 8/8 octant
            {
                e=dy-dx/2;
                while(x1<=x2)
                {
                    Glib_PutPixel(x1,y1,color);
                    if(e>0){y1-=1;e-=dx;}   
                    x1+=1;
                    e+=dy;
                }
            }
            else        // 7/8 octant
            {
                e=dx-dy/2;
                while(y1>=y2)
                {
                    Glib_PutPixel(x1,y1,color);
                    if(e>0){x1+=1;e-=dy;}   
                    y1-=1;
                    e+=dx;
                }
            }
        }   
    }
    else //dx<0
    {
        dx=-dx;     //dx=abs(dx)
        if(dy >= 0) // dy>=0
        {
            if(dx>=dy) // 4/8 octant
            {
                e=dy-dx/2;
                while(x1>=x2)
                {
                    Glib_PutPixel(x1,y1,color);
                    if(e>0){y1+=1;e-=dx;}   
                    x1-=1;
                    e+=dy;
                }
            }
            else        // 3/8 octant
            {
                e=dx-dy/2;
                while(y1<=y2)
                {
                    Glib_PutPixel(x1,y1,color);
                    if(e>0){x1-=1;e-=dy;}   
                    y1+=1;
                    e+=dx;
                }
            }
        }
        else           // dy<0
        {
            dy=-dy;   // dy=abs(dy)

            if(dx>=dy) // 5/8 octant
            {
                e=dy-dx/2;
                while(x1>=x2)
                {
                    Glib_PutPixel(x1,y1,color);
                    if(e>0){y1-=1;e-=dx;}   
                    x1-=1;
                    e+=dy;
                }
            }
            else        // 6/8 octant
            {
                e=dx-dy/2;
                while(y1>=y2)
                {
                    Glib_PutPixel(x1,y1,color);
                    if(e>0){x1-=1;e-=dy;}   
                    y1-=1;
                    e+=dx;
                }
            }
        }   
    }
}

⌨️ 快捷键说明

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