⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 msl90.c

📁 国外的一个关于msp430f449开源项目资料之二---源代码
💻 C
📖 第 1 页 / 共 2 页
字号:
/* MSL90: MSP430F449 LCD Driver Code for MSP-449STK-2 Starter Kit from Olimex.com
 -----------------------------------------------------------------------------------------------------------------------
* Author Details   :  Muneem Shahriar
                      Electrical Engineering & Mathematics (Senior)
                      Texas Tech University, Lubbock, TX, USA
                      Email: muneem.shahriar@ttu.edu

* Last Updated      : July 22,2004 
        
* Software:
           Version  : 2.0
           ID       : MSL90
           License  : Freeware 
           Features : Has functions that allows the user to:
                      (a) Display integers numbers on LCD
                      (b) Display decimal numbers on LCD (in string form)
                      (c) Display words (upto 7 characters) on LCD
                      (d) Display sentences on LCD by making them scroll right to left
                      (e) Can also display battery life and arrows on LCD

* ---------------------------------------------------------------------------------------------------------------------

* Software requirements:
  1. Microsoft Windows (tested on XP). Website: http://www.microsoft.com
  2. IAR Embedded Workbench (Regular, not Professional). This has the C compiler 
     and C-spy debugger to get the code all running. Make sure you select MSP430F449 
     in the chip description under Project>>Options>>C-spy
     Website: http://www.iar.com

* Hardware Requirements:
  1. MSP-449STK-2 Starter Kit. This kit can be purchased from http://www.sparkfun.com 
     This kit basically comes with a Olimex LCD built-in the kit. Sadly, no software was available
     when I purchased it, so I wrote this file as a driver program.
     
* Disclaimer:
  This code is specific to the MSP-449STK-2 Starter Kit. I CANNOT be held 
  responsible if the code below is tested on other standard kits. If the code
  below is not working on MSP-449STK-2, contact me. All my codes are tested thoroughly.
  
  Have a starter kit different from MSP-449STK-2 and using Olimex LCD? Let me know!
  
--------------------------------------------------------------------------------------------------------------------*/
  
#include "msp430x44x.h"      // Chip definitions for msp430F449
#include "string.h"          // for some string functions

//******************************************** GLOBAL VARIABLES******************************************************
char *LCD = LCDMEM;          // pointer to LCD Memory Segments. Pretty cool, got this idea from TI-website

//******************************************** LCD CONSTANTS ********************************************************
#define     a      (0x80)    // definitions for LCD seegments on the Olimex LCD. 4-Mux operation is assumed
#define     b      (0x40)    // For more details on 4-Mux operation, gather your LCD datasheet, 
#define     c      (0x20)    // TI's MSP430F449 User Guide (look for LCD Controller, then 4-Mux),
#define     d      (0x01)    // and MSP-449STK-2 schematic. You will need ALL these 3 when defining
#define     e      (0x02)    // each number or character. Remember, the Olimex LCD doesn't use a LCD driver!
#define     f      (0x08)    // You tell the LCD what characters to display. It's very time consuming!!
#define     g      (0x04)
#define     h      (0x10)
// ***************************************** FUNCTION DECLARATIONS **************************************************
void clearLCD(void);                            // Clears LCD memory segments so that LCD is blank
void initLCD(void);                             // Setup code to interface LCD with MSP430F449
void shortDelay(int dSpeed);                    // Loop Delay for a reasonable time. Adjustable delay.
void writeLetter(int position,char letter);     // displays a single character on the LCD
void writeWord(const char *word, int repeat_times); // displays words upto 7 characters on LCD. Can also
                                                    // display decimal numbers passed as text
void writeNumber(int long number);                  // displays integer numbers on the LCD
// void writeSentence(const char *word, int scrollForever);   // enable this function if you want to display complete
                                                              // sentences only. The sentences will scroll from right to
                                                              // left


// ***************************************** MAIN FUNCTION ************************************************************
void main(void)
{
    unsigned int position = 0;  // position refers to the location where a digit will be displayed
    unsigned int digit = 0;     // a digit as in 5, as in 4 etc
    unsigned int i = 0;
 
    WDTCTL = WDTPW + WDTHOLD;   // Stop watchdog timer  (better stop this fellow!)
    initLCD();                  // Setup LCD for work
    clearLCD();                 // Clear LCD display
    shortDelay(2);              // you can remove this delay if you want
    P1DIR |= 0x08;              // Set P1.3 to output direction to run LED

    // LCD Test Code Goes Here -----------------
    
    // See Turorial on bottom of this file on how to use the LCD properly
    
         for (i = 1; i<=2;i++) {  // repeats words two times
         writeWord("SYSTEM ",1);  // show this word once
         writeWord("READY. ",1);}  // show this word once also
    
    // -----------------------------------------
  
   LPM3;                       // enter low power mode 3 
}

// ************************************************ numberScroll ******************************************************
void writeNumber(int long number)   // A cool function that moves number right to left
{
   unsigned int i;                     // dummy variable
   unsigned int digit;                 // dummy digit       
   char Letter;
   unsigned int numLen = 0;            // length of number provided by user
   
   clearLCD();
   
   for (i=1; i<=9; i++)                // Extract each digit in number, put in an integer array, and count total length also
   {
      digit = number%10;               // digit = the least significant character obtained from number for display
      number = number/10;              // remove the least significant character from number
      
      switch(digit)                    // pass on the right char value to writeLetter function
      {   
          case 0:  Letter = '0'; writeLetter(i,Letter); break;
          case 1:  Letter = '1'; writeLetter(i,Letter); break;
          case 2:  Letter = '2'; writeLetter(i,Letter); break;
          case 3:  Letter = '3'; writeLetter(i,Letter); break;
          case 4:  Letter = '4'; writeLetter(i,Letter); break;
          case 5:  Letter = '5'; writeLetter(i,Letter); break;
          case 6:  Letter = '6'; writeLetter(i,Letter); break;
          case 7:  Letter = '7'; writeLetter(i,Letter); break;
          case 8:  Letter = '0'; writeLetter(i,Letter); break;
          case 9:  Letter = '0'; writeLetter(i,Letter); break;
      }
      
      if (number == 0)                 // when the number has finally been reduced to zero
          break;                       // break so that LCD doesn't diplay leading zeroes. E.g 234 instead of 0000234
   } 
   shortDelay(2);                      // remove this delay if you update numbers regularly
}
// ************************************************ shortDelay ****************************************************
void shortDelay(int dSpeed)  // a very easy to code delay which keeps the processor busy for a small duration of time
{    
     unsigned int iDelay = 0;          
     unsigned int kDelay = 0;
     for (kDelay = 1;kDelay < dSpeed * 5 ;kDelay++)   // kDelay value can be changed from 10 - 50
     {    
       iDelay = 80000;                      // Do not make iDelay more than 90000. Change kDelay instead
       do (iDelay--);
       while (iDelay != 0);
     }
}        

// ************************************************ initLCD ********************************************************
void initLCD(void)   // initialize the various registers for LCD to work (code obtained from sample demos of MSP430F449)
{
    FLL_CTL0 = XCAP18PF;                 //set load capacitance for 32k xtal
    // Initialize LCD driver (4Mux mode) 
    LCDCTL = LCDSG0_7 + LCD4MUX + LCDON; // 4mux LCD, segs16-23 = outputs
    BTCTL  = BT_fLCD_DIV128;             // set LCD frame freq = ACLK
    P5SEL  = 0xFC;                       // set Rxx and COM pins for LCD
}  

// ************************************************ clearLCD ********************************************************
void clearLCD(void) // makes the LCD blank
{   // clear LCD memory to clear display
    unsigned int iLCD;
    for (iLCD =0; iLCD<20; iLCD++)  // clears all 20 LCD memory segments
    {
      LCD[iLCD] = 0;
    } 
}  

// **********************************************  writeLetter ******************************************************** 
void writeLetter(int position,char letter) // writes a single character on the LCD. User can specify position as well
{
    // DO NOT PLAY WITH THE CODE BELOW ------------------------------------------------------------------------------
    if (position == 1)  {  position = position + 6; } // this is position adjustment for compatibility.
    else if (position == 2 || position == 3 || position == 4 || position == 5 || position == 6 || position == 7)
    {  position = ((position * 2) - 1) + 6; }  // adjust position
    // --------------------------------------------------------------------------------------------------------------

    switch(letter)                                  
    {
       // letter  // LCDM7                           // LCDM8                          // End
       case 'A':  LCD[position-1] = a + b + c + e;      LCD[position] = b + c + g;        break;                                                                        
       case 'B':  LCD[position-1] = c + h + e;          LCD[position] = b + c + g;        break;  
       case 'C':  LCD[position-1] = a + h;              LCD[position] = b + c;            break;  
       case 'D':  LCD[position-1] = b + c + h + e;      LCD[position] = c + g;            break;     
       case 'E':  LCD[position-1] = a + h + e;          LCD[position] = b + c + g;        break;  
       case 'F':  LCD[position-1] = a;                  LCD[position] = b + c + g;        break;  
       case 'G':  LCD[position-1] = a + c + h + e;      LCD[position] = b + c;            break; 
       case 'H':  LCD[position-1] = b + c + e;          LCD[position] = b + c + g;        break;  
       case 'I':  LCD[position-1] = a + h + f;          LCD[position] = d;                break;  
       case 'J':  LCD[position-1] = b + h + c;          LCD[position] = c;                break;  
       case 'K':  LCD[position-1] = d + g;              LCD[position] = b + c + g;        break;  
       case 'L':  LCD[position-1] = h;                  LCD[position] = b + c ;           break;    
       case 'M':  LCD[position-1] = b + c + g;          LCD[position] = b + c + f;        break;    
       case 'N':  LCD[position-1] = b + c + d;          LCD[position] = b + c + f;        break;
       case 'O':  LCD[position-1] = a + b + c + h;      LCD[position] = b + c;            break;
       case 'P':  LCD[position-1] = a + b + e;          LCD[position] = b + c + g;        break;
       case 'Q':  LCD[position-1] = a + b + c + h + d;  LCD[position] = b + c;            break;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -