📄 lcd._c
字号:
//
// File Name: lcd.c
//
// Title: LCD interface implementation
//
// Description: Interface implementation file for the Hitachi HD44780U.
// This driver is for the STK200.
// STK200 port information
// DATA = PORTA
// RS = PORTC BIT 6
// R/W = PORTD BIT 6
// E = PORTC BIT 7
//
// Creation Date: 2/2/00 11:49:37 PM
//
// By: A.C. Verbeck
//
// This file is subject to the terms and conditions of the GNU General Public
// License. See the file COPYING in the main directory of this archive
// for more details.
//
#include <io8515v.h>
#include <stdio.h>
#include "Basetype.h"
#include "t0.h"
#include "lcd.h"
//
// Local defines
//
#define FUNCTION_SET 0x38
#define CMD 0x00
#define DATA 0x01
#define CMD_IO (PUInt8)0x8000
#define DATA_IO (PUInt8)0xC000
//
// Local data
//
static UInt8 init_tab[] = {
FUNCTION_SET,
LCD_CLEAR,
LCD_OFF,
LCD_ON,
LCD_CLEAR
};
//
// Local functions
//
/*static void LCD_write(UInt8 val, UInt8 sel);
static UInt8 LCD_read(UInt8 sel);
static void LCD_busy_test(void);
static void delay(UInt16 dly);*/
//
// Function Name:
// LCD_init
//
// Description:
// Initialize the LCD.
//
// Parameters:
// (none)
//
// Returns:
// (nothing)
//
void LCD_init(void)
{
UInt8 i;
for (i=0; i<5; i++) {
LCD_busy_test();
LCD_write(init_tab[i], CMD);
}
}
//
// Function Name:
// LCD_clear
//
// Description:
// Clear the LCD.
//
// Parameters:
// (none)
//
// Returns:
// (nothing)
//
void LCD_clear(void)
{
LCD_command(LCD_CLEAR);
}
//
// Function Name:
// LCD_reset
//
// Description:
// Reset the LCD.
//
// Parameters:
// (none)
//
// Returns:
// (nothing)
//
void LCD_reset(void)
{
T0_sleep(15); // Hitachi says wait 15mS before writing the LCD
LCD_write(0x30, CMD); // Write the init (first time)
T0_sleep(5); // Then, wait 4.1mS
LCD_write(0x30, CMD); // Write the init again (second time)
T0_sleep(1); // Then, wait 100uS
LCD_write(0x30, CMD); // Write the init again (last time)
}
void LCD_command(UInt8 data)
{
LCD_busy_test();
LCD_write(data, CMD);
}
void LCD_putc(Char c)
{
LCD_busy_test();
if (c == '\n')
LCD_command(LCD_NEW_LINE);
else
LCD_write(c, DATA);
}
void LCD_puts(String s)
{
while (*s) {
LCD_busy_test();
if (*s == '\n')
LCD_command(LCD_NEW_LINE);
else
LCD_write(*s, DATA);
++s;
}
}
//
// Function Name:
// LCD_write
//
// Description:
// Write data or cmd to HD44780U
//
// Parameters:
// val = data value to be written to HD44780U
// sel = data / cmd
// 0 - cmd write
// 1 - data write is selected
//
// Returns:
// (nothing)
//
static void LCD_write(UInt8 val, UInt8 sel)
{
MCUCR = 0xC0;
switch (sel) {
case CMD: *CMD_IO = val; break;
case DATA: *DATA_IO = val; break;
}
}
//
// Function Name:
// LCD_read
//
// Description:
// Read data or cmd to HD44780U
//
// Parameters:
// sel = data / cmd
// 0 - cmd read
// 1 - data read
//
// Returns:
// data read from LCD
//
static UInt8 LCD_read(UInt8 sel)
{
UInt8 rVal;
MCUCR = 0xC0;
switch (sel) {
case CMD: rVal = *CMD_IO; break;
case DATA: rVal = *DATA_IO; break;
}
return rVal;
}
//
// Function Name:
// LCD_busy_test
//
// Description:
// Test if the LCD is busy or not
//
// Parameters:
// (none)
//
// Returns:
// (nothing)
//
static void LCD_busy_test(void)
{
while (LCD_read(CMD) & 0x80);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -