日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 >

基于NIOS II的液晶显示设计——自定义图形库

發(fā)布時(shí)間:2023/12/1 34 豆豆
生活随笔 收集整理的這篇文章主要介紹了 基于NIOS II的液晶显示设计——自定义图形库 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
基于NIOS II的液晶顯示設(shè)計(jì)——自定義圖形庫(kù)

下面是我寫的簡(jiǎn)單圖形庫(kù)

//

graphics.h

/

#ifndef GRAPHICS_H_
#define GRAPHICS_H_

#include"IO.h"
#include"system.h"
#include"alt_types.h"
//定義SRAM緩存的基地址
??? #define SRAM_BASE?????? LCD_BASE + 320*2
??? #define lcd_frame?????? 320*240
//數(shù)據(jù)類型定義
??? #define WORD??????????? alt_u16
??? #define SHORT?????????? alt_u16
??? #define pi????????????? 3.1415926
//色彩編碼
??? #define BLACK?????????? (WORD) 0x0000
??? #define BRIGHTBLUE????? (WORD) 0x001f
??? #define BRIGHTGREEN???? (WORD) 0x07e0
??? #define BRIGHTCYAN????? (WORD) 0x07ff
??? #define BRIGHTRED?????? (WORD) 0xf800
??? #define BRIGHTMAGENTA?? (WORD) 0xf81f
??? #define BRIGHTYELLOW??? (WORD) 0xffe0
??? #define BLUE??????????? (WORD) 0x0010
??? #define GREEN?????????? (WORD) 0x0400
??? #define CYAN??????????? (WORD) 0x0410
??? #define RED???????????? (WORD) 0x8000
??? #define MAGENTA???????? (WORD) 0x8010
??? #define BROWN?????????? (WORD) 0xfc00
??? #define LIGHTGRAY?????? (WORD) 0x8410
??? #define DARKGRAY??????? (WORD) 0x4208
??? #define LIGHTBLUE?????? (WORD) 0x841f
??? #define LIGHTGREEN????? (WORD) 0x87f0
??? #define LIGHTCYAN?????? (WORD) 0x87ff
??? #define LIGHTRED??????? (WORD) 0xfc10
??? #define LIGHTMAGENTA??? (WORD) 0xfc1f
??? #define YELLOW????????? (WORD) 0xfff0
??? #define WHITE?????????? (WORD) 0xffff

??? #define GRAY0?????????? (WORD) 0xe71c
??? #define GRAY1?????????? (WORD) 0xc618
??? #define GRAY2?????????? (WORD) 0xa514
??? #define GRAY3?????????? (WORD) 0x8410
??? #define GRAY4?????????? (WORD) 0x630c
??? #define GRAY5?????????? (WORD) 0x4208
??? #define GRAY6?????????? (WORD) 0x2104
??
?
?//TFT LCD 初始化
void lcd_init(void);
/
//set TFT LCD display color
void set_color(alt_u16 color);
///
//display a box
void box(alt_u16 x1, alt_u16 y1, alt_u16 x2, alt_u16 y2);
//
//display frame
void frame(alt_u16 x1, alt_u16 y1, alt_u16 x2, alt_u16 y2, alt_u16 width);
///
//move to pixel
void move_to(alt_u16 x, alt_u16 y);

//display one pixel
void pixel(alt_u16 x, alt_u16 y);

//display a line
void line(alt_u16 x1, alt_u16 y1, alt_u16 x2, alt_u16 y2, alt_u16 width);
///
//display a line ,start dot is x_pos,y_pos
void line_to(alt_u16 x, alt_u16 y, alt_u16 width);

//display circle
void circle(alt_u16 x0, alt_u16 y0, alt_u16 radius,alt_u8 width);


#endif /*GRAPHICS_H_*/

/

graphics.c

/

#include"IO.h"
#include"math.h"
#include"graphics.h"

//define TFT LCD color
alt_u16???????? pixel_color;
alt_u16???????? x_pos,y_pos;
alt_u32???????? address;

//TFT LCD 初始化
void lcd_init(void)
{
?? int i;
?? for(i=0;i<lcd_frame/2;i++)? IOWR_32DIRECT(SRAM_BASE,4*i,BLACK);
?? x_pos = 0;
?? y_pos = 0;
}
/
//set TFT LCD display color
void set_color(alt_u16 color)
{
??? pixel_color = color;
}?
///
//display a box
void box(alt_u16 x1, alt_u16 y1, alt_u16 x2, alt_u16 y2)
{
??? int offset, row, col;
??? for (row = y1; row <= y2; row++)
??? {
??????? col = x1;
??????? while (col <= x2)
??????? {
??????????? offset = row*320 + col;
??????????? IOWR_16DIRECT(SRAM_BASE,2*offset,pixel_color);
??????????? ++col;
??????? }
??? }
?? x_pos = x2;
?? y_pos = y2;
}
//
//display frame
void frame(alt_u16 x1, alt_u16 y1, alt_u16 x2, alt_u16 y2, alt_u16 width)
{
?? box(x1,y1,x2,y1+width);
?? box(x1,y2-width,x2,y2);
?? box(x1,y1,x1+width,y2);
?? box(x2-width,y1,x2,y2);
?? x_pos = x2;
?? y_pos = y2;
}
///
//move to pixel
void move_to(alt_u16 x, alt_u16 y)
{
??? x_pos = x;
??? y_pos = y;
??? address = y_pos*320 + x_pos;
}

//display one pixel
void pixel(alt_u16 x, alt_u16 y)
{
?? x_pos = x;
?? y_pos = y;
?? address = y_pos*320 + x_pos;
?? IOWR_16DIRECT(SRAM_BASE,2*address,pixel_color);
}

//display a line
void line(alt_u16 x1, alt_u16 y1, alt_u16 x2, alt_u16 y2, alt_u16 width)
{
??? int i,j,k;
??? float slope;
??? for(i=0;i<width;i++)
??? {
??????? if(x1==x2)
??????? {
??????????? for(k=y1;k<=y2;k++)? pixel(x1+i,k);?
??????? }
??????? else if(y1==y2)
??????? {
??????????? for(j=x1;j<=x2;j++)? pixel(j,y1+i);
??????? }
??????? else
??????? {
??????????? slope =(float)(y1-y2)/(x1-x2);
??????????? for(j=x1;j<=x2;j++)
??????????? {
?????????????? k=floor( slope*(j-x1)+y1 + 0.5);
?????????????? pixel(j+i,k);???????????????
??????????? }
???????????
??????? }
??? }
??? x_pos = x2;
??? y_pos = y2;
}
///
//display a line ,start dot is x_pos,y_pos
void line_to(alt_u16 x, alt_u16 y, alt_u16 width)
{
???? line(x_pos,y_pos,x,y,width);
???? x_pos = x;
???? y_pos = y;
}

//display circle
void circle(alt_u16 x0, alt_u16 y0, alt_u16 radius,alt_u8 width )
{
??? alt_u16 j,k;
??? alt_u32 RR;
??? for(j=x0-radius;j<=x0+radius;j++)
??? {
????? for(k=y0-radius;k<=y0+radius;k++)
????? {
??????? RR = (j-x0)*(j-x0) + (k-y0)*(k-y0);
??????? if( RR>= (radius-width)*(radius-width) && RR <= radius*radius )? pixel(j,k);????????
???? }
?? }
?? x_pos = x0;
?? y_pos = y0;
}

posted on 2011-04-25 11:26?Neddy11 閱讀(...) 評(píng)論(...) 編輯 收藏

轉(zhuǎn)載于:https://www.cnblogs.com/Neddy/archive/2011/04/25/2026884.html

總結(jié)

以上是生活随笔為你收集整理的基于NIOS II的液晶显示设计——自定义图形库的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。