📄 pdc.c
字号:
//!
//! This function turns off the backlight on the LCD.
//!
//! \return None.
//
//*****************************************************************************
void
PDCLCDBacklightOff(void)
{
PDCWrite(PDC_CSR, 0x00);
}
//*****************************************************************************
//
//! Clear the screen.
//!
//! This function clears the contents of the LCD screen. The cursor will be
//! returned to the upper left corner.
//!
//! \return None.
//
//*****************************************************************************
void
PDCLCDClear(void)
{
//
// Wait until the LCD has finished executing any previous command.
//
while((PDCRead(PDC_LCD_CSR) & LCD_B_BUSY))
{
}
//
// Write the clear display command.
//
PDCWrite(PDC_LCD_CSR, LCD_CLEAR);
}
//*****************************************************************************
//
//! Write a character pattern to the LCD.
//!
//! \param ucChar is the character index to create. Valid values are zero
//! through seven.
//! \param pucData is the data for the character pattern. It contains eight
//! bytes, with the first byte being the top row of the pattern. In each byte,
//! the LSB is the right pixel of the pattern.
//!
//! This function will write a character pattern into the LCD for use as a
//! character to be displayed. After writing the pattern, it can be used on
//! the LCD by writing the corresponding character index to the display.
//!
//! \return None.
//
//*****************************************************************************
void
PDCLCDCreateChar(unsigned char ucChar, unsigned char *pucData)
{
//
// Check the arguments.
//
ASSERT(ucChar < 8);
//
// Wait until the LCD has finished executing any previous command.
//
while((PDCRead(PDC_LCD_CSR) & LCD_B_BUSY))
{
}
//
// Write the character pattern memory address.
//
PDCWrite(PDC_LCD_CSR, LCD_CGADDR + (ucChar * 8));
//
// Write the pattern to chacter pattern memory.
//
for(ucChar = 0; ucChar < 8; ucChar++)
{
//
// Wait until the LCD has finished executing any previous command.
//
while((PDCRead(PDC_LCD_CSR) & LCD_B_BUSY))
{
}
//
// Write this row of the pattern.
//
PDCWrite(PDC_LCD_RAM, *pucData++);
}
}
//*****************************************************************************
//
//! Set the position of the cursor.
//!
//! \param ucX is the horizontal position. Valid values are zero through
//! fifteen.
//! \param ucY is the vertical position.. Valid values are zero and one.
//!
//! This function will move the cursor to the specified position. All
//! characters written to the LCD are placed at the current cursor position,
//! which is automatically advanced.
//!
//! \return None.
//
//*****************************************************************************
void
PDCLCDSetPos(unsigned char ucX, unsigned char ucY)
{
//
// Check the arguments.
//
ASSERT(ucX < 16);
ASSERT(ucY < 2);
//
// Wait until the LCD has finished executing any previous command.
//
while((PDCRead(PDC_LCD_CSR) & LCD_B_BUSY))
{
}
//
// Set the cursor position.
//
PDCWrite(PDC_LCD_CSR, LCD_DDADDR | (0x40 * ucY) + ucX);
}
//*****************************************************************************
//
//! Writes a string to the LCD display.
//!
//! \param pcStr pointer to the string to be displayed.
//! \param ulCount is the number of characters to be displayed.
//!
//! This function will display a string on the LCD at the current cursor
//! position. It is the caller's responsibility to position the cursor to the
//! place where the string should be displayed (either explicitly via
//! PDCLCDSetPos() or implicitly from where the cursor was left after a
//! previous call to PDCLCDWrite()), and to properly account for the LCD
//! boundary (line wrapping is not automatically performed). Null characters
//! are not treated special and are written to the LCD, which interprets it as
//! a special programmable character glyph (see PDCLCDCreateChar()).
//!
//! \return None.
//
//*****************************************************************************
void
PDCLCDWrite(const char *pcStr, unsigned long ulCount)
{
//
// Write the string to the LCD.
//
while(ulCount--)
{
//
// Wait until the LCD has finished executing any previous command.
//
while((PDCRead(PDC_LCD_CSR) & LCD_B_BUSY))
{
}
//
// Write this character to the LCD.
//
PDCWrite(PDC_LCD_RAM, *pcStr++);
}
}
//*****************************************************************************
//
//! Reads a GPIO direction register.
//!
//! \param ucIdx is the index of the GPIO direction register to read; valid
//! values are 0, 1, and 2.
//!
//! This function reads one of the GPIO direction registers in the PDC. The
//! direction bit is set for pins that are outputs and clear for pins that are
//! inputs.
//!
//! \return The contents of the direction register.
//
//*****************************************************************************
unsigned char
PDCGPIODirRead(unsigned char ucIdx)
{
//
// Check the argument.
//
ASSERT((ucIdx == 0) || (ucIdx == 1) || (ucIdx == 2));
//
// Read the requested direction register.
//
if(ucIdx == 0)
{
return(PDCRead(PDC_GPXDIR));
}
else if(ucIdx == 1)
{
return(PDCRead(PDC_GPYDIR));
}
else
{
return(PDCRead(PDC_GPZDIR));
}
}
//*****************************************************************************
//
//! Write a GPIO direction register.
//!
//! \param ucIdx is the index of the GPIO direction register to write; valid
//! values are 0, 1, and 2.
//! \param ucValue is the value to write to the GPIO direction register.
//!
//! This function writes ones of the GPIO direction registers in the PDC. The
//! direction bit should be set for pins that are to be outputs and clear for
//! pins that are to be inputs.
//!
//! \return None.
//
//*****************************************************************************
void
PDCGPIODirWrite(unsigned char ucIdx, unsigned char ucValue)
{
//
// Check the arguments.
//
ASSERT((ucIdx == 0) || (ucIdx == 1) || (ucIdx == 2));
//
// Write the requested direction register.
//
if(ucIdx == 0)
{
PDCWrite(PDC_GPXDIR, ucValue);
}
else if(ucIdx == 1)
{
PDCWrite(PDC_GPYDIR, ucValue);
}
else
{
PDCWrite(PDC_GPZDIR, ucValue);
}
}
//*****************************************************************************
//
//! Reads a GPIO data register.
//!
//! \param ucIdx is the index of the GPIO direction register to read; valid
//! values are 0, 1, and 2.
//!
//! This function reads one of the GPIO data registers in the PDC. The value
//! returned for a pin is the value being driven out for outputs or the value
//! being read for inputs.
//!
//! \return The contents of the data register.
//
//*****************************************************************************
unsigned char
PDCGPIORead(unsigned char ucIdx)
{
//
// Check the argument.
//
ASSERT((ucIdx == 0) || (ucIdx == 1) || (ucIdx == 2));
//
// Read the requested data register.
//
if(ucIdx == 0)
{
return(PDCRead(PDC_GPXDAT));
}
else if(ucIdx == 1)
{
return(PDCRead(PDC_GPYDAT));
}
else
{
return(PDCRead(PDC_GPZDAT));
}
}
//*****************************************************************************
//
//! Write a GPIO data register.
//!
//! \param ucIdx is the index of the GPIO data register to write; valid values
//! are 0, 1, and 2.
//! \param ucValue is the value to write to the GPIO data register.
//!
//! This function writes one of the GPIO direction registers in the PDC. The
//! written to a pin is driven out for output pins and ignored for input pins.
//!
//! \return None.
//
//*****************************************************************************
void
PDCGPIOWrite(unsigned char ucIdx, unsigned char ucValue)
{
//
// Check the arguments.
//
ASSERT((ucIdx == 0) || (ucIdx == 1) || (ucIdx == 2));
//
// Write the requested data register.
//
if(ucIdx == 0)
{
PDCWrite(PDC_GPXDAT, ucValue);
}
else if(ucIdx == 1)
{
PDCWrite(PDC_GPYDAT, ucValue);
}
else
{
PDCWrite(PDC_GPZDAT, ucValue);
}
}
//*****************************************************************************
//
// Close the Doxygen group.
//! @}
//
//*****************************************************************************
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -