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

📄 smproc1.c

📁 A Digital Thermometer Using the AT89C2051 MCU
💻 C
字号:
@CODE_TAB = Listing 1.

@CODE_TAB = /* <R>
<N> By J. Dybowski - 1995 <R>
<N> This file contains support functions for the 8 x 2 LCD display.   <R>
  Interface is using direct processor I/O method in 4 bit mode. <R>
*/

@CODE_TAB = 

@CODE_TAB = /* 8051 definitions */ <R>
#include sreg.h <R>
#include sbit.h 

@CODE_TAB = 

@CODE_TAB = /* Defined bits for LCD control */ <R>
#define DEN P1.2 <R>
#define DRS P1.3

@CODE_TAB = 

@CODE_TAB = /* Global register (IRAM) data */ <R>
register unsigned char Cursor;

@CODE_TAB = 

@CODE_TAB = /* Putstring to LCD */ <R>
PutString (unsigned char *p) <R>
{ <R>
<N>  unsigned char c;

@CODE_TAB = 

@CODE_TAB = <N>  while (c = *p++)<R>
<N>     PutChar (c); 

@CODE_TAB = }

@CODE_TAB = 

@CODE_TAB = /* Putchar to LCD */ <R>
PutChar (unsigned char c) <R>
{ <R>
<N>  if (c == '\n')<R>
<N>  {<R>
        if (Cursor < 8)<R>
            PositionLcd (8);<R>
        else <R>
<N>          PositionLcd (0);<R>
   } <R>
<N>  else <R>
<N>      DataWr (c);<R>
}

@CODE_TAB = /* Position LCD cursor */<R>
 PositionLcd (unsigned char c)<R>
{ <R>
<N>  Cursor = c;

@CODE_TAB = 

@CODE_TAB =     if (c >><N>7)<R>
        CommandWr ((c - 8) + 64 + 0x80);<R>
    else<R>
        CommandWr (c + 0x80);

@CODE_TAB = 

@CODE_TAB = 	 delay (5);<R>
}

@CODE = 

@CODE_TAB = /* Clear LCD and home cursor */<R>
ClearLcd (void) 

@CODE_TAB = {<R>
<N>  Cursor = 0;<R>
<N>  CommandWr (1);

@CODE_TAB = 

@CODE_TAB =     delay (5); <R>
}

@CODE_TAB = /* Write to LCD data register and handle cursor positioning 
*/ <R>
DataWr (unsigned char c) <R>
{<R>
    if (Cursor == 8)<R>
        PositionLcd (8);<R>
    else if (Cursor == 16)<R>
        PositionLcd (0);

@CODE_TAB = 

@CODE_TAB =     Cursor++;

@CODE_TAB = 

@CODE_TAB =     setbit (DRS)<R>
    setbit (DEN)<R>
    P1 &= 0x0f;<R>
    P1 |= (c & 0xf0);<R>
    clrbit (DEN)

@CODE_TAB = 

@CODE_TAB =     setbit (DEN)<R>
    P1 &= 0x0f;<R>
    P1 |= (c << 4);<R>
    clrbit (DEN) 

@CODE_TAB = }

@CODE_TAB = 

@CODE_TAB = /* Write to LCD command register */<R>
CommandWr (unsigned char c)

@CODE_TAB = {

@CODE_TAB = <N>  clrbit (DRS)<R>
<N>  setbit (DEN) <R>
<N>  P1 &= 0x0f; <R>
<N>  P1 |= (c & 0xf0); <R>
<N>  clrbit (DEN)

@CODE_TAB =  

@CODE_TAB = <N>  setbit (DEN) <R>
<N>  P1 &= 0x0f; <R>
<N>  P1 |= (c << 4); <R>
<N>  clrbit (DEN)

@CODE_TAB =  

@CODE_TAB = <N>  delay (2); 

@CODE_TAB = }

@CODE_TAB = 

@CODE_TAB = /* Initialize LCD panel */<R>
InitLcd (void) <R>
{ <R>
<N>  /* Put LCD in known state */ <R>
<N>  clrbit (DRS) <R>
<N>  delay (20);

@CODE_TAB = 

@CODE_TAB = <N>  setbit (DEN) <R>
<N>  P1 &= 0x0f; <R>
<N>  P1 |= (0x30); <R>
<N>  clrbit (DEN) <R>
<N>  delay (5);



@CODE_TAB = <N>  setbit (DEN) <R>
<N>  P1 &= 0x0f; <R>
<N>  P1 |= (0x30); <R>
<N>  clrbit (DEN) <R>
<N>  delay (5);

@CODE_TAB = 

@CODE_TAB = <N>  setbit (DEN) <R>
<N>  P1 &= 0x0f; <R>
<N>  P1 |= (0x30); <R>
<N>  clrbit (DEN) <R>
<N>  delay (5);

@CODE_TAB = 

@CODE_TAB = <N>  /* Set 4 bit mode */ <R>
<N>  setbit (DEN) <R>
<N>  P1 &= 0x0f; <R>
<N>  P1 |= (0x20); <R>
<N>  clrbit (DEN) <R>
<N>  delay (5);

@CODE_TAB = 

@CODE_TAB = <N>  /* 4 bit, 1 line, 4X7 matrix */ <R>
<N>  CommandWr (0x28); <R>
<N>  delay (5);

@CODE_TAB = 

@CODE_TAB = <N>  /* Display on, cursor off */ <R>
<N>  CommandWr (0x0c); <R>
<N>  delay (5);

@CODE_TAB = 

@CODE_TAB = <N>  /* Auto increment, shift right */ <R>
<N>  CommandWr (0x06); <R>
<N>  delay (5);

@CODE_TAB = 

@CODE_TAB = <N>  /* Clear the LCD and set initial cursor address */ 
<R>
<N>  ClearLcd (); 

@CODE_TAB = }

⌨️ 快捷键说明

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