在线情况
楼主
  • 头像
  • 级别
    • 积分4
    • 经验17
    • 文章2
    • 注册2014-11-19
    关于msp430f149驱动1602的程序移植问题
    [P][FACE=宋体][SIZE=12px],从郭天祥那本书上移植过来的,但是移植过来后就不能用了,看了很久也不知道问题所在,请大神们帮忙看看[/SIZE][/FACE][/P][FACE=宋体][SIZE=9pt]#include "msp430x14x.h"[/SIZE][/FACE]
    [FACE=宋体][SIZE=9pt]typedef unsigned char uchar;[/SIZE][/FACE]
    [FACE=宋体][SIZE=9pt]typedef unsigned int uint;[/SIZE][/FACE]
    [FACE=宋体][SIZE=9pt]#define lcden_on P6OUT|=BIT5;        //E=1[/SIZE][/FACE]
    [FACE=宋体][SIZE=9pt]#define lcden_off P6OUT&=~BIT5;      //E=0[/SIZE][/FACE]
    [FACE=宋体][SIZE=9pt]#define lcdrw_off P6OUT&=~BIT4;      //RW=0[/SIZE][/FACE]
    [FACE=宋体][SIZE=9pt]#define lcdrs_off P6OUT&=~BIT3;      //RS=0[/SIZE][/FACE]
    [FACE=宋体][SIZE=9pt]#define lcdrs_on P6OUT|=BIT3;        //RS=1[/SIZE][/FACE]
    [FACE=宋体][SIZE=9pt]uchar table[]="I LOVE MCU!";[/SIZE][/FACE]
    [FACE=宋体][SIZE=9pt]uchar table1[]="[/SIZE][/FACE][URL=http://www.ffffff.com]www.ffffff.com[/URL][FACE=宋体][SIZE=9pt]";[/SIZE][/FACE]
    [FACE=宋体][SIZE=9pt]void delay(void)                   //延时函数5ms [/SIZE][/FACE]
    [FACE=宋体][SIZE=9pt] { [/SIZE][/FACE]
    [FACE=宋体][SIZE=9pt]    uint k=40000;[/SIZE][/FACE]
    [FACE=宋体][SIZE=9pt]    while (k != 0)[/SIZE][/FACE]
    [FACE=宋体][SIZE=9pt]    {[/SIZE][/FACE]
    [FACE=宋体][SIZE=9pt]        k--;[/SIZE][/FACE]
    [FACE=宋体][SIZE=9pt]    }[/SIZE][/FACE]
    [FACE=宋体][SIZE=9pt]}[/SIZE][/FACE]
    [FACE=宋体][SIZE=9pt]void write_com(uchar com)         //写指令操作[/SIZE][/FACE]
    [FACE=宋体][SIZE=9pt]{[/SIZE][/FACE]
    [FACE=宋体][SIZE=9pt]    lcdrs_off;[/SIZE][/FACE]
    [FACE=宋体][SIZE=9pt]    lcdrw_off;[/SIZE][/FACE]
    [FACE=宋体][SIZE=9pt]   _NOP();[/SIZE][/FACE]
    [FACE=宋体][SIZE=9pt]    P2OUT = com;[/SIZE][/FACE]
    [FACE=宋体][SIZE=9pt]   _NOP();[/SIZE][/FACE]
    [FACE=宋体][SIZE=9pt]    lcden_on;[/SIZE][/FACE]
    [FACE=宋体][SIZE=9pt]    delay();[/SIZE][/FACE]
    [FACE=宋体][SIZE=9pt]    lcden_off;[/SIZE][/FACE]
    [FACE=宋体][SIZE=9pt]}[/SIZE][/FACE]
    [FACE=宋体][SIZE=9pt]void write_data(uchar data)       //写数据操作[/SIZE][/FACE]
    [FACE=宋体][SIZE=9pt]{[/SIZE][/FACE]
    [FACE=宋体][SIZE=9pt]     lcdrs_on;[/SIZE][/FACE]
    [FACE=宋体][SIZE=9pt]    lcdrw_off;[/SIZE][/FACE]
    [FACE=宋体][SIZE=9pt]    _NOP();[/SIZE][/FACE]
    [FACE=宋体][SIZE=9pt]    P2OUT = data;[/SIZE][/FACE]
    [FACE=宋体][SIZE=9pt]   _NOP();[/SIZE][/FACE]
    [FACE=宋体][SIZE=9pt]    lcden_on;[/SIZE][/FACE]
    [FACE=宋体][SIZE=9pt]   delay();[/SIZE][/FACE]
    [FACE=宋体][SIZE=9pt]    lcden_off;[/SIZE][/FACE]
    [FACE=宋体][SIZE=9pt]}[/SIZE][/FACE]
    [FACE=宋体][SIZE=9pt]void init( void )[/SIZE][/FACE]
    [FACE=宋体][SIZE=9pt]{[/SIZE][/FACE]
    [FACE=宋体][SIZE=9pt]    delay();[/SIZE][/FACE]
    [FACE=宋体][SIZE=9pt]    lcden_off;[/SIZE][/FACE]
    [FACE=宋体][SIZE=9pt]    write_com(0x38);                //设置16X2显示,5X7点阵,8位数据接口[/SIZE][/FACE]
    [FACE=宋体][SIZE=9pt]    delay();[/SIZE][/FACE]
    [FACE=宋体][SIZE=9pt]    write_com(0x0c);                //设置开显示,不显示光标[/SIZE][/FACE]
    [FACE=宋体][SIZE=9pt]    delay();[/SIZE][/FACE]
    [FACE=宋体][SIZE=9pt]    write_com(0x06);                //写一个字符后地址指针加1[/SIZE][/FACE]
    [FACE=宋体][SIZE=9pt]    delay();[/SIZE][/FACE]
    [FACE=宋体][SIZE=9pt]    write_com(0x01);                //显示清0,数据指针清0[/SIZE][/FACE]
    [FACE=宋体][SIZE=9pt]    delay();[/SIZE][/FACE]
    [FACE=宋体][SIZE=9pt]}[/SIZE][/FACE]
    [FACE=宋体][SIZE=9pt]int main( void )[/SIZE][/FACE]
    [FACE=宋体][SIZE=9pt]{[/SIZE][/FACE]
    [FACE=宋体][SIZE=9pt]  // Stop watchdog timer to prevent time out reset[/SIZE][/FACE]
    [FACE=宋体][SIZE=9pt]  WDTCTL = WDTPW + WDTHOLD;         [/SIZE][/FACE]
    [FACE=宋体][SIZE=9pt]  P2DIR = 0xFF;[/SIZE][/FACE]
    [FACE=宋体][SIZE=9pt]  init();[/SIZE][/FACE]
    [FACE=宋体][SIZE=9pt]  int i,j;[/SIZE][/FACE]
    [FACE=宋体][SIZE=9pt]  write_com(0x80);[/SIZE][/FACE]
    [FACE=宋体][SIZE=9pt]  for(i=0;i<11;i++)[/SIZE][/FACE]
    [FACE=宋体][SIZE=9pt]  {[/SIZE][/FACE]
    [FACE=宋体][SIZE=9pt]      write_data(table[/SIZE][/FACE][i][FACE=宋体][SIZE=9pt]);
          delay();
      }
      write_com(0x80+0x40);
      for(j=0;j<14;j++)
      {
          write_data(table1[j]);
          delay();
      }
      while(1);
    }[/SIZE][/FACE][/i]
    哈哈哈
    在线情况
    2
    • 头像
    • 级别
    • 门派
    • 职务总版主
    • 声望+9
    • 财富5
    • 积分3065
    • 经验390701
    • 文章6744
    • 注册2006-03-07
    我给你一些建议:
    [1] 注意MCU的主频,及操作的过程中的延时时间。及初始化每步间的时间。
    [2] 注意数据口读与写之间方向操作。控制线一般全为写。数据可能需要用到读。注意方向的切换。[P][3] 移植注意IO线要修过来,不要搞错。[/P][P][4] 注意LCD的偏置,也许你程序对了。但偏置不对,也无法正常显示的。[/P]
    [COLOR=#0000ff]欢迎发贴分享设计心得、开源DIY...[/COLOR]
    Powered by LeadBBS 9.2 .
    Page created in 0.2656 seconds with 5 queries.