微波EDA网,见证研发工程师的成长!
首页 > 研发问答 > 硬件电路设计 > 硬件电路设计讨论 > MSP430F149驱动LCD

MSP430F149驱动LCD

时间:12-12 整理:3721RD 点击:
用MSP430驱动LCD屏,不显示字,但是在数据引脚上可以测到相应的高低电平,比如说显示'T',在DB7~DB0上可以检测到“底高低高低高低低”电平,不知道是什么原因。程序如下:(刚开始做,写的不好)
#include <MSP430x14x.h>
#include <intrinsics.h>
typedef unsigned char uchar;
typedef unsigned int  uint;
#define RS BIT7
#define RW BIT6
#define E  BIT5
//-----------------------------------
// dispaly data
//-----------------------------------
uchar Logo1[]="TOPWAY Char LCDM";
uchar Logo[]="1234567890123456";
uchar i;
//-----------------------------------
// Delay Routine
//-----------------------------------
void delayus(uint u)                        //delay routine
{
        uint i;
        for(i=0;i<=u;i++)
        {
        __no_operation();
        __no_operation();
        }
}
void delayms(uint m)
{
        uint j;
        uint i;
        
        for(i=0; i<m; i++)
            for(j=0; j<250; j++)
                __no_operation();
}
//-----------------------------------
// IO Routine
//-----------------------------------
void SdCmd(uchar command)                //send command
{
    P2OUT &= ~BIT5;
    P2OUT &= ~BIT6;
    P2OUT &= ~BIT7;  
    P4OUT=command;
    P2OUT |= BIT5;
    __no_operation();
    __no_operation();
    __no_operation();
    P2OUT &= ~BIT5;
    delayus(50);
}
void SdData(uchar DData)                //send data
{
    P2OUT &= ~BIT5;
    P2OUT &=~ BIT6;
    P2OUT |= BIT7;
    P4OUT=DData;
    P2OUT |= BIT5;  
    __no_operation();
    __no_operation();
    __no_operation();
    P2OUT &= ~BIT5;
    __no_operation();
    __no_operation();
    __no_operation();
}
//-----------------------------------
// init
//-----------------------------------
void LCD_init()
{
        SdCmd(0x38);        //8bit I/F;2-linedisplay;5x8 font
        SdCmd(0x04);        //No screen shifting
        SdCmd(0x0c);        //Display on;cursor off;cursor-blinking off
        SdCmd(0x01);    //clear screen
        delayms(2);        //clear screen command takes more time
}
//-----------------------------------
// Main Program
//-----------------------------------
void main()
{      
        WDTCTL = WDTPW + WDTHOLD;
        P2SEL &= ~0xe0;
        P2DIR |= 0xe0;
        P2OUT &= ~0Xe0;
        P3SEL &= ~BIT3;
        P3DIR |= BIT3;
        P3OUT |= BIT3;
        P4SEL &= ~0xff;
        P4DIR |= 0xff;
        P4OUT=0x00;
        delayms(10);        // wait for LCD module power on reset
        LCD_init();
        SdCmd(0x80);
        for(i=0;i<16;i++)
        {  SdData(Logo1);
           delayms(5);}
        SdCmd(0x80+0x40);
        for(i=0;i<16;i++)
        {  SdData(Logo);
           delayms(5);}
        while(1);        //end of program
}

Copyright © 2017-2020 微波EDA网 版权所有

网站地图

Top