lcd.c File Reference

Implementation: wrapper for ROM LCD number display functions. More...

#include <config.h>
#include <dlcd.h>
#include <conio.h>
#include <string.h>
#include <sys/h8.h>
#include <sys/lcd.h>
#include <rom/registers.h>
#include <lnp/sys/irq.h>
Include dependency graph for lcd.c:

Go to the source code of this file.

Macros

#define set(b)   __asm__ __volatile__("bset %0,@0xbb:8" : : "i"(b));
 set single bit convenience macro More...
 
#define clr(b)   __asm__ __volatile__("bclr %0,@0xbb:8" : : "i"(b));
 clear single bit convenience macro More...
 
#define slowdown()
 generate the necessary delay for the i2c bus. More...
 

Functions

void lcd_number (int i, lcd_number_style n, lcd_comma_style c)
 show number on LCD display More...
 
static __inline__ void i2c_start (void)
 generate an i2c start condition. More...
 
static __inline__ void i2c_stop (void)
 generate an i2c stop condition. More...
 
static __inline__ void i2c_read_ack (void)
 read the acknoledge from the i2c bus. More...
 
static __inline__ void i2c_write (unsigned char val)
 write one byte to the i2c bus. More...
 
static void lcd_write_data (unsigned char *data, unsigned char len)
 write an array of bytes to the i2c bus. More...
 
 HANDLER_WRAPPER ("lcd_refresh_next_byte", "lcd_refresh_next_byte_core")
 lcd refresh handler, called from system timer interrupt More...
 
void lcd_refresh_next_byte_core (void)
 alternate name for the refresh next byte routine More...
 
void lcd_refresh (void)
 refresh the entire LCD display More...
 
void lcd_power_on (void)
 power on the LCD controller More...
 
void lcd_power_off (void)
 power off the LCD controller More...
 
void lcd_init (void)
 initialize the LCD display driver More...
 

Variables

unsigned char lcd_refresh_counter
 counter for lcd refresh in ms More...
 
unsigned char lcd_byte_counter
 LCD byte to refresh. More...
 
unsigned char lcd_refresh_period = 2
 LCD refresh period in ms. More...
 
static unsigned char lcd_shadow [LCD_DATA_OFFSET+LCD_DATA_SIZE]
 lcd_shadow buffer: More...
 

Detailed Description

Implementation: wrapper for ROM LCD number display functions.

Author
Markus L. Noga marku.nosp@m.s@no.nosp@m.ga.de

Definition in file lcd.c.

Macro Definition Documentation

◆ clr

#define clr (   b)    __asm__ __volatile__("bclr %0,@0xbb:8" : : "i"(b));

clear single bit convenience macro

Definition at line 113 of file lcd.c.

◆ set

#define set (   b)    __asm__ __volatile__("bset %0,@0xbb:8" : : "i"(b));

set single bit convenience macro

Definition at line 111 of file lcd.c.

◆ slowdown

#define slowdown ( )

generate the necessary delay for the i2c bus.

the h8/300 at 16 MHz is slow enough to run without delay, when running this code from RAM. There might be some delay necessary when running from ROM.

Definition at line 121 of file lcd.c.

Function Documentation

◆ HANDLER_WRAPPER()

HANDLER_WRAPPER ( "lcd_refresh_next_byte"  ,
"lcd_refresh_next_byte_core"   
)

lcd refresh handler, called from system timer interrupt

refresh one byte of display_memory.

Bytes are refreshed in round robin fashon and the lcd_shadow buffer is updated. If there was no difference between display_memory and the lcd_shadow buffer, the actual write to the LCD controller is skipped.

This routine is called every 6ms from the timer interrupt, resulting in a complete LCD update every 54ms, which is a refresh rate of 18 updates per second.

◆ i2c_read_ack()

static __inline__ void i2c_read_ack ( void  )
static

read the acknoledge from the i2c bus.

Warning: the value of the acknoledge is ignored. We can't do much on errors anyway.

Definition at line 153 of file lcd.c.

References clr, PORT6_DDR, rom_port6_ddr, SCL, SDA, set, and slowdown.

Referenced by lcd_write_data().

◆ i2c_start()

static __inline__ void i2c_start ( void  )
static

generate an i2c start condition.

Definition at line 124 of file lcd.c.

References clr, SCL, SDA, set, and slowdown.

Referenced by lcd_write_data().

◆ i2c_stop()

static __inline__ void i2c_stop ( void  )
static

generate an i2c stop condition.

Definition at line 136 of file lcd.c.

References clr, SCL, SDA, set, and slowdown.

Referenced by lcd_write_data().

◆ i2c_write()

static __inline__ void i2c_write ( unsigned char  val)
static

write one byte to the i2c bus.

Parameters
valbyte to write to the i2c bus

Definition at line 169 of file lcd.c.

References clr, SCL, SDA, set, and slowdown.

Referenced by lcd_write_data().

◆ lcd_init()

void lcd_init ( void  )

initialize the LCD display driver

initialize LCD driver

output drivers are configured as outputs. the lcd_shadow buffer is cleared and initialized. the LCD controller is enabled.

Definition at line 295 of file lcd.c.

References clr, I2C_WRITE, lcd_byte_counter, LCD_DEV_ID, LCD_LONG_CMD, lcd_power_on(), lcd_refresh_counter, lcd_shadow, LCD_SHORT_CMD, memset(), PORT6_DDR, rom_port6_ddr, SCL, and SDA.

◆ lcd_number()

void lcd_number ( int  i,
lcd_number_style  n,
lcd_comma_style  c 
)

show number on LCD display

Parameters
ithe number
na number style
ca comma style

◆ lcd_power_off()

void lcd_power_off ( void  )

power off the LCD controller

power off LCD display

the LCD controller is put in low power mode and output drivers to the LCD controller are disabled.

Note: without disabling the output drivers the CPU will not save power in sleep mode.

Definition at line 279 of file lcd.c.

References clr, LCD_DISABLE, LCD_MODE_SET, lcd_refresh(), lcd_shadow, LCD_SHORT_CMD, lcd_write_data(), SCL, and SDA.

◆ lcd_power_on()

void lcd_power_on ( void  )

power on the LCD controller

power on LCD display, also called from lcd_init()

the LCD controller is enabled.

Definition at line 266 of file lcd.c.

References LCD_ENABLE, LCD_MODE_SET, lcd_shadow, LCD_SHORT_CMD, and lcd_write_data().

Referenced by lcd_init().

◆ lcd_refresh()

void lcd_refresh ( void  )

refresh the entire LCD display

show LCD display contents to the world

the entire 9 bytes of display_memory are written to the LCD controller unconditionally. lcd_shadow is updated to the new values.

Definition at line 254 of file lcd.c.

References display_memory, LCD_DATA_OFFSET, LCD_DATA_SIZE, LCD_LONG_CMD, lcd_shadow, and lcd_write_data().

Referenced by lcd_power_off(), show_off(), and show_on().

◆ lcd_refresh_next_byte_core()

void lcd_refresh_next_byte_core ( void  )

alternate name for the refresh next byte routine

Todo:
find a better description for this

Definition at line 229 of file lcd.c.

References display_memory, lcd_byte_counter, LCD_DATA_OFFSET, LCD_DATA_SIZE, lcd_shadow, LCD_SHORT_CMD, and lcd_write_data().

◆ lcd_write_data()

static void lcd_write_data ( unsigned char *  data,
unsigned char  len 
)
static

write an array of bytes to the i2c bus.

Parameters
dataarray of bytes to write to the i2c bus
lennumber of bytes to write

len bytes are written to the i2c bus, including initial start condition and final stop condition. The first byte must contain a device address and the r/w flag.

Definition at line 195 of file lcd.c.

References i2c_read_ack(), i2c_start(), i2c_stop(), and i2c_write().

Referenced by lcd_power_off(), lcd_power_on(), lcd_refresh(), and lcd_refresh_next_byte_core().

Variable Documentation

◆ lcd_byte_counter

unsigned char lcd_byte_counter

LCD byte to refresh.

Definition at line 43 of file lcd.c.

Referenced by lcd_init(), and lcd_refresh_next_byte_core().

◆ lcd_refresh_counter

unsigned char lcd_refresh_counter

counter for lcd refresh in ms

Definition at line 42 of file lcd.c.

Referenced by lcd_init().

◆ lcd_refresh_period

unsigned char lcd_refresh_period = 2

LCD refresh period in ms.

Definition at line 44 of file lcd.c.

◆ lcd_shadow

unsigned char lcd_shadow[LCD_DATA_OFFSET+LCD_DATA_SIZE]
static

lcd_shadow buffer:

contains the last display_memory bytes written to the LCD controller at position LCD_DATA_OFFSET.

lcd_shadow also contains the buffer for the i2c commands written to the LCD controller.

At offset LCD_SHORT_CMD a small piece of memory is reserved for direct commands to the LCD controller. This is used for power on/off, and for single byte updates.

At offset LCD_LONG_CMD a small piece of memory is reserved for the i2c command header to do a full LCD update. The display data directly follows this header.

The entire buffer in memory looks like this:

0 1 2 3 4 5 +---—+---—+---—+---—+---—+— —+ | Addr | Cmd | Data | Addr | 0x00 | display data (9 bytes) | +---—+---—+---—+---—+---—+— —+ __________________/ ____________________________________/ LCD_SHORT_CMD LCD_LONG_CMD with display data

Definition at line 72 of file lcd.c.

Referenced by lcd_init(), lcd_power_off(), lcd_power_on(), lcd_refresh(), and lcd_refresh_next_byte_core().


brickOS is released under the Mozilla Public License.
Original code copyright 1998-2005 by the authors.

Generated for brickOS Kernel Developer by doxygen 1.8.16