📄 lcdd.txt
字号:
*
* @param Address The target pointer location in the LCD.
*
* @return none
*************************************************************************/
void halLcdSetAddress(int Address)
{
int temp;
Draw_Block_Address_Macro[4] = Address >> 8;
Draw_Block_Address_Macro[5] = Address & 0xFF;
halLcdSendCommand(Draw_Block_Address_Macro);
LcdAddress = Address;
temp = Address >> 5; // Divided by 0x20
temp = temp + (temp << 4);
//Multiplied by (1+16) and added by the offset
LcdTableAddress = temp + (Address & 0x1F);
}
/**********************************************************************//**
* @brief Draws a block at the specified LCD address.
*
* A block is the smallest addressable memory on the LCD and is
* equivalent to 8 pixels, each of which is represented by 2 bits
* that represent a grayscale value between 00b and 11b.
*
* @param Address The address at which to draw the block.
*
* @param Value The value of the block
*
* @return none
*************************************************************************/
void halLcdDrawBlock(unsigned int Address, unsigned int Value)
{
halLcdSetAddress(Address);
halLcdDrawCurrentBlock(Value);
}
/**********************************************************************//**
* @brief Writes Value to LCD CGram and MSP430 internal LCD table.
*
* Also updates the LcdAddress and LcdTableAddress to the correct values.
*
* @param Value The value of the block to be written to the LCD.
*
* @return none
*************************************************************************/
void halLcdDrawCurrentBlock(unsigned int Value)
{
int temp;
Draw_Block_Value_Macro[4] = Value >> 8;
Draw_Block_Value_Macro[5] = Value & 0xFF;
LCD_MEM[ LcdTableAddress ] = Value;
halLcdSendCommand(Draw_Block_Value_Macro);
LcdAddress++;
temp = LcdAddress >> 5; // Divided by 0x20
temp = temp + (temp << 4);
// Multiplied by (1+16) and added by the offset
LcdTableAddress = temp + (LcdAddress & 0x1F);
// If LcdAddress gets off the right edge, move to next line
if ((LcdAddress & 0x1F) > 0x11)
halLcdSetAddress( (LcdAddress & 0xFFE0) + 0x20 );
if (LcdAddress == LCD_Size)
halLcdSetAddress( 0 );
}
/**********************************************************************//**
* @brief Returns the LCD CGRAM value at location Address.
*
* @param Address The address of the block to be read from the LCD.
*
* @return Value The value held at the specified address.
*************************************************************************/
int halLcdReadBlock(unsigned int Address)
{
int i = 0, Value = 0, ReadData[7];
halLcdSetAddress( Address );
halLcdSendCommand(Read_Block_Address_Macro);
LCD_COMM_OUT &= ~LCD_CS_PIN; // start transfer CS=0
UCB2TXBUF = 0x77; // Transmit first character 0x75
while (!(UCB2IFG & UCTXIFG));
while (UCB2STAT & UCBUSY);
//Read 5 dummies values and 2 valid address data
P9SEL &= ~BIT1; //Change SPI2C Dir
P9SEL |= BIT2;
for (i = 0; i < 7; i ++ )
{
P4OUT |= BIT2;
P4OUT &= ~BIT2;
UCA0IFG &= ~UCRXIFG;
UCA0TXBUF = 1; // load dummy byte 1 for clk
while (!(UCA0IFG & UCRXIFG));
ReadData[i] = UCA0RXBUF;
}
LCD_COMM_OUT |= LCD_CS_PIN; // Stop Transfer CS = 1
P9SEL |= BIT1; //Change SPI2C Dir
P9SEL &= ~BIT2;
Value = (ReadData[5] << 8) + ReadData[6];
return Value;
}
/**********************************************************************//**
* @brief Draw a Pixel of grayscale at coordinate (x,y) to LCD
*
* @param x x-coordinate for grayscale value
*
* @param y y-coordinate for grayscale value
*
* @param GrayScale The intended grayscale value of the pixel - one of
* four possible settings.
*
* @return none
*************************************************************************/
void halLcdPixel( int x, int y, unsigned char GrayScale)
{
int Address, Value;
unsigned char offset;
//Each line increments by 0x20
if ( (x>=0 ) && (x<LCD_COL) && (y>=0) && (y<LCD_ROW))
{
Address = (y << 5) + (x >> 3) ; //Narrow down to 8 possible pixels
offset = x & 0x07; //3 LSBs = pos. within the 8 columns
Value = LCD_MEM[(y << 4)+ y + (x>>3)]; //y * 17 --> row. x>>3 --> column
switch(GrayScale)
{
case PIXEL_OFF:
Value &= ~ ( 3 << (offset * 2 )); //Both corresponding bits are off
break;
case PIXEL_LIGHT:
Value &= ~ ( 1 << ((offset * 2) + 1));
Value |= 1<< ( offset * 2 ); //Lower bit is on
break;
case PIXEL_DARK:
Value &= ~ ( 1 << (offset * 2) ); //Lower bit is on
Value |= ( 1 << ( (offset * 2) + 1));
break;
case PIXEL_ON:
Value |= ( 3 << (offset * 2 )); //Both on
break;
}
halLcdDrawBlock( Address, Value );
}
}
/**********************************************************************//**
* @brief Clears entire LCD CGRAM as well as LCD_MEM.
*
* @param none
*
* @return none
*************************************************************************/
void halLcdClearScreen(void)
{
int i;
halLcdSetAddress(0);
// Clear the entire LCD CGRAM
for ( i = 0; i < LCD_Size; i++)
halLcdDrawCurrentBlock(0x00);
halLcdSetAddress(0); // Reset LCD address
}
/**********************************************************************//**
* @brief Loads an image of size = rows * columns, starting at the
* coordinate (x,y).
*
* @param Image[] The image to be loaded
*
* @param Rows The number of rows in the image. Size = Rows * Columns.
*
* @param Columns The number of columns in the image. Size = Rows * Columns.
*
* @param x x-coordinate of the image's starting location
*
* @param y y-coordinate of the image's starting location
*
* @return none
*************************************************************************/
void halLcdImage(const unsigned int Image[], int Columns, int Rows, int x, int y)
{
int i,j, CurrentLocation, index=0 ;
CurrentLocation = (y << 5) + (x >> 3);
halLcdSetAddress( CurrentLocation );
for (i=0; i < Rows; i++)
{
for (j=0; j < Columns; j++)
halLcdDrawCurrentBlock(Image[index++]);
CurrentLocation += 0x20;
halLcdSetAddress(CurrentLocation );
}
}
/**********************************************************************//**
* @brief Clears an image of size rows x columns starting at (x, y).
*
* @param Columns The size, in columns, of the image to be cleared.
*
* @param Rows The size, in rows, of the image to be cleared.
*
* @param x x-coordinate of the image to be cleared
*
* @param y y-coordinate of the image to be cleared
*
* @return none
*************************************************************************/
void halLcdClearImage(int Columns, int Rows, int x, int y)
{
int i,j, Current_Location;
Current_Location = (y << 5) + (x >> 3);
halLcdSetAddress( Current_Location );
for (i=0; i < Rows; i++)
{
for (j=0; j < Columns; j++)
halLcdDrawCurrentBlock(0);
Current_Location += 0x20;
halLcdSetAddress(Current_Location );
}
}
/**********************************************************************//**
* @brief Writes Value to LCD CGRAM. Pointers internal to the LCD
* are also updated.
*
* @param Value The value to be written to the current LCD pointer
*
* @return none
*************************************************************************/
void halLcdDrawTextBlock(unsigned int Value)
{
int temp;
Draw_Block_Value_Macro[4] = Value >> 8;
Draw_Block_Value_Macro[5] = Value & 0xFF;
LCD_MEM[ LcdTableAddress ] = Value;
halLcdSendCommand(Draw_Block_Value_Macro);
LcdAddress++;
temp = LcdAddress >> 5; // Divided by 0x20
temp = temp + (temp << 4);
//Multiplied by (1+16) and added by the offset
LcdTableAddress = temp + (LcdAddress & 0x1F);
// If LcdAddress gets off the right edge, move to next line
if ((LcdAddress & 0x1F) > 0x10)
halLcdSetAddress( (LcdAddress & 0xFFE0) + 0x20 );
if (LcdAddress >= LCD_Size)
halLcdSetAddress( 0 );
}
/**********************************************************************//**
* @brief Displays the string to the LCD starting at current location.
*
* Writes all the data to LCD_MEM first, then updates all corresponding
* LCD CGRAM locations at once, in a continuous fashion.
*
* @param String[] The string to be displayed on LCD.
*
* @param TextStyle Value that specifies whether the string is to be
* inverted or overwritten.
* - Invert = 0x01
* - Overwrite = 0x04
*
* @return none
*************************************************************************/
void halLcdPrint( char String[], unsigned char TextStyle)
{
int i, j, Counter=0, BlockValue;
int Address, LCD_MEM_Add, ActualAddress;
int temp;
char LookUpChar;
ActualAddress = LcdAddress;
Counter = LcdAddress & 0x1F;
i=0;
while (String[i]!=0) // Stop on null character
{
LookUpChar = fonts_lookup[String[i]];
for (j=0;j < FONT_HEIGHT ;j++)
{
Address = ActualAddress + j*0x20;
temp = Address >> 5;
temp += (temp <<4);
LCD_MEM_Add = temp + (Address & 0x1F);
BlockValue = LCD_MEM[ LCD_MEM_Add ];
if (TextStyle & INVERT_TEXT)
if (TextStyle & OVERWRITE_TEXT)
BlockValue = 0xFFFF - fonts[LookUpChar*13+j];
else
BlockValue |= 0xFFFF - fonts[LookUpChar*13+j];
else
if (TextStyle & OVERWRITE_TEXT)
BlockValue = fonts[LookUpChar*(FONT_HEIGHT+1) +j];
else
BlockValue |= fonts[LookUpChar*(FONT_HEIGHT+1) +j];
halLcdDrawBlock( Address, BlockValue);
}
Counter++;
if (Counter == 17)
{
Counter = 0;
ActualAddress += 0x20*FONT_HEIGHT - 16;
if (ActualAddress > LCD_Last_Pixel-0x20*FONT_HEIGHT )
ActualAddress = 0;
}
else
ActualAddress++;
i++;
}
halLcdSetAddress(ActualAddress);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -