?? graphics.c
字號:
/*-------------------------------------------------------------------*/
/* GRAPHICS.C */
/*-------------------------------------------------------------------*/
/* Copyright (C) 2006, By ZhaiGang */
/* */
/* Function: LCD Graphics Functions */
/*-------------------------------------------------------------------*/
/**************************************************/
/*包含的頭文件。 */
/**************************************************/
#include <stdlib.h>
#include "Graphics.h"
#include "Hzk16.h"
#include "Picture.h"
/**************************************************/
/*位。定義一個字節(jié),用于位操作。 */
/**************************************************/
const unsigned char vLcdBit[8]=
{0x80,0x40,0x20,0x10,0x08,0x04,0x02,0x01};
unsigned int vLcdRow,vLcdCol,HzNumber;
unsigned int OldSpeedValue=0; //車速
unsigned int OldWaterTValue=0; //水溫
unsigned int OldOilValue=0; //燃油
/**************************************************/
/*初始化端口。 */
/**************************************************/
void vLcd_DeviceInit(void) {
DDRA=0xFF;
DDRB=0xFF;
PORTA=0xFF;
PORTB=0xFF;
}
/**************************************************/
/*設(shè)置光標。先選擇行,再選擇列。圖形方式。 */
/**************************************************/
void vLcd_SetCursor(unsigned int col,unsigned int row){
vLcd_WRCommand(Lcd_YAxisR,row);
vLcd_WRCommand(Lcd_XAxisR,col);
vLcd_WRCommand(Lcd_CntrlR,((col/256)<<2)|(row/256));
}
/**************************************************/
/*寫指令、數(shù)據(jù)子程序。 */
/**************************************************/
void vLcd_WRCommand(byte bIndex,unsigned int bValue){
DDRB= 0xff;
switch (bIndex) {
case Lcd_XAxisR: /* Select X-Axis R */
A1=0; A0=0;
break;
case Lcd_YAxisR: /* Select Y-Axis R */
A1=0; A0=1;
break;
case Lcd_CntrlR: /* Select Cntrl R */
A1=1; A0=0;
break;
case Lcd_DataR: /* Select Data R */
A1=1; A0=1;
break;
}/* switch */
PORTB=bValue; /* Write Value to PortB */
CS=0; WR=0;
WR=1; CS=1;
}
/**************************************************/
/*清屏。全屏清零,可設(shè)置背景色。 */
/**************************************************/
void vLcd_ClearViewport(unsigned char BColor){
unsigned int x,y;
vLcd_DeviceInit();
for(y=0;y<480;y++){
x=0;
vLcd_SetCursor(x,y);
for(;x<640;x++)
vLcd_WRCommand(Lcd_DataR,BColor);
}
}
/**************************************************/
/*清屏。局部清零,可設(shè)置背景色。 */
/**************************************************/
void vLcd_ClearRect(unsigned int x1,unsigned int y1,
unsigned int x2,unsigned int y2,unsigned char BColor){
unsigned int i,j;
for(j=y1;j<y2;j++){
i=x1;
vLcd_SetCursor(i,j);
for(;i<x2;i++)
vLcd_WRCommand(Lcd_DataR,BColor);
}
}
/**************************************************/
/*延時。 */
/**************************************************/
static void vLcd_Delay1ms(void){
unsigned int cnt=0;
while(cnt<Delay) cnt++;
}
void vLcd_DelayNms(int Nms){
unsigned int i;
for(i=1;i<Nms;i++)
vLcd_Delay1ms();
}
/**************************************************/
/*畫點。可設(shè)置前景色。 */
/**************************************************/
void vLcd_DrawPoint(int x0,int y0,unsigned char FColor){
vLcd_SetCursor(x0,y0);
vLcd_WRCommand(Lcd_DataR,FColor);
}
/**************************************************/
/*畫線。可設(shè)置前景色。 */
/**************************************************/
void vLcd_DrawLine(int x0,int y0,int x1,int y1, unsigned int color){
int i,DeltaX,DeltaY,DeltaX2,DeltaY2,x_inc,y_inc,Err;
DeltaX= x1-x0;
DeltaY= y1-y0;
if(DeltaX>=0){
x_inc= 1;
}
else{
x_inc= -1;
DeltaX= -DeltaX;
}
if(DeltaY>=0){
y_inc= 1;
}
else{
y_inc= -1;
DeltaY= -DeltaY;
}
DeltaX2= DeltaX<<2;
DeltaY2= DeltaY<<2;
if(DeltaX>DeltaY){
Err= DeltaY2- DeltaX;
for(i=0;i<=DeltaX;i++){
vLcd_DrawPoint(x0,y0,color);
if(Err>=0){
Err-= DeltaX2;
y0+= y_inc;
}
Err+= DeltaY2;
x0+= x_inc;
}
}
else{
Err= DeltaY2- DeltaX;
for(i=0;i<=DeltaY;i++){
vLcd_DrawPoint(x0,y0,color);
if(Err>=0){
Err-= DeltaY2;
x0+= x_inc;
}
Err+= DeltaX2;
y0+= y_inc;
}
}
}
void vLcd_DrawLine2(int x0,int y0,int x1, int y1,int FColor){
int x,y,dx,dy,e;
unsigned int i;
dx=x1-x0;
dy=y1-y0;
e=-dx;
x=x0;
y=y0;
for(i=0;i<dx;i++){
vLcd_DrawPoint(x,y,FColor);
x++;
e=e+2*dy;
if(e>=0){
y++;
e=e-2*dx;
}
}
}
/**************************************************/
/*畫圓弧。可設(shè)置前景色。 1/8象限圓弧 */
/**************************************************/
void vLcd_DrawPartArc(unsigned int ox,unsigned int oy,unsigned int Rx,
unsigned char FColor,unsigned char quad){
unsigned int xx,rr,xt,yt,rs;
unsigned int col,row;
yt=Rx;
rr=Rx*Rx+1;
rs=(yt+(yt>>1))>>1;
for(xt=0;xt<=rs;xt++){
xx=xt*xt;
while((yt*yt)>(rr-xx)) yt--;
switch(quad){
case 0:
col=ox+xt; row=oy-yt; break;
case 1:
col=ox-xt; row=oy-yt; break;
case 2:
col=ox-xt; row=oy+yt; break;
case 3:
col=ox+xt; row=oy+yt; break;
case 4:
col=ox+yt; row=oy-xt; break;
case 5:
col=ox-yt; row=oy-xt; break;
case 6:
col=ox-yt; row=oy+xt; break;
case 7:
col=ox+yt; row=oy+xt; break;
}
vLcd_DrawPoint(col,row,FColor);
}
}
/**************************************************/
/*畫圓。可設(shè)置前景色、方式(0:不填充;1:填充)。 */
/**************************************************/
void vLcd_DrawCircle(int centerx, int centery, int radius, unsigned char FColor, int type){
int x = 0;
int y = radius;
int delta = 2*(1-radius);
int direction;
while (y >= 0) {
if(!type) {
vLcd_DrawPoint(centerx+x, centery+y, FColor);
vLcd_DrawPoint(centerx-x, centery+y, FColor);
vLcd_DrawPoint(centerx-x, centery-y, FColor);
vLcd_DrawPoint(centerx+x, centery-y, FColor);
}
else{
vLcd_DrawLine(centerx+x, centery+y, centerx+x, centery-y, FColor);
vLcd_DrawLine(centerx-x, centery+y, centerx-x, centery-y, FColor);
}
if(delta < 0){
if((2*(delta+y)-1) < 0) {
direction = 1;
}
else {
direction = 2;
}
}
else if(delta > 0){
if((2*(delta-x)-1) <= 0) {
direction = 2;
}
else{
direction = 3;
}
}
else {
direction=2;
}
switch(direction) {
case 1:
x++;
delta += (2*x+1);
break;
case 2:
x++;
y--;
delta += 2*(x-y+1);
break;
case 3:
y--;
delta += (-2*y+1);
break;
}
}
}
/**************************************************/
/*單個漢字顯示(16×16)。 */
/* FColor:字體顏色。 */
/* HzSituation:待顯漢字在字庫(HZK16)中的位置。 */
/**************************************************/
void vLcd_Show16DotWord(unsigned char HzSituation,unsigned char FColor){
unsigned char i,j,k;
unsigned int delta,HzS;
delta=vLcdCol+HzNumber*8;
if(delta>624){
vLcdCol=0; vLcdRow+=24;
HzNumber=0;
delta=vLcdCol+HzNumber*8;
}
HzS=HzSituation*32;
for(i=0;i<2;i++){
for(j=0;j<16;j++){
for(k=0;k<8;k++)
if(HZK16[HzS+j*2+i]&vLcdBit[k])
vLcd_DrawPoint(delta+i*8+k,vLcdRow+j,FColor);
}
HzNumber++;
}
}
/**************************************************/
/*多個漢字顯示(16×16)。 */
/* FColor:字體顏色。 HzNum:待顯漢字的總數(shù)。 */
/* Hz:多個待顯漢字的位置順序。 */
/* 可自動換行,超出屏幕下沿時,余字將不再顯示。*/
/**************************************************/
void vLcd_Disply16DotHz(unsigned int row,unsigned int col,unsigned char *Hz,
unsigned char HzNum,unsigned char FColor){
unsigned char i;
HzNumber=0;
vLcdCol=col; vLcdRow=row;
vLcd_SetCursor(vLcdCol,vLcdRow);
for(i=0;i<HzNum;i++){
vLcd_Show16DotWord(Hz[i],FColor);
if(vLcdRow>464) break;
}
}
void vLcd_LeftScroll1(void){
unsigned int y,n;
for(y=0;y<75;y++){
//vLcd_WRCommand(Lcd_YAxisR,300+y);
//vLcd_WRCommand(Lcd_CntrlR,(y+100)/256);
//vLcd_WRCommand(Lcd_XAxisR,100);
//vLcd_SetCursor(100,100+y);
for(n=0;n<101;n++) {
vLcd_SetCursor(270+n,340+y);
//vLcd_WRCommand(Lcd_XAxisR,400+n);
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
減小字號
Ctrl + -