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

📄 grafik.c

📁 Project with S1D13506 and AVR M8515
💻 C
字号:
#include <avr/io.h>
#include <avr/interrupt.h>
#include <avr/pgmspace.h>
#include "global.h"
#include "s1d13506.h"
#include "grafik.h"
#include "8x8_horizontal_MSB_1.h"

unsigned short x_size,y_size;

void lcd_writechar (unsigned short x, unsigned short y, unsigned char textfarbe, unsigned short hintergrundfarbe, unsigned char zeichen)
{	unsigned char wert,i,j;

	if (y>252)
		return;

	for(i=0; i<8; i++)
	{	wert=pgm_read_byte(&font[zeichen][i]);
		for(j=0; j<8; j++)
		{	if (wert&128)
				lcd_pixel(x+j,y+i,textfarbe);
			else if (hintergrundfarbe<256)
				lcd_pixel(x+j,y+i,hintergrundfarbe);
			wert<<=1;
		 }
	}
}

void lcd_pixel (unsigned short x, unsigned short y, unsigned char farbe)
{
	s1d13506_writemem((unsigned long)y*x_size+x, farbe);
}

void lcd_clear(void)
{	unsigned short x=0,y=0;
	for (y=0;y<y_size;y++)
		for (x=0;x<x_size;x++)
			lcd_pixel(x,y,0);
}

void bresenham_line (unsigned short x1, unsigned short y1, unsigned short x2, unsigned short y2, unsigned char farbe)
{	signed short dx,dy,x,y;
	signed char sdx,sdy;
	unsigned short i,px,py;

	dx=(signed int)x2-x1;      /* the horizontal distance of the line */
	dy=(signed int)y2-y1;      /* the vertical distance of the line */
	if (dx==0)
		sdx=0;
	if (dx>0)
		sdx=1;
	else
	{  	sdx=-1;
		dx=-dx;
	}
	if (dy==0)
		sdy=0;
	if (dy>0)
		sdy=1;
	else
	{	sdy=-1;
		dy=-dy;
	}
	x=dx*2;
	y=dy*2;
	px=x1;
	py=y1;
	lcd_pixel (px,py,farbe);

	if (dx>=dy) /* the line is more horizontal than vertical */
	{	for(i=0;i<dx;i++)
		{	y+=dy;
			if (y>=dx)
			{	y-=dx;
				py+=sdy;
			}
			px+=sdx;
			lcd_pixel (px,py,farbe);
		}
	}
	else /* the line is more vertical than horizontal */
	{	for(i=0;i<dy;i++)
		{	x+=dx;
			if (x>=dy)
			{	x-=dy;
				px+=sdx;
			}
			py+=sdy;
			lcd_pixel (px,py,farbe);
		}
	}
}

void lcd_line (unsigned short x1, unsigned short y1, unsigned short x2, unsigned short y2, unsigned char farbe)
{	unsigned short temp;
	if (y1==y2)
	{	if (x1>x2)
		{	temp=x1;
			x1=x2;
			x2=temp;
		}
		unsigned short x;
		for (x=x1; x<=x2; x++)
			lcd_pixel (x,y1,farbe);
	}
	else if (x1==x2)
	{	if (y1>y2)
		{	temp=y1;
			y1=y2;
			y2=temp;
		}
		unsigned short y;
		for (y=y1; y<=y2; y++)
			lcd_pixel (x1,y,farbe);
	}
	else
		bresenham_line (x1, y1, x2, y2, farbe);
}

⌨️ 快捷键说明

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