📄 upsd_lcd.c
字号:
/*------------------------------------------------------------------------
uPSD_LCD.c
Version:
June 2004, Version 1.1 - Unused functions removed.
Dependencies:
upsd_timer.c - needed for delays used in functions that write to the LCD.
Description:
The uPSD3200 LCD display driver.
Copyright (c) 2004 ST Microelectronics
This example demo code is provided as is and has no warranty,
implied or otherwise. You are free to use/modify any of the provided
code at your own risk in your applications with the expressed limitation
of liability (see below) so long as your product using the code contains
at least one uPSD products (device).
LIMITATION OF LIABILITY: NEITHER STMicroelectronics NOR ITS VENDORS OR
AGENTS SHALL BE LIABLE FOR ANY LOSS OF PROFITS, LOSS OF USE, LOSS OF DATA,
INTERRUPTION OF BUSINESS, NOR FOR INDIRECT, SPECIAL, INCIDENTAL OR
CONSEQUENTIAL DAMAGES OF ANY KIND WHETHER UNDER THIS AGREEMENT OR
OTHERWISE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
-------------------------------------------------------------------------*/
#pragma optimize(9,size)
#include "upsd3200.h"
#include "upsd_hardware.h"
#include "upsd_timer.h"
#include "upsd_LCD.h"
typedef xdata struct LCD_display_st {
unsigned char LCD_CMD_WR; // LCD_BASE+0x00
unsigned char LCD_CMD_RD; // +0x01
unsigned char LCD_RAM_WR; // +0x02
unsigned char LCD_RAM_RD; // +0x03
} LCD_DISPLAY;
// XDATA address for display
xdata LCD_DISPLAY LCD_reg _at_ LCD_BASE_ADDR;
//extern code char blank[];
static unsigned char Cursor_LCD;
// These are the LCD functions.
void lcd_init(void) // initialize LCD module per specs
{
delay_10ms();
LCD_reg.LCD_CMD_WR = 0x30;
delay_10ms();
LCD_reg.LCD_CMD_WR = 0x30;
delay_10ms();
LCD_reg.LCD_CMD_WR = 0x30;
delay_10ms();
LCD_reg.LCD_CMD_WR = 0x38; // 8 bits, 2 lines, 5 x 7 font
delay_10ms(); // delay 4 ms
BusyCheck();
LCD_reg.LCD_CMD_WR = 0x0C; //Display on, Cursor off, Non-Blink
BusyCheck();
LCD_reg.LCD_CMD_WR = 0x01; //Clear display
BusyCheck();
LCD_reg.LCD_CMD_WR = 0x02; //Cursor home
BusyCheck();
LCD_reg.LCD_CMD_WR = 0x06; //Cursor inc, no shift/cursor move
Cursor_LCD = DD_ADDR; //Display from 1st row, 1st column
BusyCheck();
LCD_reg.LCD_CMD_WR = Cursor_LCD;
}
void BusyCheck(void) // wait until BF is cleared
{
while (LCD_reg.LCD_CMD_RD & BF_BIT);
}
void printfLCD(unsigned char *chr_ptr, ...) {
unsigned char *var_ptr=&chr_ptr+1;
unsigned char var;
while (*chr_ptr != NULL) {
BusyCheck();
if (*chr_ptr == '\r') {
chr_ptr++;
Cursor_LCD &= 0xC0; //return to position 0 at current line
LCD_reg.LCD_CMD_WR = Cursor_LCD;
}
else
if (*chr_ptr == '\n') {
chr_ptr++;
Cursor_LCD ^= 0x40; //goto next line
Cursor_LCD &= 0xC0; //return to position 0
LCD_reg.LCD_CMD_WR = Cursor_LCD;
}
else
if (*chr_ptr == '%') {
chr_ptr++;
if (*chr_ptr == 'd') { // display 1 digit decimal 0-9
chr_ptr++;
var = *var_ptr++;
LCD_reg.LCD_RAM_WR = (var & 0x0F)+'0';
}
else
if (*chr_ptr == 'x') { // display 1 byte hex 00-FF
chr_ptr++;
var = *var_ptr++;
//LCD_reg.LCD_RAM_WR = Bin2Hex(var>>4);
LCD_reg.LCD_RAM_WR = htoa_hi(var);
BusyCheck();
//LCD_reg.LCD_RAM_WR = Bin2Hex(var&0x0F);
LCD_reg.LCD_RAM_WR = htoa_lo(var);
}
else
if (*chr_ptr == 'w') { // display 1 word hex 0000-FFFF
chr_ptr++;
var = *var_ptr++;
//LCD_reg.LCD_RAM_WR = Bin2Hex(var>>4);
LCD_reg.LCD_RAM_WR = htoa_hi(var);
BusyCheck();
//LCD_reg.LCD_RAM_WR = Bin2Hex(var&0x0F);
LCD_reg.LCD_RAM_WR = htoa_lo(var);
BusyCheck();
var = *var_ptr++;
//LCD_reg.LCD_RAM_WR = Bin2Hex(var>>4);
LCD_reg.LCD_RAM_WR = htoa_hi(var);
BusyCheck();
//LCD_reg.LCD_RAM_WR = Bin2Hex(var&0x0F);
LCD_reg.LCD_RAM_WR = htoa_lo(var);
}
else {
LCD_reg.LCD_RAM_WR = *chr_ptr++; //out character to LCD Diaplay RAM
}
}
else
{
LCD_reg.LCD_RAM_WR = *chr_ptr++; //out character to LCD Diaplay RAM
}
}
}
// this is a collection of conversion routines used in conjunction with the LCD display
char htoa_lo(byte) // converts low nibble of unsigned byte
// (0-F hex) to ascii
unsigned char byte;
{
byte = byte & 0x0F; // keep lower nibble only
if (byte <= 0x09)
return(byte + 0x30);
else
return (byte + 0x37);
}
char htoa_hi(byte) // converts hi nibble of unsigned byte
// (0-F hex) to ascii
unsigned char byte;
{
byte = byte & 0xF0; // keep upper nibble only
byte = byte >> 4;
if (byte <= 0x09)
return(byte + 0x30);
else
return (byte + 0x37);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -