📄 test44x_lcd02.c
字号:
#include "msp430x44x.h"
// variable declaration //
unsigned int value = 1789; // number to display, range = 0 - 1999 = max display
// NOTE: DO NOT use leading zeros
unsigned int h;
unsigned int i;
unsigned int dig_pntr;
char *LCD = LCDMEM;
// array declaration //
char digit[40] = {
0x11, 0x11, // "0" LCD segments a+b & c+d = lower two bytes
0x11, 0x00, // "0" LCD segments e+f & g+h = upper two bytes
0x10, 0x01, // "1"
0x00, 0x00, // "1"
0x11, 0x10, // "2"
0x01, 0x01, // "2"
0x11, 0x11, // "3"
0x00, 0x01, // "3"
0x10, 0x01, // "4"
0x10, 0x01, // "4"
0x01, 0x11, // "5"
0x10, 0x01, // "5"
0x01, 0x11, // "6"
0x11, 0x01, // "6"
0x11, 0x01, // "7"
0x00, 0x00, // "7"
0x11, 0x11, // "8"
0x11, 0x01, // "8"
0x11, 0x11, // "9"
0x10, 0x01, // "9"
};
void main(void)
{
WDTCTL = WDTPW + WDTHOLD; // stop watchdog timer
FLL_CTL0 = XCAP18PF; // set load capacitance for 32k xtal
// initialize LCD driver (static mode) //
LCDCTL = 0x65; //static LCD, segments = 0 - 23
BTCTL = BTFRFQ1+BTFRFQ0; // BTCTL ;set fLCD = ACLK / 256 BTFRFQ1
// set up ports //
P1DIR = 0xFF; // set port to outputs
P2DIR = 0xFF; // set port to outputs
P3DIR = 0xFF; // set port to outputs
P4DIR = 0xFF; // set port to outputs
P5DIR = 0xFF; // set port to outputs
P6DIR = 0xFF; // set port to outputs
// clear LCD memory to clear display //
for (i=0; i<20; i++)
{
LCD[i] = 0;
}
// display lower 3 digits //
for (h=0; h<3; h++) // loops to move 3 digits to LCD
{
dig_pntr = 4*(value%10); // set pointer to start of digit in table
for (i=0; i<4; i++) // loops to load 4 bytes of digit
{
LCD[i] = digit[dig_pntr++]; // byte of digit to byte of LCD memory
} // and increment to next byte of digit
value /= 10; // shifts value right to display next character
LCD += 4; // increment by 4 for next character location
}
// test for leading 1 and display if present //
if (value == 1)
{
LCDM12 |= 0x10; // set bit = leading 1
}
LPM3; // enter low power mode 3
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -