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

📄 ks0108.c

📁 Atmega64单片机程序(完整工程)
💻 C
📖 第 1 页 / 共 3 页
字号:

    if(Y>(128-8)){//换行
        X += 2;
        Y  = 0;
    }
    if(!Nor){
        for(i=0;i<8;i++){
            if(EnFont == 0){
                WriteByte(X,(Y+i),chardot[i+(Char-0x20)*16]);
            }else{
                dot = chardot[i+(Char-0x20)*16];
                temp = Changedot[dot];
//这段代码把字体纵向放大2倍,外部调用时换行需要加倍
                WriteByte(X,(Y+i),(U8)(temp&0x00FF));
                WriteByte(X+1,(Y+i),(U8)((temp&0xFF00)>>8));

/*
//这段代码把字体放大4倍,但由于横向轴被放大,因此外部调用函数时也需要加倍
                WriteByte(X,(Y+i*2),(U8)(temp&0x00FF));
                WriteByte(X,(Y+i*2+1),(U8)(temp&0x00FF));
                WriteByte(X+1,(Y+i*2),(U8)((temp&0xFF00)>>8));
                WriteByte(X+1,(Y+i*2+1),(U8)((temp&0xFF00)>>8));
*/
            }

        }
        for(i=8;i<16;i++){
            if(EnFont == 0){
                WriteByte(X+1,(Y+i-8),chardot[i+(Char-0x20)*16]);
            }else{
                dot = chardot[i+(Char-0x20)*16];
                temp = Changedot[dot];

                WriteByte(X+2,(Y+i-8),(U8)(temp&0x00FF));
                WriteByte(X+3,(Y+i-8),(U8)((temp&0xFF00)>>8));

/*
                WriteByte(X+2,(Y+(i-8)*2),(U8)(temp&0x00FF));
                WriteByte(X+2,(Y+(i-8)*2+1),(U8)(temp&0x00FF));
                WriteByte(X+3,(Y+(i-8)*2),(U8)((temp&0xFF00)>>8));
                WriteByte(X+3,(Y+(i-8)*2+1),(U8)((temp&0xFF00)>>8));
*/
            }
        }
    }else{
        for(i=0;i<8;i++){
            if(EnFont == 0){
                WriteByte(X,(Y+i),0xFF-chardot[i+(Char-0x20)*16]);
            }else{
                dot = 0xFF-chardot[i+(Char-0x20)*16];
                temp = Changedot[dot];
                WriteByte(X*2,(Y+i),(U8)(temp&0x00FF));
                WriteByte(X*2,(Y+i+1),(U8)(temp&0x00FF));
                WriteByte(X*2+1,(Y+i),(U8)((temp&0xFF00)>>8));
                WriteByte(X*2+1,(Y+i+1),(U8)((temp&0xFF00)>>8));

            }
        }
        for(i=8;i<16;i++){
            if(EnFont == 0){
                WriteByte(X+1,(Y+i-8),0xFF-chardot[i+(Char-0x20)*16]);
            }else{
                dot = 0xFF-chardot[i+(Char-0x20)*16];
                temp = Changedot[dot];
                WriteByte((X+1)*2,(Y+i-8+1),(U8)(temp&0x00FF));
                WriteByte((X+1)*2,(Y+i-8),(U8)(temp&0x00FF));
                WriteByte((X+1)*2+1,(Y+i-8+1),(U8)((temp&0xFF00)>>8));
                WriteByte((X+1)*2+1,(Y+i-8),(U8)((temp&0xFF00)>>8));
            }
        }
    }
}
#endif
//--------------------------

#if 0
//-------------显示普通图片
//------(图像 长度 起始位置)
void Display_Image(U8 _CONST_ *IMG)
{
    U8 XAddr;
    U8 YAddr;
    U16 Count;
    Count = 0;
    for(XAddr=0;XAddr<8;XAddr++){//0--7
        for(YAddr=0;YAddr<128;YAddr++){//0--127
            WriteByte(XAddr,YAddr,IMG[Count++]);
        }
    }
}
#endif

/*
*****************************************************************************
* GUI_DrawIcon - 制定位置显示一个32x32的图标
* DESCRIPTION: -
*
* @Param x0:X轴坐标
* @Param y0:Y轴坐标 注意边界!
* @Param Ico:图标数据
* @Return :
* ----
*****************************************************************************
*/
void GUI_DrawIcon(U8 _CONST_ *Ico,U8 x0,U8 y0)
{
    U8 i;
    U16 Count;
    Count = 0;
    if( y0 > 4){//边界保护
        y0 = 4;
    }
    if(x0 >(LCD_XSIZE-32)){
        x0 = LCD_XSIZE-32;
    }
    for(i=0;i<32;i++){//第一行
        Display_Locate(Ico[Count++],x0+i,y0);
    }
    for(i=0;i<32;i++){//第二行
        Display_Locate(Ico[Count++],x0+i,y0+1);
    }
    for(i=0;i<32;i++){//第三行
        Display_Locate(Ico[Count++],x0+i,y0+2);
    }
    for(i=0;i<32;i++){//第四行
        Display_Locate(Ico[Count++],x0+i,y0+3);
    }
}
#if 0

/*
*****************************************************************************
* GUI_DispDecAt - 显示十进制数值
* DESCRIPTION: -
* 处理长度最多5个数字(因为U16--->65536)
* @Param v:显示的数据
* @Param x:X轴坐标
* @Param y:Y轴坐标  XY 均是起点位置坐标 也就是数值最高位的坐标
* @Param Len:指定的显示长度1--5内
* @Return :
*
*****************************************************************************
*/
void GUI_DispDecAt(U16 v, U16 x, U16 y, U8 Len)
{
    U8 i;
    U8 CharBuf[5];
    U8 HighByte;

    HighByte = 0;
    for(i = 0; i < 5; i++){
        CharBuf[i] = (U8)(v%10);
        v = v/10;
        if(CharBuf[i]){
            HighByte = i;
        }
    }
    //第0位无论如何也显示
    i = 0;
    GUI_DispCharAt(CharBuf[i]+'0',x+((Len-1)-i)*Char_XSIZE,y);
    for(i = 1; i < Len; i++){
        if(CharBuf[i]){
            GUI_DispCharAt(CharBuf[i]+'0',x+((Len-1)-i)*Char_XSIZE,y);
        }else if(i > HighByte){
            GUI_DispCharAt(' ',x+((Len-1)-i)*Char_XSIZE,y);
        }
    }

}

/*
*****************************************************************************
* GUI_DispHexAt - 显示一个数据的十六进制值
* DESCRIPTION: -
* 最大长度4个
* @Param v:数据
* @Param x:X轴坐标
* @Param y:Y轴坐标  XY均是起点坐标 也就是数据最高字节坐标
* @Param Len:长度1--4
* @Return :
*
*****************************************************************************
*/
void GUI_DispHexAt(U32 v, U8 x, U8 y, U8 Len)
{
    U8 i;
    U8 HexData;
    if(Len > 8){//限制范围
        Len = 8;
    }
    for(i = 0; i < Len; i++){
        HexData = v&0x0F;
        v = v >>4;
        if(HexData < 0x0A){
            GUI_DispCharAt(HexData+'0',x+Char_XSIZE*(Len-1-i),y);
        }else{
            GUI_DispCharAt(HexData-0x0A+'A',x+Char_XSIZE*(Len-1-i),y);
        }
    }
}
/*
*****************************************************************************
* HBar - 显示一个水平的进度条
* DESCRIPTION: -
* 附加有百分比显示
* @Param x0:进度条起点X轴坐标   0-->127
* @Param x1:进度条结束点X坐标   0-->127  必须大于x0  百分比显示于该坐标之后
* @Param y:进度条Y轴坐标        0--7
* @Param percent:当前百分值     0-->100
* @Return :
*
*****************************************************************************
*/
void HBar(U8 y, U8 x0, U8 x1,U8 percent)
{
    U8 U8Temp;
    U8 i;
    float Center;
    Center = (x1-x0);
    Center *= percent;
    Center /= 100;
//    U8Temp = (x1-x0)*percent/100;//这个计算做法在430上能用,但C51下似乎必须用浮点算
    U8Temp = (U8)Center;
    Display_Locate(0xFF, x0, y);
    Display_Locate(0xFF, x1, y);
    for(i = 1; i < U8Temp; i++){
        Display_Locate(0xBD, x0+i, y);
    }
    for(i = x0+U8Temp+1; i < x1; i++){
        Display_Locate(0x81, i, y);
    }
}
/*                  x1 +3
|-------------------|
|                   ||
|                   |||
|                   ||||
|                   ||||
--------------------
 -------------------
  ------------------
x0--->x1+3
y0--->y1


*/

void TipDisp( U8 x0, U8 y0, U8 x1, U8 y1)
{
    U8 i;
    for(i = 0; i < x1-x0+4; i++){
        Display_Locate(0x01, x0+i, y0);
        Display_Locate(0x0F, x0+i, y1);
    }
    Display_Locate(0x01, x0+0, y1);
    Display_Locate(0x01, x0+1, y1);
    Display_Locate(0x03, x0+2, y1);
    Display_Locate(0x03, x0+3, y1);
    Display_Locate(0x07, x0+4, y1);
    Display_Locate(0x07, x0+5, y1);

    for(i = 0; i < y1-y0; i++){
        Display_Locate(0xFF, x0, y0+i);
        Display_Locate(0xFF, x1, y0+i);
        Display_Locate(0xFF, x1+1, y0+i);
        Display_Locate(0xFF, x1+2, y0+i);
        Display_Locate(0xFF, x1+3, y0+i);
    }
    Display_Locate(0xFC, x1+1, y0);
    Display_Locate(0xF0, x1+2, y0);
    Display_Locate(0xC0, x1+3, y0);
}

/*
清空Tip
坐标应该跟TipDisp一样
*/
void TipClr( U8 x0, U8 y0, U8 x1, U8 y1)
{
    U8 i;
    U8 j;
    for(i = 0; i <= x1+3-x0; i++){
        for(j = 0; j <= y1-y0; j++){
            Display_Locate(0x00, x0+i, y0+j);
        }
    }

}
#endif
/*
// ---- 显示不带符号的整数  (数字 起始位置XY,显示长度) -----------------------------
void Display_Number(U16 Number, U8 X, U8 Y, U8 Lenth)
{
  U8 DispNum;

  X = ( X + Lenth * 8 - 8 );
  for(; Lenth>0; Lenth--)
  {
    DispNum = Number%10 + 0x30;
    Display_ASCII(DispNum, X, Y);
    X -= 8;
    Number = Number / 10;
  }
}

// ---- 显示带符号的整数  (数字 起始位置XY,显示长度) ---------------------------------
void Display_SignedNumber(int Number,U8 X,U16 Y,U8 Lenth)
{
  if(Number < 0)
  {
    Display_ASCII('-', X, Y);
    Display_Number(-Number, X+8, Y, Lenth);
  }
  else
  {
    Display_ASCII(' ', X, Y);
    Display_Number(Number, X+8, Y, Lenth);
  }
}

// ---- 显示不带符号的小数 (数字 起始位置XY,整数位数,小数位数) ------------------------------
void Display_Decimal(unsigned long int Number, char X, U16 Y, U8 INT, U8 DEC)
{
  U8 DispNum, Lenth;
  //Y = Y +(( X + INT * 8 + DEC * 8 ) / 84) * 2;
  X = ( X + ( INT + DEC ) *8);
  // 显示小数部分
  for(Lenth=DEC; Lenth>0; Lenth--)
  {
    DispNum = Number%10 + 0x30;
    Display_ASCII(DispNum, X, Y);
    //if (X < 8) {Y -= 2; X += 84;}
    X -= 8;
    Number = Number / 10;
  }
  // 显示小数点
  Display_ASCII('.', X, Y);
  //if (X < 8) {Y -= 2; X += 84;}
    X -= 8;
  // 显示整数部分
  for(Lenth=INT; Lenth>0; Lenth--)
  {
    DispNum = Number%10 + 0x30;
    Display_ASCII(DispNum, X, Y);
    //if (X < 8) {Y -= 2; X += 84;}
    X -= 8;
    Number = Number / 10;
  }
}

// ---- 显示带符号的小数 (数字 起始位置XY,整数位数,小数位数) ------------------------------
void Display_SignedDecimal(long int Number, char X, U16 Y, U8 INT, U8 DEC)
{
  if(Number < 0)
  {
    Display_ASCII('-', X, Y);
    Display_Decimal(-Number, X+8, Y, INT, DEC);
  }
  else
  {
  Display_ASCII(' ',X,Y);
  Display_Decimal(Number, X+8, Y, INT, DEC);
  }
}
*/


//--------------
/*
Bar的算法
    ___
 |   |
 |   |
| |<-|-----BarLen
 |   L
 |   |
 |   |
 |  _|_
Bar的滑动距离是L-BarLen
为了美观,可以在开始和结尾部分多流出来一些点,那么滑动距离要扣除这些点的长度,并在计算结果
得到0的时候,添加上上端要留出来的点BarRemainDot
2种显示方式:
一种是BarLen是定长的,
一种BarLen是根据显示总共的项数定下来的
*/


//--------------
//Bar的长度
//预留出来的点
#define BarRemainDot  3
//数字显示位置
//#define BarNumPosX (128-8+2)
#define BarNumPosY (7)
//Bar的显示开始/结束位置
//#define BarBeginPosX (126)
#define BarBeginPosY (0*8)
#define BarEndPosX (126)
#define BarEndPosY (6*8)

U8 _CONST_ BarCode0[]={0xFF,0xFE,0xFC,0xF8,0xF0,0xE0,0xC0,0x80,0x00};
U8 _CONST_ BarCode1[]={0x00,0x01,0x03,0x07,0x0F,0x1F,0x3F,0x7F,0xFF};
extern U8 ItemBackup_i;
extern U8 ItemBackup[];

void Bar(U8 Item_,U8 ItemNum_,U8 BarPosX,U8 BarNumPosX)
{
    U8 U8_temp;
    U8 DispFlag;
    U8 YOffset;
    U16 Temp;
    U8 BarLen;
    U8 Y;
    U8 i;
//    U8 CharBuf[5];
//    Bool HighBit;

    BarLen = (BarEndPosY-BarBeginPosY-BarRemainDot)/(ItemNum_);//BarLen根据ItemNum_得到
    if (BarLen == 0) {
        BarLen = 5;
    }
    BarLen = 8;
    Temp = Item_*(BarEndPosY-BarBeginPosY-BarLen-BarRemainDot);//BarRemainDot是被扣除的部分
    Temp = Temp/(ItemNum_-1);
    YOffset = (U8)Temp;
    if(!Temp){//顶端,把预留的加上
        YOffset = BarRemainDot;
    }

    for(Y = 0;Y < BarEndPosY/8;Y++){
        if((Y != (YOffset/8))&&(Y != (YOffset/8+1))){
            Display_Locate(0x00,BarPosX,Y);//清除 X=125 列
            Display_Locate(0xFF,BarPosX+1,Y);//X=126列画线
            Display_Locate(0x00,BarPosX+2,Y);//清除 X=127 列
        }else{//Y = YOffset/8 Y = YOffset/8+1
            Display_Locate(BarCode0[YOffset%8],BarPosX,(YOffset/8));
            Display_Locate(0xFF-BarCode0[YOffset%8],BarPosX+1,(YOffset/8));
            Display_Locate(BarCode0[YOffset%8],BarPosX+2,(YOffset/8));
            if((YOffset/8)+1 < (BarEndPosY/8)){//防止下越界
                Display_Locate(BarCode1[YOffset%8],BarPosX,(YOffset/8+1));
                Display_Locate(0xFF-BarCode1[YOffset%8],BarPosX+1,(YOffset/8+1));
                Display_Locate(BarCode1[YOffset%8],BarPosX+2,(YOffset/8+1));
            }
        }
    }

    GUI_SetEnFont(En_5x8);
    Item_ += 1;
    //显示Bar数字
/*
    for(i = 0; i < 5; i++){
        CharBuf[i] = (U8)(Item%10);
        Item = Item/10;
    }
    HighBit = false;
    for(i = 0; i < 5; i++){
        if(CharBuf[4-i]){//从最高位开始显示
            GUI_DispCharAt(CharBuf[4-i]+'0',x+8*i,y);
            HighBit = true;
        }else{
            if(HighBit == true){
                GUI_DispCharAt('0',x+Char_XSIZE*i,y);//如果高位不为0,当前值为0 ,显示0
            }
        }
    }
*/
    DispFlag = false;
    U8_temp = (U8)(Item_/100);//  百位
    if(U8_temp){
        GUI_DispCharAt(U8_temp+'0',BarNumPosX-12,BarNumPosY);
        DispFlag = true;//通知低位显示
    }else{
        GUI_DispCharAt(' ',BarNumPosX-12,BarNumPosY);
    }

    Item_ = (Item_-U8_temp*100);//剔除百位
    U8_temp = (U8)(Item_/10);//  十位
    if(U8_temp||(DispFlag == true)){//本位不为0,或者高位已经显示,那么必须显示
        GUI_DispCharAt(U8_temp+'0',BarNumPosX-6,BarNumPosY);
        DispFlag = 1;
    }else{
        GUI_DispCharAt(' ',BarNumPosX-6,BarNumPosY);
    }

    U8_temp = (U8)(Item_%10);//  个位
    GUI_DispCharAt(U8_temp+'0',BarNumPosX,BarNumPosY);

//----------------------------------
//显示历史索引号
    if(ItemBackup_i > 1){//大于1才是
        for(i = 0; i <ItemBackup_i-1;i++){//最后一个位于1的位置
            Item_ = ItemBackup[ItemBackup_i-1-i]+1;  //从备份数据中得到标号,然后加1显示
            U8_temp = (U8)(Item_%10);//
            GUI_DispCharAt(U8_temp+'0',BarNumPosX-8*(i+1),BarNumPosY);
            Display_Locate(0x10, BarNumPosX-8*(i+1)+8-1, BarNumPosY); //描分隔符
            Display_Locate(0x10, BarNumPosX-8*(i+1)+8-0, BarNumPosY);
        }
    }
//----------------------------------
    GUI_SetEnFont(En_8x16);

   return;

}


⌨️ 快捷键说明

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