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

📄 lcd_4bit.lst

📁 完成数据的采集
💻 LST
📖 第 1 页 / 共 2 页
字号:
    174          *   Parameter:    c:      command to be written                                *
    175          *   Return:                                                                    *
    176          *******************************************************************************/
    177          
    178          void lcd_write_cmd (unsigned char c)
    179          {
    180            wait_while_busy();
    181          
    182            LCD_RS(0)
    183            lcd_write_4bit (c>>4);
    184            lcd_write_4bit (c);
    185          }
    186          
    187          
    188          /*******************************************************************************
    189          * Write data to LCD controller                                                 *
    190          *   Parameter:    c:      data to be written                                   *
    191          *   Return:                                                                    *
    192          *******************************************************************************/
    193          
    194          static void lcd_write_data (unsigned char c)
    195          {
    196            wait_while_busy();
    197          
    198            LCD_RS(1)
    199            lcd_write_4bit (c>>4);
    200            lcd_write_4bit (c);
    201          }
    202          
    203          
    204          /*******************************************************************************
    205          * Print Character to current cursor position                                   *
    206          *   Parameter:    c:      character to be printed                              *
    207          *   Return:                                                                    *
    208          *******************************************************************************/
    209          
    210          void lcd_putchar (char c)
    211          { 
    212            lcd_write_data (c);
    213          }
    214          
    215          
    216          /*******************************************************************************
    217          * Initialize the LCD controller                                                *
    218          *   Parameter:                                                                 *
    219          *   Return:                                                                    *
    220          *******************************************************************************/
    221          
    222          void lcd_init (void)
    223          { 
    224            int i;
    225            char const *p;
    226          
    227            LCD_CLOCK_EN                          /* Enable clock for peripheral        */
    228          
    229            /* Set all pins for LCD as outputs                                          */
    230            LCD_ALL_DIR_OUT
    231          
    232            delay (15000);
    233            LCD_RS(0)
    234            lcd_write_4bit (0x3);                 /* Select 4-bit interface             */
    235            delay (4100);
    236            lcd_write_4bit (0x3);
    237            delay (100);
    238            lcd_write_4bit (0x3);
    239            lcd_write_4bit (0x2);
    240          
    241            lcd_write_cmd (0x28);                 /* 2 lines, 5x8 character matrix      */
    242            lcd_write_cmd (0x0C);                 /* Display ctrl:Disp=ON,Curs/Blnk=OFF */
    243            lcd_write_cmd (0x06);                 /* Entry mode: Move right, no shift   */
    244          
    245            /* Load user-specific characters into CGRAM                                 */
    246            lcd_write_cmd(0x40);                  /* Set CGRAM address counter to 0     */
    247            p = &UserFont[0][0];
    248            for (i = 0; i < sizeof(UserFont); i++, p++)
    249              lcd_putchar (*p);
    250          
    251            lcd_write_cmd(0x80);                  /* Set DDRAM address counter to 0     */
    252          }
    253          
    254          
    255          
    256          /*******************************************************************************
    257          * Set cursor position on LCD display                                           *
    258          *   Parameter:    column: column position                                      *
    259          *                 line:   line position                                        *
    260          *   Return:                                                                    *
    261          *******************************************************************************/
    262          
    263          void set_cursor (int column, int line)
    264          {
    265            unsigned char address;
    266          
    267            address = (line * 40) + column;
    268            address = 0x80 + (address & 0x7F);
    269            lcd_write_cmd(address);               /* Set DDRAM address counter to 0     */
    270          }
    271          
    272          /*******************************************************************************
    273          * Clear the LCD display                                                        *
    274          *   Parameter:                                                                 *
    275          *   Return:                                                                    *
    276          *******************************************************************************/
    277          
    278          void lcd_clear (void)
    279          {
    280            lcd_write_cmd(0x01);                  /* Display clear                      */
    281            set_cursor (0, 0);
    282          }
    283          
    284          
    285          /*******************************************************************************
    286          * Print sting to LCD display                                                   *
    287          *   Parameter:    string: pointer to output string                             *
    288          *   Return:                                                                    *
    289          *******************************************************************************/
    290          
    291          void lcd_print (char *string)
    292          {
    293            while (*string)  {
    294              lcd_putchar (*string++);
    295            }
    296          }
    297          
    298          
    299          /*******************************************************************************
    300          * Display bargraph on LCD display                                              *
    301          *   Parameter:     pos_x: horizontal position of bargraph start                *
    302          *                  pos_y: vertical position of bargraph                        *
    303          *                  value: size of bargraph active field (in pixels)            *
    304          *   Return:                                                                    *
    305          *******************************************************************************/
    306          
    307          void lcd_bargraph (int pos_x, int pos_y, int value) {
    308            int i;
    309          
    310            set_cursor (pos_x, pos_y);
    311            for (i = 0; i < 16; i++)  {
    312              if (value > 5) {
    313                lcd_putchar (0x05);
    314                value -= 5;
    315              } else {
    316                lcd_putchar (value);
    317                while (i++ < 16) lcd_putchar (0);
    318              }
    319            }
    320          }
    321          
    322          /******************************************************************************/

   Maximum stack usage in bytes:

     Function        .cstack
     --------        -------
     lcd_bargraph        16
     lcd_clear            8
     lcd_init            16
     lcd_print            8
     lcd_putchar          8
     lcd_write_4bit       0
     lcd_write_cmd        8
     set_cursor           8
     wait_while_busy     24


   Section sizes:

     Function/Label  Bytes
     --------------  -----
     SWAP_DATA         64
     UserFont          64
     wait_while_busy  136
     lcd_write_4bit    52
     lcd_write_cmd     34
     lcd_putchar       32
     lcd_init         136
     set_cursor        24
     lcd_clear         16
     lcd_print         20
     lcd_bargraph      68
     ??DataTable4       4
     ??DataTable6       4
     ??DataTable8       4
     ??DataTable10      4

 
 128 bytes in section .rodata
 534 bytes in section .text
 
 534 bytes of CODE  memory
 128 bytes of CONST memory

Errors: none
Warnings: none

⌨️ 快捷键说明

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