MAX456
MAX456
//// ////
//// MAX7456.C ////
//// ////
//// Library for a Maxim MAX7456 On-Screen Display ////
//// ////
//// osd_init() - Call before other functions. ////
//// ////
//// osd_enable(e) - If e is TRUE, enables the OSD display. If e ////
//// is FALSE, disables the display. Display can be ////
//// enabled/disabled and it won't lose it's display memory. ////
//// osd_init() will enable the display with blank memory. ////
//// ////
//// osd_gotoxy(x,y) - Set write position on OSD (upper left is 0,0). ////
//// ////
//// osd_putc(c) - Will display c on the next position of the OSD. ////
//// If the character is not supported, it will display an empty ////
//// character. ////
//// The following have special meaning: ////
//// \f Clear display ////
//// \r Go to start of current row ////
//// \n Go to start of next column ////
//// \b Go back one position ////
//// ////
//// CONFIGURATION ////
//// Either define MAX7456_SPI to SPI1 or SPI2 to use the hardware ////
//// SPI port, -OR- define MAX7456_OUT and MAX7456_CLK to the ////
//// IO pins used (the input SPI pin is not needed by this driver). ////
//// MAX7456_CS must be defined to configure the chip select pin. ////
//// ////
//// EXAMPLE ////
//// osd_init(); ////
//// osd_enable(TRUE); ////
//// osd_putc('\f'); ////
//// osd_gotoxy(0,3); ////
//// printf(osd_putc, "Hello\n World\n"); ////
//// ////
///////////////////////////////////////////////////////////////////////////
//// (C) Copyright 1996, 2009 Custom Computer Services ////
//// This source code may only be used by licensed users of the CCS C ////
//// compiler. This source code may only be distributed to other ////
//// licensed users of the CCS C compiler. No other use, reproduction ////
//// or distribution is permitted without written permission. ////
//// Derivative programs created using this software in object code ////
//// form are not restricted in any way. ////
///////////////////////////////////////////////////////////////////////////
#if defined(MAX7456_SPI)
#use spi(MAX7456_SPI, mode=0, MASTER, bits=8, MSB_FIRST, stream=STREAM_MAX7456)
#else
#use spi(mode=0, MASTER, bits=8, MSB_FIRST, do=MAX7456_OUT, clk=MAX7456_CLK,
stream=STREAM_MAX7456)
#endif
#ifndef MAX7456_CS
#define MAX7456_CS PIN_D0
#endif
#define OSD_MAX_X 30
#define OSD_MAX_Y 16
#define MAX7456_CHAR_SPACE 0
MAX7456_XFER(reg);
MAX7456_XFER(val);
output_high(MAX7456_CS);
}
max7456_write(MAX7456_REG_VM0, reg);
}
void osd_putc(char c)
{
unsigned int8 i;
unsigned int16 addy;
switch(c)
{
case '\f':
max7456_write(MAX7456_REG_DMM, 4);
delay_us(30);
osd_gotoxy(0, 0);
break;
case '\b':
if (g_OSDX)
g_OSDX--;
else
{
if (g_OSDY)
g_OSDY--;
else
g_OSDY = OSD_MAX_Y - 1;
g_OSDX = OSD_MAX_X - 1;
}
osd_gotoxy(g_OSDX, g_OSDY);
break;
case '\r':
g_OSDX = 0;
osd_gotoxy(g_OSDX, g_OSDY);
break;
case '\n':
g_OSDX = 0;
g_OSDY++;
if (g_OSDY >= OSD_MAX_Y)
g_OSDY = 0;
osd_gotoxy(g_OSDX, g_OSDY);
break;
default:
c = Max7456TransformFromASCII(c);
max7456_write(MAX7456_REG_DMM, 0);
max7456_write(MAX7456_REG_DMAH, bit_test(addy, 8));
max7456_write(MAX7456_REG_DMAL, addy & 0xFF);
max7456_write(MAX7456_REG_DMDI, c);
g_OSDX++;
if (g_OSDX >= OSD_MAX_X)
{
g_OSDX = 0;
g_OSDY++;
if (g_OSDY >= OSD_MAX_Y)
g_OSDY = 0;
}
osd_gotoxy(g_OSDX, g_OSDY);
break;
}
}
void osd_init(void)
{
#if (defined(MAX7456_OUT) && defined(MAX7456_CLK))
output_drive(MAX7456_OUT);
output_drive(MAX7456_CLK);
output_high(MAX7456_CS);
output_drive(MAX7456_CS);
#endif
delay_us(200);
osd_enable(TRUE);
}