📄 lcdutl.c
字号:
/*""FUNC COMMENT""*************************************************************
* ID : ---
* function name : int LCD__putdec(int dec)
* function : display decimal number on LCD
* parameter : unsigned int dec;number to be displayed (0乣32767)
* return : int OK ; normal end
* : ERR ; not be initialized
* function used : LCD__putchar();
* notify : can not deal with minus
* History :
*""FUNC COMMENT END""*********************************************************/
int LCD__putdec(unsigned int dec)
{
unsigned int num ; /* number to be displayed */
int i; /* loop counter */
unsigned char str_buf[5]; /* buffer for data display */
if(init_hard){ /* if initialized */
num = dec; /* save number to be displayed */
for(i = 0 ;num != 0; i++){ /* confirm digit */
str_buf[i] = num % 10; /* get every digit number and save in buffer*/
num = num / 10;
}
if(i == 0){ /* if number is 0 */
LCD__putchar('0'); /* display '0' in LCD */
}
else{ /* if number is not 0 */
for(--i; i >= 0; i--){ /* loop times of digits */
LCD__putchar(str_buf[i] + '0'); /* after transfered into ASCII code */
} /* display in LCD */
}
return OK; /* normal end */
}
/* if not be initialized */
return ERR; /* return error */
}
/*""FUNC COMMENT""*************************************************************
* ID : ---
* function name : int LCD__puthex(int dec)
* function : display hexadeimal number in LCD
* parameter : unsigned int dec;number to be displayed (0乣0x7fff)
* return : int OK ; normal end
* : ERR ; if not be initialized
* function used : LCD__putchar();
* notice : can not deal with minus
* History :
*""FUNC COMMENT END""*********************************************************/
int LCD__puthex(unsigned int dec)
{
unsigned int num ; /* number to be displayed */
int i ; /* loop counter */
unsigned char str_buf[4]; /* buffer for displaying data */
if(init_hard){ /* if initialized */
num = dec ; /* save number to be displayed */
for(i = 0 ; num != 0; i++){ /* confirm digit */
str_buf[i] = num % 16; /* get every digit number and save in buffer */
num = num / 16;
}
if(i == 0){ /* if number is 0 */
LCD__putchar('0'); /* display '0' in LCD */
}
else{ /* if number is not 0 */
for(--i; i >= 0; i--){ /* after transfered into ASCII code, display in LCD */
if(str_buf[i] < 0x0A){ /* if less than 0x0A (plus 0x30) */
LCD__putchar(str_buf[i] + '0');
}
else{ /* if more than or equal 0x0A (plus 0x37 */
LCD__putchar(str_buf[i] + 0x37);
}
}
}
return OK;
}
return ERR;
}
/* #############################################################################
* ### private function
*/
/*""FUNC COMMENT""*************************************************************
* ID : ---
* function name : void init_timerC(void)
* function : initialize timer C
* : set as output compare mode, confirm time for process LCD command
* parameter : none
* return : none
* function used : none
* notice : interrupt function called by interrupt program
* History :
*""FUNC COMMENT END""*********************************************************/
static void init_timerC(void)
{
tcc0 = 0x00 ; /* set timer C control register 0 */
/* 00000000 */
/* |||||||+ stop count */
/* |||||++- select f1 as count source*/
/* +++++--- this mode invalid */
tcc1 = 0x08 ; /* set timer C control register 1 */
/* 00001000 */
/* |||||+++ this mode invalid */
/* ||||+--- comapre 0(output compare mode) */
/* ++++---- this mode invalid */
cmp0ic = 0x01 ; /* set compare 0 interrupt(priority level=1) */
}
/*""FUNC COMMENT""*************************************************************
* ID : ---
* function name : void set_busy( unsigned int time )
* function : set busy flag(start timer C)
* parameter : unsigned int time ; command processing time(50us*parameter)
* return : none
* function used : none
* notice : none
* History :
*""FUNC COMMENT END""*********************************************************/
static void set_busy(unsigned int time)
{
F_busy = 1; /* set busy flag */
tm0 = time * 1000; /* set timer C */
tcc00 = 1; /* start timer C counter */
}
/*""FUNC COMMENT""*************************************************************
* ID : ---
* function name : void INT_cmp0( void )
* function : compare 0 interrupt function(clear busy flag)
* parameter : none
* return : none
* function used : none
* notice : none
* History :
*""FUNC COMMENT END""*********************************************************/
void INT_cmp0(void)
{
tcc00 = 0; /* stop timer C */
F_busy = 0; /* clear busy flag */
ir_cmp0ic = 0; /* clear interrupt request bit */
}
/*""FUNC COMMENT""*************************************************************
* ID : ---
* function name : static int read_creg(void)
* function : read from Command-Register
* parameter : none
* return : int ; value read(only lower 8 bits valid)
* function used : _lcd1__rd_nibble_creg();
* notice : none
* History :
*""FUNC COMMENT END""*********************************************************/
static int read_creg(void)
{
int command;
command = _lcd1__rd_nibble_creg() << 4; /* interface length 4 bits */
command |= _lcd1__rd_nibble_creg();
return command;
}
/*""FUNC COMMENT""*************************************************************
* ID : ---
* function name : static void write_creg(int data)
* function : write Command-Register
* parameter : int command ; value to write(only lower 8 bits valid)
* return : none
* function used : _lcd1__wr_nibble_creg();
* notice : none
* History :
*""FUNC COMMENT END""*********************************************************/
static void write_creg(int command)
{
_lcd1__wr_nibble_creg(command >>4 & 0x0f); /* interface length 4 bits */
_lcd1__wr_nibble_creg(command & 0x0f);
}
/*""FUNC COMMENT""*************************************************************
* ID : ---
* function name : static int read_dreg(void)
* function : read from Data-Register
* parameter : none
* return : int ; value read(only lower 8 bits valid)
* function used : _lcd1__rd_nibble_dreg();
* notice : none
* History :
*""FUNC COMMENT END""*********************************************************/
static int read_dreg(void)
{
int data;
data = _lcd1__rd_nibble_dreg() << 4; /* interface length 4 bits */
data |= _lcd1__rd_nibble_dreg();
return data;
}
/*""FUNC COMMENT""*************************************************************
* ID : ---
* function name : static void write_dreg(int data)
* function : write Data-Register
* parameter : int data ; value to write(only lower 8 bits valid)
* return : none
* function used : _lcd1__wr_nibble_dreg();
* notice : none
* History :
*""FUNC COMMENT END""*********************************************************/
static void write_dreg(int data)
{
_lcd1__wr_nibble_dreg(data>>4 & 0x0f); /* interface length 4 bits */
_lcd1__wr_nibble_dreg(data & 0x0f);
}
/*""FUNC COMMENT""*************************************************************
* ID : ---
* function name : void move_cursol( void )
* function : move cursor position
* parameter : none
* return : none
* function used : LCD_setcursol();
* notice : none
* History :
*""FUNC COMMENT END""*********************************************************/
static void move_cursol(void)
{
if(++cursol_x > 0x0f){ /* move cursor to right, if get to end of the line */
cursol_x = 0; /* move to begin of the line */
if(++cursol_y >= 2){ /* return, if over the second line */
cursol_y = 0; /* return to begin of the line */
}
LCD__setcursol(cursol_x, cursol_y); /* set cursor */
}
}
/******************************************************************************
end of file
******************************************************************************/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -