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

📄 lcd.c

📁 MSP acquires data and sends through USB to PC. Check the link for PC capture software and project d
💻 C
📖 第 1 页 / 共 2 页
字号:
/*
 * File:        lcd.c
 * Purpose:     Nokia 6610 LCD handling functions
 * Author:      Peter Ivanov, Olimex Ltd.
 * Modified by:
 * Created:     2007-05-19 11:29:32
 * Last modify: 2007-10-21 10:37:53 ivanovp {Time-stamp}
 * Copyright:   (C) Peter Ivanov, Olimex Ltd., 2007
 * Licence:     GPL
 */
/**
 * \file lcd.c
 * \brief Nokia 6610 LCD handling functions
 * \author Peter Ivanov, Olimex Ltd.
 */
//#include <msp430x44x.h>
#include <msp430xG461x.h>
#include <stdio.h>
#include <signal.h>
#include <string.h>
#include "lcd.h"
#include "ball.h"
#include "bits.h"
#include "font.h"
#include "time.h"

#define LCD_RESET_LOW()     P7OUT &= ~BIT4;
#define LCD_RESET_HIGH()    P7OUT |= BIT4;

// Chip Select: P4.2
#define CS_LOW()            P4OUT &= ~BIT2;
#define CS_HIGH()           P4OUT |= BIT2;    

static uint8_t xBase = 0;
static uint8_t x = 0;
static uint8_t y = 0;
static uint16_t fgColor = LCD_DEFAULT_FG_COLOR;
static uint16_t bgColor = LCD_DEFAULT_BG_COLOR;

void LCD_writeSpiCommand (unsigned char data);
void LCD_writeSpiData (unsigned char data);
void LCD_setup (void);

void LCD_init (void) 
{
    // USART1 initialization for SPI communications //

    U1CTL |= SWRST; // Enable software reset P-I-

    // Enable USART0 SPI mode
    U1ME |= USPIE1;
    
    U1CTL &= ~SWRST; // Disable software reset P-I-

    /* USART Control Register */
    // 8-bit, SPI Master
    U1CTL = CHAR + SYNC + MM;

    /* USART Transmit Control Register */
    // Select SMCLK and 3-pin SPI select, Clock Polarity
    U1TCTL = SSEL_SMCLK + STC + CKPL;

    /* USART Baud Rate Control Register 0 and 1 */
    // Set BaudRate - no divider
    U1BR0   = 0x02;
    U1BR1   = 0x00;

    /* USART Modulation Control Register */
    U1MCTL  = 0x00;

    // Setup P4 for SPI1 operation
    P4SEL |= (BIT3 | BIT5); // P4.3 and P4.5 SPI option select

    P4SEL &= ~(BIT4);       // P4.2 as GPIO
    P4OUT |= BIT2;          // CS high
    P4DIR |= BIT2;          // P4.2 output direction

    // Reset Pin
    P7SEL &= ~BIT4;         // P7.4 as GPIO
    P7OUT |= BIT4;          // reset high
    P7DIR |= BIT4;          // P7.4 output direction

    LCD_setup ();
}

void LCD_writeSpiCommand (unsigned char data)
{
    // Software clock for first bit (must be high)
    P4SEL &= ~(BIT3 + BIT5);    // P4.3 and P4.5 as GPIO
    P4OUT |= BIT5;              // P4.5  -> HIGH
    P4OUT &= ~BIT3;             // P4.3  -> LOW
    P4DIR |= BIT3 + BIT5;       // P4.3 and P4.5 -> OUTPUT

    // CS Low
    CS_LOW ();

    P4OUT &= ~BIT5;             // P4.5 -> LOW
    P4OUT |= BIT5;              // P4.5 -> HIGH

    P4SEL |= BIT3 + BIT5;       // P4.3 and P4.5 SPI option select

    // Write byte
    //TXBUF1 = data;
    U1TXBUF = data;

    // wait to send data
    while ((U1TCTL & TXEPT) == 0);

    // CS High
    // CS_HIGH ();
}

void LCD_writeSpiData (unsigned char data)
{
    // Software clock for first bit (must be high)
    P4SEL &= ~ (BIT3 + BIT5);    // P4.3 and P4.5 as GPIO
    P4OUT |= BIT3 + BIT5;       // P4.3 and P4.5  -> HIGH
    P4DIR |= BIT3 + BIT5;       // P4.3 and P4.5 -> OUTPUT

    // CS Low
    CS_LOW ();

    P4OUT &= ~BIT5;             // P4.5 -> LOW
    P4OUT |= BIT5;              // P4.5 -> HIGH

    P4SEL |= BIT3 + BIT5;       // P4.3 and P4.5 SPI option select

    // Write byte
    //TXBUF1 = data;
    U1TXBUF = data;

    // wait to send data
    while ((U1TCTL & TXEPT) == 0);    

    // CS High
    // CS_HIGH ();
}

void LCD_setBacklight (unsigned char state) 
{
    if (!state)
    {
        P7OUT |= BIT6;    //Turn on light
    }
    else
    {
        P7OUT &= ~BIT6;    //Turn off light
    }
}

void LCD_setContrast (unsigned char contrast) 
{
#ifdef GE12
    LCD_writeSpiCommand (CONTRAST);
    LCD_writeSpiData (0x20 + contrast);    // contrast
#endif
}

void LCD_setup (void) 
{
#ifdef GE12
    /*
     * LCD type: GE12
     */
    ///// Initialization start /////

    // 2. Software Reset
    LCD_writeSpiCommand (SOFTRST);
    DelayS (2000);

    // 3. Initial escape
    LCD_writeSpiCommand (INITESC);
    DelayS (2000);

    ///// Initialization end /////

    ///// Display setting 1 /////

    // 1. Refresh set
    LCD_writeSpiCommand (REFSET);
    LCD_writeSpiData (0);

    // 2. Display control - 7 parameters
    LCD_writeSpiCommand (DISPCTRL);
    LCD_writeSpiData (128);  // Set the lenght of one selection term
    LCD_writeSpiData (128);  // Set N inversion -> no N inversion
    LCD_writeSpiData (134);  // Set frame frequence and bias rate -> 2 devision of frequency and 1/8 bias, 1/67 duty, 96x67 size
    LCD_writeSpiData (84);   // Set duty parameter
    LCD_writeSpiData (69);   // Set duty parameter
    LCD_writeSpiData (82);   // Set duty parameter
    LCD_writeSpiData (67);   // Set duty parameter


    // 3.1 Grey scale 0 position set - 15 parameters
    LCD_writeSpiCommand (GRAYSCALE0);
    LCD_writeSpiData (1);    // GCP1 - gray level to be output when the RAM data is "0001"
    LCD_writeSpiData (2);    // GCP2 - gray level to be output when the RAM data is "0010"
    LCD_writeSpiData (4);    // GCP3 - gray level to be output when the RAM data is "0011"
    LCD_writeSpiData (8);    // GCP4 - gray level to be output when the RAM data is "0100"
    LCD_writeSpiData (16);   // GCP5 - gray level to be output when the RAM data is "0101"
    LCD_writeSpiData (30);   // GCP6 - gray level to be output when the RAM data is "0110"
    LCD_writeSpiData (40);   // GCP7 - gray level to be output when the RAM data is "0111"
    LCD_writeSpiData (50);   // GCP8 - gray level to be output when the RAM data is "1000"
    LCD_writeSpiData (60);   // GCP9 - gray level to be output when the RAM data is "1001"
    LCD_writeSpiData (70);   // GCP10 - gray level to be output when the RAM data is "1010"
    LCD_writeSpiData (80);   // GCP11 - gray level to be output when the RAM data is "1011"
    LCD_writeSpiData (90);   // GCP12 - gray level to be output when the RAM data is "1100"
    LCD_writeSpiData (100);  // GCP13 - gray level to be output when the RAM data is "1101"
    LCD_writeSpiData (110);  // GCP14 - gray level to be output when the RAM data is "1110"
    LCD_writeSpiData (127);  // GCP15 - gray level to be output when the RAM data is "1111"

    // 4. Gamma curve set - select gray scale - GRAYSCALE 0 or GREYSCALE 1
    LCD_writeSpiCommand (GAMMA);
    LCD_writeSpiData (1);     // Select grey scale 0


    // 5. Command driver output
    LCD_writeSpiCommand (COMMONDRV);
    LCD_writeSpiData (0);     // Set COM1-COM41 side come first, normal mod


    // 6. Set Normal mode (my)
    LCD_writeSpiCommand (NORMALMODE);

    // 7. Inversion off
    //LCD_writeSpiCommand (INVERSIONOFF);

    // 8. Column address set
    //LCD_writeSpiCommand (COLADDRSET);
    //LCD_writeSpiData (0);
    //LCD_writeSpiData (130);
    //LCD_writeSpiData (0);

    // 9. Page address set
    //LCD_writeSpiCommand (PAGEADDRSET);
    //LCD_writeSpiData (0);
    //LCD_writeSpiData (130);
    //LCD_writeSpiData (0);

    // 10. Memory access controler
    LCD_writeSpiCommand (ACCESSCTRL);
    LCD_writeSpiData (0x40);     // horizontal
    //LCD_writeSpiData (0x20);   // vertical

    ///// Display setting 1 end  /////


    ///// Power supply  ///////

    // 1. Power control
    LCD_writeSpiCommand (PWRCTRL);
    LCD_writeSpiData (4);     // Internal resistance, V1OUT -> high power mode, oscilator devision rate
    // LCD_writeSpiData (0x44);     // Internal resistance, V1OUT -> high power mode, oscilator devision rate

    // 2. Sleep out
    LCD_writeSpiCommand (SLEEPOUT);


    // 3. Voltage control - voltage control and write contrast define LCD electronic volume
    LCD_writeSpiCommand (VOLTCTRL);
    //LCD_writeSpiData (0x7f);    //  full voltage control
    //LCD_writeSpiData (0x03);    //  must be "1"

    // 4. Write contrast
    LCD_writeSpiCommand (CONTRAST);
    LCD_writeSpiData (0x30);    // contrast

    DelayS (2000);

    // 5. Temperature gradient
    LCD_writeSpiCommand (TEMPGRADIENT);
    for (i = 0; i < 14; i++) 
    {
        LCD_writeSpiData (0);
    }

    // 6. Booster voltage ON
    LCD_writeSpiCommand (BOOSTVON);

#else // GE12
    /*
     * LCD type: GE8
     */
    // Hardware reset
    LCD_RESET_LOW ();
    mdelay (100);
    //Delay (1000);
    LCD_RESET_HIGH ();
    mdelay (100);
    //Delay (1000);

    // Display control
    LCD_writeSpiCommand (DISCTL);
    //  LCD_writeSpiData (0x03); // no division
    //  LCD_writeSpiData (0x23); // 160 line
    //  LCD_writeSpiData (0x02); // 2 highlighte line
    LCD_writeSpiData (0x00); // default
    LCD_writeSpiData (0x20); // (32 + 1) * 4 = 132 lines (of which 130 are visible)
    LCD_writeSpiData (0x0a); // default

    // COM scan
    LCD_writeSpiCommand (COMSCN);
    LCD_writeSpiData (0x00);  // Scan 1-80

    // Internal oscilator ON
    LCD_writeSpiCommand (IOSCON);

    // wait aproximetly 100ms
    mdelay (100);
    //Delay (10000);

    // Sleep out
    LCD_writeSpiCommand (SLPOUT);

    // Voltage control
    LCD_writeSpiCommand (VOLCTR);
    LCD_writeSpiData (0x1F); // middle value of V1
    LCD_writeSpiData (0x03); // middle value of resistance value

    // Temperature gradient
    LCD_writeSpiCommand (TMPGRD);
    LCD_writeSpiData (0x00); // default

    // Power control
    LCD_writeSpiCommand (PWRCTR);
    LCD_writeSpiData (0x0f);   // referance voltage regulator on, circuit voltage follower on, BOOST ON

    // Normal display
    LCD_writeSpiCommand (DISNOR);

    // Inverse display
    LCD_writeSpiCommand (DISINV);

    // Partial area off

⌨️ 快捷键说明

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