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

📄 lcd_hw.c

📁 飞思卡尔液带晶驱动的MCU例程 飞思卡尔液带晶驱动的MCU例程
💻 C
字号:
#include "lcd.h"
#include "lcd_hw.h"

/* functions to access the features present on the display */

const unsigned int wt_display1[3][16][LCD_BP_CNT]={ 
  { /* digit 1 */
    {0x0003,0x0002,0x0003,0x0002}, /* 0 */
    {0x0000,0x0002,0x0002,0x0000}, /* 1 */
    {0x0003,0x0001,0x0002,0x0002}, /* 2 */
    {0x0002,0x0003,0x0002,0x0002}, /* 3 */
    {0x0000,0x0003,0x0003,0x0000}, /* 4 */
    {0x0002,0x0003,0x0001,0x0002}, /* 5 */
    {0x0003,0x0003,0x0001,0x0002}, /* 6 */
    {0x0000,0x0002,0x0002,0x0002}, /* 7 */
    {0x0003,0x0003,0x0003,0x0002}, /* 8 */
    {0x0002,0x0003,0x0003,0x0002}, /* 9 */
    {0x0001,0x0003,0x0003,0x0002}, /* A */
    {0x0003,0x0003,0x0001,0x0000}, /* B */
    {0x0003,0x0000,0x0001,0x0002}, /* C */
    {0x0003,0x0003,0x0002,0x0000}, /* D */
    {0x0003,0x0001,0x0001,0x0002}, /* E */
    {0x0001,0x0001,0x0001,0x0002}  /* F */
  },
  { /* digit 2 */
    {0x000C,0x0008,0x000C,0x0008}, /* 0 */
    {0x0000,0x0008,0x0008,0x0000}, /* 1 */
    {0x000C,0x0004,0x0008,0x0008}, /* 2 */
    {0x0008,0x000C,0x0008,0x0008}, /* 3 */
    {0x0000,0x000C,0x000C,0x0000}, /* 4 */
    {0x0008,0x000C,0x0004,0x0008}, /* 5 */
    {0x000C,0x000C,0x0004,0x0008}, /* 6 */
    {0x0000,0x0008,0x0008,0x0008}, /* 7 */
    {0x000C,0x000C,0x000C,0x0008}, /* 8 */
    {0x0008,0x000C,0x000C,0x0008}, /* 9 */
    {0x0004,0x000C,0x000C,0x0008}, /* A */
    {0x000C,0x000C,0x0004,0x0000}, /* B */
    {0x000C,0x0000,0x0004,0x0008}, /* C */
    {0x000C,0x000C,0x0008,0x0000}, /* D */
    {0x000C,0x0004,0x0004,0x0008}, /* E */
    {0x0004,0x0004,0x0004,0x0008}  /* F */
  },
  { /* digit 3 */
    {0x0030,0x0020,0x0030,0x0020}, /* 0 */
    {0x0000,0x0020,0x0020,0x0000}, /* 1 */
    {0x0030,0x0010,0x0020,0x0020}, /* 2 */
    {0x0020,0x0030,0x0020,0x0020}, /* 3 */
    {0x0000,0x0030,0x0030,0x0000}, /* 4 */
    {0x0020,0x0030,0x0010,0x0020}, /* 5 */
    {0x0030,0x0030,0x0010,0x0020}, /* 6 */
    {0x0000,0x0020,0x0020,0x0020}, /* 7 */
    {0x0030,0x0030,0x0030,0x0020}, /* 8 */
    {0x0020,0x0030,0x0030,0x0020}, /* 9 */
    {0x0010,0x0030,0x0030,0x0020}, /* A */
    {0x0030,0x0030,0x0010,0x0000}, /* B */
    {0x0030,0x0000,0x0010,0x0020}, /* C */
    {0x0030,0x0030,0x0020,0x0000}, /* D */
    {0x0030,0x0010,0x0010,0x0020}, /* E */
    {0x0010,0x0010,0x0010,0x0020}, /* F */
  }
};

const unsigned int wt_display2[2][16][LCD_BP_CNT]={ 
  { /* digit 1 */
    {0x1800,0x1000,0x1800,0x1000}, /* 0 */
    {0x0000,0x1000,0x1000,0x0000}, /* 1 */
    {0x1800,0x0800,0x1000,0x1000}, /* 2 */
    {0x1000,0x1800,0x1000,0x1000}, /* 3 */
    {0x0000,0x1800,0x1800,0x0000}, /* 4 */
    {0x1000,0x1800,0x0800,0x1000}, /* 5 */
    {0x1800,0x1800,0x0800,0x1000}, /* 6 */
    {0x0000,0x1000,0x1000,0x1000}, /* 7 */
    {0x1800,0x1800,0x1800,0x1000}, /* 8 */
    {0x1000,0x1800,0x1800,0x1000}, /* 9 */
    {0x0800,0x1800,0x1800,0x1000}, /* A */
    {0x1800,0x1800,0x0800,0x0000}, /* B */
    {0x1800,0x0000,0x0800,0x1000}, /* C */
    {0x1800,0x1800,0x1000,0x0000}, /* D */
    {0x1800,0x0800,0x0800,0x1000}, /* E */
    {0x0800,0x0800,0x0800,0x1000}, /* F */
  },
  { /* digit 2 */
    {0x6000,0x4000,0x6000,0x4000}, /* 0 */
    {0x0000,0x4000,0x4000,0x0000}, /* 1 */
    {0x6000,0x2000,0x4000,0x4000}, /* 2 */
    {0x4000,0x6000,0x4000,0x4000}, /* 3 */
    {0x0000,0x6000,0x6000,0x0000}, /* 4 */
    {0x4000,0x6000,0x2000,0x4000}, /* 5 */
    {0x6000,0x6000,0x2000,0x4000}, /* 6 */
    {0x0000,0x4000,0x4000,0x4000}, /* 7 */
    {0x6000,0x6000,0x6000,0x4000}, /* 8 */
    {0x4000,0x6000,0x6000,0x4000}, /* 9 */
    {0x2000,0x6000,0x6000,0x4000}, /* A */
    {0x6000,0x6000,0x2000,0x0000}, /* B */
    {0x6000,0x0000,0x2000,0x4000}, /* C */
    {0x6000,0x6000,0x4000,0x0000}, /* D */
    {0x6000,0x2000,0x2000,0x4000}, /* E */
    {0x2000,0x2000,0x2000,0x4000}, /* F */
  }
};

static const unsigned int wt_bargraph[10][LCD_BP_CNT]={ 
  {0x0000,0x0000,0x0000,0x0000}, /* empty */
  {0x0200,0x0000,0x0000,0x0000}, /* underline */
  {0x0280,0x0000,0x0000,0x0000}, /* 1 bar */
  {0x0280,0x0080,0x0000,0x0000}, /* 2 bars */
  {0x0280,0x0080,0x0080,0x0000}, /* 3 bars */
  {0x0280,0x0080,0x0080,0x0080}, /* 4 bars */
  {0x0280,0x0080,0x0080,0x0180}, /* 5 bars */
  {0x0280,0x0080,0x0180,0x0180}, /* 6 bars */
  {0x0280,0x0180,0x0180,0x0180}, /* 7 bars */
  {0x0380,0x0180,0x0180,0x0180}  /* 8 bars */
};

/* displays a digit on one of the 7-segment digit displays */
void wt_display_digit(const unsigned int data[16][LCD_BP_CNT],unsigned char digit) {
  /* erase the digit */
  LCD_data.data[0][0]&=~data[8][0];  
  LCD_data.data[1][0]&=~data[8][1];  
  LCD_data.data[2][0]&=~data[8][2];  
  LCD_data.data[3][0]&=~data[8][3];  
  /* display new digit */  
  LCD_data.data[0][0]|=data[digit][0];  
  LCD_data.data[1][0]|=data[digit][1];  
  LCD_data.data[2][0]|=data[digit][2];  
  LCD_data.data[3][0]|=data[digit][3];  
}

/* displays a bargraph, 0=hide, 1=underline only, 2=1bar, ... */
void wt_display_bargraph(unsigned char no_of_bars) {
  /* erase the bargraph */
  LCD_data.data[0][0]&=~wt_bargraph[9][0];  
  LCD_data.data[1][0]&=~wt_bargraph[9][1];  
  LCD_data.data[2][0]&=~wt_bargraph[9][2];  
  LCD_data.data[3][0]&=~wt_bargraph[9][3];  
  /* display new bargraph */  
  LCD_data.data[0][0]|=wt_bargraph[no_of_bars][0];  
  LCD_data.data[1][0]|=wt_bargraph[no_of_bars][1];  
  LCD_data.data[2][0]|=wt_bargraph[no_of_bars][2];  
  LCD_data.data[3][0]|=wt_bargraph[no_of_bars][3];  
}

/* displays a number on display 1 */
/* format: 0=3 digits, no decimal place, 1=3 digits, 1 decimal place, 2=2 digits + degF sign */
void wt_diplay1_set(unsigned int value, unsigned char format) {
  switch (format) {
    case 0:
      /* 3 digits & no decimal place */
      wt_display_digit(wt_display1[0],value/100);
      value-=(value/100)*100;
      wt_display_digit(wt_display1[1],value/10);
      value-=(value/10)*10;
      wt_display_digit(wt_display1[2],value);
      WT_ERASE(WT_DISP1_DOT);
      WT_ERASE(WT_DISP1_DEGREE);
      break;
    case 1:
      /* 3 digits & 1 decimal place */
      wt_display_digit(wt_display1[0],value/100);
      value-=(value/100)*100;
      wt_display_digit(wt_display1[1],value/10);
      value-=(value/10)*10;
      wt_display_digit(wt_display1[2],value);
      WT_DISPLAY(WT_DISP1_DOT);
      WT_ERASE(WT_DISP1_DEGREE);
      break;
    case 2:
      /* 2 digits & degF */
      wt_display_digit(wt_display1[0],value/10);
      value-=(value/10)*10;
      wt_display_digit(wt_display1[1],value);
      WT_ERASE(WT_DISP1_DOT);
      WT_DISPLAY(WT_DISP1_DEGREE);
      wt_display_digit(wt_display1[2],0xf);
      break;
  }
}

/* displays a number on display 2 */
void wt_diplay2_set(int value) {
  if (value<0) {
    /* negative value */
    value=-value;
    WT_DISPLAY(WT_DISP2_MINUS);    
  } else {
    /* positive value */
    WT_ERASE(WT_DISP2_MINUS);    
  }
  if (value>=100) {
    /* leading 1 */  
    WT_DISPLAY(WT_DISP2_100);    
    value-=100;
  } else {
    /* no leading 1 */
    WT_ERASE(WT_DISP2_100);    
  }
  wt_display_digit(wt_display2[0],value/10);
  value-=(value/10)*10;
  wt_display_digit(wt_display2[1],value);
}

⌨️ 快捷键说明

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