注册 登录
电子工程世界-论坛 返回首页 EEWORLD首页 频道 EE大学堂 下载中心 Datasheet 专题
他化自在天的个人空间 https://home.eeworld.com.cn/space-uid-378163.html [收藏] [复制] [分享] [RSS]
日志

我写的基于msp430的1602显示程序

热度 4已有 2402 次阅读2011-11-24 21:21


#

#include "io430.h"
#define uint unsigned int                              //定义数据类型替代码
#define uchar unsigned char
#define dat P1OUT                                      //定义LCD1602的数据口为P1
#define CLR_RS P2OUT&=~BIT0                            //置零P2.0位,即置零RS
#define SET_RS P2OUT|=BIT0                             //置一P2.0位,即置一RS
#define CLR_RW P2OUT&=~BIT1                            //置零P2.1位,即置零RW
#define SET_RW P2OUT|=BIT1                             //置一P2.1位,即置一RW
#define CLR_EN P2OUT&=~BIT2                            //置零P2.2位,即置零EN
#define SET_EN P2OUT|=BIT2                             //置一P2.2位,即置一EN
uchar busy;                                            //1602判忙标志
void delay_lms(int x);                                  //延时程序,短延时
void delay_ls(int x);                                   //延时程序,长延时
void display(void);                                    //显示程序
void busy_1602(void);                                  //液晶查忙程序
void init_1602(void);                                  //液晶初始化
void shj_1602(uchar a);                                //液晶写数据程序
void zhl_1602(uchar a);                                //液晶写指令程序

int main( void )
{
  // Stop watchdog timer to prevent time out reset
  WDTCTL = WDTPW + WDTHOLD;
  P1DIR=0xff;
  P3DIR=0xff;
  display(); 
}


void delay_lms(int x)                                   //延时程序,短延时
{
  while(x--)
    for(int i=0;i<25;i++);
}


void delay_ls(int x)                                    //延时程序,长延时
{
  for(int i=0;i<8;i++)
  {
    while(x--)
      for(int i=0;i<150;i++);
  }
}


void display(void)                                     //液晶显示程序
{
  uchar i;                                             //定义计数值
  uchar table0[16]={"fuck the rules.."};               //定义LCD1602显示两行的字符
  uchar table1[16]={"God bless you..."};
  init_1602();                                         //初始化1602
  zhl_1602(0x08);                                      //关闭显示
  zhl_1602(0x01);                                      //显示清屏
  for(i=0;i<16;i++)                                    //发送数据第一行
  {
    shj_1602(table0);
  }
  zhl_1602(0x80+0x40);                                 //显示换行
  for (i=0;i<16;i++)                                   //发送数据第二行
  {
    shj_1602(table1);
  }
  zhl_1602(0x0c);                                      //显示开及光标设置
}
            
            
void busy_1602(void)                                   //查询忙碌标志信号程序
{
  do
  {
    CLR_EN;                                            //EN置0
    SET_RW;                                            //RW置1   读信号线
    CLR_RS;                                            //RS置0   读取指令
    SET_EN;                                            //EN置1   读信息
    busy=dat;
    CLR_EN;                                            //EN置0
    delay_lms(10);
  }
  while(busy&&0x10==1);
}
            

void zhl_1602(uchar a)                                 //写指令到LCM程序
{
  busy_1602();
  CLR_EN;                                              //EN置0
  CLR_RW;                                              //RW置0   写信号线            
  CLR_RS;                                              //RS置1   读取指令
  SET_EN;                                              //EN置1   读信息
  dat=a; 
  CLR_EN;                                              //EN置0
}
            
            
void shj_1602(uchar a)                                 //写指令到LCM程序
{
  busy_1602();
  CLR_EN;                                              //EN置0
  CLR_RW;                                              //RW置0   写信号线
  SET_RS;                                              //RS置1   读取数据
  SET_EN;                                              //EN置1    读信息
  dat=a;
  CLR_EN;                                              //EN置0
}
            

void init_1602(void)                                   //启动LCM程序
{
  zhl_1602(0x38);                                      //写指令
  zhl_1602(0x0c);                                      //显示开及光标设置
  zhl_1602(0x06);                                      //光标移动设置
}
     

发表评论 评论 (5 个评论)
回复 dianzichina 2012-3-30 20:57
这么长时间了没人踩踩吗?
回复 时光碎了天 2014-3-16 16:13
  
回复 glass 2014-7-6 21:41
赞一个
回复 11207990121 2014-7-30 18:06
楼主,为啥你的p3口没用用到,你也定义了它的方向的呢
回复 xuechaolei 2015-1-6 16:01
你敢说 你你这个能好使

facelist doodle 涂鸦板

您需要登录后才可以评论 登录 | 注册