📄 lcd.cpp
字号:
#include "Lcd.h"
#include "LcdDefines.h"
#include "msp430x44x.h"
bool Lcd::firstTime = true;
Lcd::Lcd()
{
Init();
}
Lcd::Lcd( char* string, bool uppercase, bool flush )
{
Init();
for(int i = 0; string[i] != '\0'; ++i )
{
PutChar( string[i], uppercase, flush );
}
}
void
Lcd::Init()
{
//
mPos = 0;
// Initialize LCD driver (4Mux mode)
LCDCTL = LCDON + LCD4MUX + LCDSG0_7;
BTCTL = BTFRFQ1; // set LCD frame freq = ACLK
P5SEL = 0xFC; // set Rxx and COM pins for LCD
FLL_CTL0 = XCAP18PF; // set load capacitance for 32k xtal
if( firstTime )
{
// used to access the LCDMx as an array
char *LCD = LCDMEM;
// clear LCD memory to clear display
for( int i=0; i<20; ++i )
{
LCD[i] = 0x00;
}
firstTime = false;
}
}
int
Lcd::PutChar( char c, bool uppercase, bool flush )
{
// make sure we don't get outside the defined range
if( c < FIRST_CHAR || c > LAST_CHAR )
c = 0;
// default we only use upper case
// since this is easier to read
if( uppercase )
{
if( c >= 'a' && c <= 'z')
c -= 'a' - 'A';
}
// inc. the buffer pointer
mPos++;
// buffer can only contain 255 characters
if( mPos > 0xFF )
{
// light '+' to indicate overload
Plus();
return kLcdError;
}
// copy character into buffer
mBuffer[mPos] = c;
// are we to update the display?
if( flush )
{
UpdateDisplay(2000);
}
return kLcdOk;
}
void
Lcd::UpdateDisplay( long delay )
{
char *LCD = LCDMEM;
// loop from left to right and display character in mBuffer
for( int i = 0; i < 7*2; i += 2 )
{
int pos = mPos - 6 + i/2;
short c = pos <= 0 ? 0 : table14seg[mBuffer[pos] - FIRST_CHAR];
LCD[19 - i - 1] = c & 0x00FF;
LCD[19 - i] = (c >> 8) & 0x00FF;
// simple delay so that we can see what is happening
for(int i = 0; i<delay; ++i);
}
}
void
Lcd::SegmentControl( unsigned char LCDMx, unsigned char regValue, bool on )
{
// compensate the index since LCDM1
// have the index 0 in the "array"
LCDMx--;
if( on )
((char*)LCDMEM)[LCDMx] |= regValue;
else
((char*)LCDMEM)[LCDMx] &= ~regValue;
}
void
Lcd::SevenSeg( int left, int right, bool colon )
{
unsigned char dig1;
unsigned char dig2;
unsigned char dig3;
unsigned char dig4;
dig2 = right / 10;
dig1 = right - (dig2 * 10);
dig4 = left / 10;
dig3 = left - (dig4 * 10);
((char*)LCDMEM)[2] = right7seg[dig1];
((char*)LCDMEM)[3] = right7seg[dig2];
((char*)LCDMEM)[4] = left7seg[dig3];
((char*)LCDMEM)[5] = left7seg[dig4];
if( colon )
SegmentControl( 4, 0x80, true );
}
void
Lcd::Clear7Seg( void )
{
Clear( 2, 5 );
}
void
Lcd::Clear14Seg( void )
{
Clear( 6, 19 );
}
void
Lcd::Clear( int No )
{
Clear( No, No );
}
void
Lcd::Clear( int first, int last )
{
for(int i= first; i <= last; ++i )
((char*)LCDMEM)[i] = 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -