Electronic Sculpture Archive
Bruce Cannon

This site is an archive of my older interactive,  electronic and computer-controlled sculpture.  You can always find out about my latest projects via my gateway, brucecannon.com.

   

hdsp2113.c

Code Listing

Below is my driver for using the Hewlett-Packard HDSP2113 LED display with Custom Computer Services PIC C compiler.  There are functions to blink the display, flash individual characters, scroll characters and write to individual display positions.

To use this code you will also need my standard header file of convenience labels, my_prefs.h.

/****************************************************************************************
HDSP2113.C
Bruce Cannon
05-22-99
Driver for HP HDSP2113 dot matrix LED 8-char display, currently set up for use on a
28 pin PIC.
Relies on convenience labels defined in myprefs.h.
****************************************************************************************/
struct								//For setting bits in the control word:
{
	byte brightness : 3;
	bit flash;
	bit blink;
	bit test_result;
	bit self_test;
	bit clear;
} CTL_REG;
#byte CTL_REG = 6					//Maps struct onto PORTB.
#bit FLASH_ATTRIBUTE = CTL_REG.0	//Used to set flash attribute of a particular bit.
#define BRIGHTNESS_MASK 0xF8		//This value used to clear brightness bits.
#define HUNDRED_PERCENT 0x00		//These values used to set brightness bits.
#define EIGHTY_PERCENT 0x01			//	"
#define FIFTY_PERCENT 0x02			//	"
#define TWENTY_PERCENT 0x06			//	"
struct								//For setting control pins:
{
	byte address : 3;				//A0,A1,A2.  000 = leftmost character.
	byte reg_select : 3;			//A3,A4,FL.  Used with constants below.
	bit _reset;
	bit _write;
}	CTL_PINS;
#byte CTL_PINS = 7					//Maps struct onto PORTC.
#define FLASH_RAM 0x03				//Used in reg_select bits.
#define UDC_ADDR 0x04				//	"
#define UDC_RAM 0x05				//	"
#define CTL_RAM 0x06				//	"
#define CHAR_RAM 0x07				//	"
#define HOME_POSITION 0				//Used with display_screen().
#define CLEAR_DISPLAY 1				//	"
/****************************************************************************************
Switches.
****************************************************************************************/
#define NORMAL_DISPLAY 0x0A			//PORTB values set 50% bright, no blink, flash enabled.
#define CONTROL 0xF0				//PORTC configuration to access control register,
									//and set initial states of pins at same time.
/****************************************************************************************
Prototypes.
****************************************************************************************/
void scrolling_display(char ascii_value);
void display_char(byte display_position, char ascii_value);
void display_screen(byte which_value);
void flash_character(bit on_off, byte display_position);
void blink_display(bit on_off);
void initialize_display();
void write_display();
void display_binary(byte what_value);
/****************************************************************************************
Description:
Power up initialization of HDSP2113 display using predetermined settings.
Assumes:
-register page 0 already selected.
-desired default settings already defined in NORMAL_DISPLAY.
****************************************************************************************/
void initialize_display()
{
	RP0 = TRIS;							//Switch to register page 1.
	CTL_REG = 0;						//Make all port address pins outputs.
	CTL_PINS = 0;						//Make all control pins outputs.
	RP0 = PORT;							//Switch back to register page 0.
CTL_PINS._write = _NO;				//Disable write pin.
	CTL_PINS._reset = _YES;				//Reset display.
	delay_us(1);						//	"
	CTL_PINS._reset = _NO;				//	"
	delay_us(150);						//	"
	CTL_PINS.reg_select = CTL_RAM;		//Select control register.
	CTL_REG = NORMAL_DISPLAY;			//Sets fifty percent bright, no flash or blink.
	write_display();					//Latch in.
}
/****************************************************************************************
Writes specified ascii value to next HDSP2113 display position, using a static,
rotating display-position pointer, or performs a display control function.
CLEAR_DISPLAY clears the display and sets pointer to 0 (leftmost position).
HOME_POSITION sets position pointer to 0.
Can be used with compiler's constant-string workaround to
display a screenful of chars.
Assumes:
-compiler correctly truncates/masks inverted byte.
-register page 0 already selected.
-all other bits correctly set in CTL_PINS.
Takes:
-one ASCII value, or one of a few control codes.
Returns:
-Nothing.
****************************************************************************************/
void display_screen(byte which_value)
{
	static byte display_position = 0;
	if((which_value >= ' ') & (which_value <= '~'))	//If printable character,
	{
		display_char(display_position,which_value);	//write it,
		++display_position;							//increment position for next time.
		if(display_position > 7)					//At end of display,
		{
			display_position = 0;					//roll around to the beginning again.
		}
	}
	if(which_value == HOME_POSITION)
	{
		display_position = 0;						//Set pointer to leftmost position.
	}
	if(which_value == CLEAR_DISPLAY)
	{
		CTL_PINS.reg_select = CTL_RAM;				//Select control register.
		CTL_REG.clear = YES;						//Set clear-ram bit.
		write_display();							//Latch it in.
		CTL_REG = NORMAL_DISPLAY;					//Return all settings to default.
		write_display();							//Latch it in.
		display_position = 0;						//Reset pointer.
	}
}
/*****************************************************************************************
Description:
Scrolling display function for the HDSP2113.  Scroll is from right to left.
Maintains an array the size of the display.  When passed a single character, shifts it into
the array and then displays writes each value to the display.  HP char order is leftmost =
0, rightmost = 7.
Assumes:
-ascii value passed.
-scroll rate set by periodicity of calls to this function.
Takes:
-one ascii value.
Returns:
-Nothing.
*****************************************************************************************/
void scrolling_display(char ascii_value)
{
	static byte display[9] = "        ";
	byte position;
	for (position = 0; position <= 6; position++)	//Shift chars 0-6 left.
	{
		display[position] = display[position+1];
	}
display[7] = ascii_value;						//Put in new character.
	for (position = 0; position <= 7; position++)	//Write all to display:
	{
		display_char(position,display[position]);
	}
}
/****************************************************************************************
Description:
Displays a binary representation of a byte value on the HDSP2113 in binary.
Assumes:
-Nothing.
Takes:
-8 bit value
Returns:
-Nothing.
****************************************************************************************/
void display_binary(byte what_value)
{
	byte which_bit,which_char;
	for(which_bit = 7,which_char = 0; which_bit <= 7; which_bit--,which_char++)
	{
		if(bit_test(what_value,which_bit))
		{
			display_char(which_char,'1');
		}
		else
		{
			display_char(which_char,'0');
		}
	}
}
/****************************************************************************************
Writes specified ascii value to specified HDSP2113 display position.
HP char order is leftmost = 0, rightmost = 7.
Assumes:
-compiler correctly truncates/masks inverted byte.
-register page 0 already selected.
-all other bits correctly set in CTL_PINS.
Takes:
-one value indicating which character position on display.
-one ASCII value.
Returns:
-Nothing.
****************************************************************************************/
void display_char(byte display_position, char ascii_value)
{
	CTL_PINS.address = display_position;	//Select character.
	CTL_PINS.reg_select = CHAR_RAM;			//Select character register.
	PORTB = ascii_value;					//Set desired character code.
	write_display();						//Latch it in.
}
/****************************************************************************************
Turns flashing on or off on specified character of HDSP2113 display.  HP char order is
leftmost = 0, rightmost = 7.
Assumes:
-HP bit order supplied.
-register page 0 already selected.
-all other bits correctly set.
-implicit truncation of inverted byte.
Takes:
-Positive true bit value to turn flashing ON or OFF for specified char.
-Byte value indicating character position.
Returns:
-Nothing.
****************************************************************************************/
void flash_character(bit on_off, byte display_position)
{
	CTL_PINS.reg_select = FLASH_RAM;		//Select flash register.
	CTL_PINS.address = display_position;	//Select character.
	FLASH_ATTRIBUTE = on_off;				//Set attribute bit.
	write_display();						//Latch it in.
}
/****************************************************************************************
Description:
Sets whole HDSP2113 display blinking, or turns that feature off.
Takes:
-positive-true bit.
Assumes:
-register page 0 already selected.
-other bits in port B already set correctly.
-other bits in port C already set correctly.
****************************************************************************************/
void blink_display(bit on_off)
{
	CTL_PINS.reg_select = CTL_RAM;		//Select control register.
	CTL_REG = NORMAL_DISPLAY;			//Set all bit defaults.
	CTL_REG.blink = on_off;				//Set specified action.
	write_display();					//Latch it in.
}
/****************************************************************************************
Convenience toggle function.
****************************************************************************************/
void write_display()
{
	CTL_PINS._write = _YES;
	delay_us(1);
	CTL_PINS._write = _NO;
}

 

Site contents licensed under a
Creative Commons License.

Creative Commons License