📄 osram96x16x1.c
字号:
//! until the byte has been written to the controller.
//!
//! \return None.
//
//*****************************************************************************
static void
OSRAM96x16x1WriteFirst(unsigned char ucChar)
{
//
// Set the slave address.
//
I2CMasterSlaveAddrSet(I2C0_MASTER_BASE, SSD0303_ADDR, false);
//
// Write the first byte to the controller.
//
I2CMasterDataPut(I2C0_MASTER_BASE, ucChar);
//
// Start the transfer.
//
I2CMasterControl(I2C0_MASTER_BASE, I2C_MASTER_CMD_BURST_SEND_START);
}
//*****************************************************************************
//
//! \internal
//!
//! Write a byte to the SSD0303 controller.
//!
//! \param ucChar is the byte to be transmitted to the controller.
//!
//! This function continues a transfer to the SSD0303 controller by writing
//! another byte over the I2C bus. This must only be called after calling
//! OSRAM96x16x1WriteFirst(), but before calling OSRAM96x16x1WriteFinal().
//!
//! The data is written in a polled faashion; this function will not return
//! until the byte has been written to the controller.
//!
//! \return None.
//
//*****************************************************************************
static void
OSRAM96x16x1WriteByte(unsigned char ucChar)
{
//
// Wait until the current byte has been transferred.
//
while(I2CMasterIntStatus(I2C0_MASTER_BASE, false) == 0)
{
}
//
// Provide the required inter-byte delay.
//
OSRAM96x16x1Delay(g_ulDelay);
//
// Write the next byte to the controller.
//
I2CMasterDataPut(I2C0_MASTER_BASE, ucChar);
//
// Continue the transfer.
//
I2CMasterControl(I2C0_MASTER_BASE, I2C_MASTER_CMD_BURST_SEND_CONT);
}
//*****************************************************************************
//
//! \internal
//!
//! Write a sequence of bytes to the SSD0303 controller.
//!
//! This function continues a transfer to the SSD0303 controller by writing a
//! sequence of bytes over the I2C bus. This must only be called after calling
//! OSRAM96x16x1WriteFirst(), but before calling OSRAM96x16x1WriteFinal().
//!
//! The data is written in a polled fashion; this function will not return
//! until the entire byte sequence has been written to the controller.
//!
//! \return None.
//
//*****************************************************************************
static void
OSRAM96x16x1WriteArray(const unsigned char *pucBuffer, unsigned long ulCount)
{
//
// Loop while there are more bytes left to be transferred.
//
while(ulCount != 0)
{
//
// Wait until the current byte has been transferred.
//
while(I2CMasterIntStatus(I2C0_MASTER_BASE, false) == 0)
{
}
//
// Provide the required inter-byte delay.
//
OSRAM96x16x1Delay(g_ulDelay);
//
// Write the next byte to the controller.
//
I2CMasterDataPut(I2C0_MASTER_BASE, *pucBuffer++);
ulCount--;
//
// Continue the transfer.
//
I2CMasterControl(I2C0_MASTER_BASE, I2C_MASTER_CMD_BURST_SEND_CONT);
}
}
//*****************************************************************************
//
//! \internal
//!
//! Finish a transfer to the SSD0303 controller.
//!
//! \param ucChar is the final byte to be written to the controller.
//!
//! This function will finish a transfer to the SSD0303 controller via the I2C
//! bus. This must only be called after calling OSRAM96x16x1WriteFirst().
//!
//! The data is written in a polled fashion; this function will not return
//! until the byte has been written to the controller.
//!
//! \return None.
//
//*****************************************************************************
static void
OSRAM96x16x1WriteFinal(unsigned char ucChar)
{
//
// Wait until the current byte has been transferred.
//
while(I2CMasterIntStatus(I2C0_MASTER_BASE, false) == 0)
{
}
//
// Provide the required inter-byte delay.
//
OSRAM96x16x1Delay(g_ulDelay);
//
// Write the final byte to the controller.
//
I2CMasterDataPut(I2C0_MASTER_BASE, ucChar);
//
// Finish the transfer.
//
I2CMasterControl(I2C0_MASTER_BASE, I2C_MASTER_CMD_BURST_SEND_FINISH);
//
// Wait until the final byte has been transferred.
//
while(I2CMasterIntStatus(I2C0_MASTER_BASE, false) == 0)
{
}
//
// Provide the required inter-byte delay.
//
OSRAM96x16x1Delay(g_ulDelay);
}
//*****************************************************************************
//
//! Clears the OLED display.
//!
//! This function will clear the display. All pixels in the display will be
//! turned off.
//!
//! This function is contained in <tt>osram96x16x1.c</tt>, with
//! <tt>osram96x16x1.h</tt> containing the API definition for use by
//! applications.
//!
//! \return None.
//
//*****************************************************************************
void
OSRAM96x16x1Clear(void)
{
static const unsigned char pucRow1[] =
{
0xb0, 0x80, 0x04, 0x80, 0x12, 0x40
};
static const unsigned char pucRow2[] =
{
0xb1, 0x80, 0x04, 0x80, 0x12, 0x40
};
unsigned long ulIdx;
//
// Move the display cursor to the first column of the first row.
//
OSRAM96x16x1WriteFirst(0x80);
OSRAM96x16x1WriteArray(pucRow1, sizeof(pucRow1));
//
// Fill this row with zeros.
//
for(ulIdx = 0; ulIdx < 95; ulIdx++)
{
OSRAM96x16x1WriteByte(0x00);
}
OSRAM96x16x1WriteFinal(0x00);
//
// Move the display cursor to the first column of the second row.
//
OSRAM96x16x1WriteFirst(0x80);
OSRAM96x16x1WriteArray(pucRow2, sizeof(pucRow2));
//
// Fill this row with zeros.
//
for(ulIdx = 0; ulIdx < 95; ulIdx++)
{
OSRAM96x16x1WriteByte(0x00);
}
OSRAM96x16x1WriteFinal(0x00);
}
//*****************************************************************************
//
//! Displays a string on the OLED display.
//!
//! \param pcStr is a pointer to the string to display.
//! \param ulX is the horizontal position to display the string, specified in
//! columns from the left edge of the display.
//! \param ulY is the vertical position to display the string, specified in
//! eight scan line blocks from the top of the display (that is, only 0 and 1
//! are valid).
//!
//! This function will draw a string on the display. Only the ASCII characters
//! between 32 (space) and 126 (tilde) are supported; other characters will
//! result in random data being draw on the display (based on whatever appears
//! before/after the font in memory). The font is mono-spaced, so characters
//! such as ``i'' and ``l'' have more white space around them than characters
//! such as ``m'' or ``w''.
//!
//! If the drawing of the string reaches the right edge of the display, no more
//! characters will be drawn. Therefore, special care is not required to avoid
//! supplying a string that is ``too long'' to display.
//!
//! This function is contained in <tt>osram96x16x1.c</tt>, with
//! <tt>osram96x16x1.h</tt> containing the API definition for use by
//! applications.
//!
//! \return None.
//
//*****************************************************************************
void
OSRAM96x16x1StringDraw(const char *pcStr, unsigned long ulX, unsigned long ulY)
{
//
// Check the arguments.
//
ASSERT(ulX < 96);
ASSERT(ulY < 2);
//
// Move the display cursor to the requested position on the display.
//
OSRAM96x16x1WriteFirst(0x80);
OSRAM96x16x1WriteByte((ulY == 0) ? 0xb0 : 0xb1);
OSRAM96x16x1WriteByte(0x80);
OSRAM96x16x1WriteByte((ulX + 36) & 0x0f);
OSRAM96x16x1WriteByte(0x80);
OSRAM96x16x1WriteByte(0x10 | (((ulX + 36) >> 4) & 0x0f));
OSRAM96x16x1WriteByte(0x40);
//
// Loop while there are more characters in the string.
//
while(*pcStr != 0)
{
//
// See if there is enough space on the display for this entire
// character.
//
if(ulX <= 90)
{
//
// Write the contents of this character to the display.
//
OSRAM96x16x1WriteArray(g_pucFont[*pcStr - ' '], 5);
//
// See if this is the last character to display (either because the
// right edge has been reached or because there are no more
// characters).
//
if((ulX == 90) || (pcStr[1] == 0))
{
//
// Write the final column of the display.
//
OSRAM96x16x1WriteFinal(0x00);
//
// The string has been displayed.
//
return;
}
//
// Write the inter-character padding column.
//
OSRAM96x16x1WriteByte(0x00);
}
else
{
//
// Write the portion of the character that will fit onto the
// display.
//
OSRAM96x16x1WriteArray(g_pucFont[*pcStr - ' '], 95 - ulX);
OSRAM96x16x1WriteFinal(g_pucFont[*pcStr - ' '][95 - ulX]);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -