广告

原创 iar lpc2131 4线lcd1602_test

2008-8-5 23:35 2165 1 1 分类: MCU/ 嵌入式

早就听说IAR的强大,苦于没有JLINK的支持,一直使用ADS和KEIL,这次把keil版本的lpc2131  4线显示lcd1602,移植过去,感觉很不错。以下为代码部分:


//main.c


  FrecInit();                     // 
  LCDInit();                      //


  /**** LCD ˉ ****/
  LCDSendCommand(DISP_ON);        // LCD
  LCDSendCommand(CLR_DISP);       // LCD
//μúò?DD
  LCDSendCommand(DD_RAM_ADDR1);    // 


  LCDSendTxt1(" www.iar.com ");   //
//μú2DD
  LCDSendCommand(DD_RAM_ADDR2);    // 
  LCDSendTxt2("zhangjiawei");     //


}


 


//lcd.c



#include <string.h>
#include "lcd.h"


unsigned long data;


//HD44780 4?????ó?y?ˉDèòaμ?E????????3?
void E_Pulse() {
  IO0SET_bit.P0_28 = 1; // E="1"
  Delay(100);
  IO0CLR_bit.P0_28 = 1; // E="0"
}


void LCDInit() {
//????4??êy?Y?? D4, D5, D6, D7, ??′??÷???? RS, ?áD′ RW, ???? E ?aê?3?
  IO0DIR_bit.P0_10 = 1;   //D4
  IO0DIR_bit.P0_11 = 1;   //D5
  IO0DIR_bit.P0_12 = 1;   //D6
  IO0DIR_bit.P0_13 = 1;   //D7
  IO0DIR_bit.P0_22 = 1;   //RS
  IO0DIR_bit.P0_29 = 1;   //R/W
  IO0DIR_bit.P0_28 = 1;   //E


 //LCD 3?ê??ˉ£?4?????ó?y?ˉ·?ê?
  IO0CLR_bit.P0_22 = 1;  // RS = 0
  IO0CLR_bit.P0_29 = 1;  // R/W = 0
  IO0CLR_bit.P0_28 = 1;  // E = 0
  Delay(10000);        // ?óê±110ms


  IO0SET_bit.P0_10 = 1;   // D4 = 1
  IO0SET_bit.P0_11 = 1;   // D5 = 1
  E_Pulse();              // E????????3?
  Delay(10000);           // ?óê±10ms


  IO0SET_bit.P0_10 = 1;   // D4 = 1
  IO0SET_bit.P0_11 = 1;   // D5 = 1
  E_Pulse();              // E????????3?
  Delay(10000);           // ?óê±10ms


  IO0SET_bit.P0_10 = 1;   // D4 = 1
  IO0SET_bit.P0_11 = 1;   // D5 = 1
  E_Pulse();              // E????????3?
  Delay(10000);           // ?óê±10ms


  IO0SET_bit.P0_11 = 1;   // D5 = 1
  IO0CLR_bit.P0_10 = 1;   // D4 = 0
  E_Pulse();              // E????????3?
}


void LCDSendCommand(unsigned long a) {  //?òLCD·¢?í?????üá?
  IO0CLR_bit.P0_29 = 1;                     // RW = 0
  Delay(20000);                             // ?óê±2ms
  data = 0x0;


  data = 0xffffff0f | a;                    // ??4??
  IO0CLR |= 0x00003c00;                     // ??0 D4-D7
  data = data << 6;


  IO0SET = (IO0SET | 0x00003c00) & data;     // ??1 D4-D7
  IO0CLR_bit.P0_22 = 1;                      // RS = 0 -> ?üá?·?ê?
  E_Pulse();                                 // E????????3?
  data = 0x0;
  a = a<<4;


  data = 0xffffff0f | a;                     // ??4??
  IO0CLR |= 0x00003c00;                      // ??0 D4-D7
  data = data << 6;
  IO0SET = (IO0SET | 0x00003c00) & data;      // ??1 D4-D7
  IO0CLR_bit.P0_22 = 1;                       // RS = 0 -> ?üá?·?ê?
  E_Pulse();                                  // E????????3?
}


void LCDSendChar(unsigned long a){ //?òLCD·¢?í????ê?êy?Y
  IO0CLR_bit.P0_29 = 1;                     // RW = 0
  Delay(20000);                             // ?óê±2ms
  data = 0x0;


  data = 0xffffff0f | a;                    // ??4??
  IO0CLR |= 0x00003c00;                     // ??0 D4-D7
  data = data << 6;


  IO0SET = (IO0SET | 0x00003c00) & data;    // ??1 D4-D7
  IO0SET_bit.P0_22 = 1;                     // RS = 1  -> êy?Y·?ê?
  E_Pulse();                                // E????????3?
  data = 0x0;
  a = a<<4;


  data = 0xffffff0f | a;                     // ??4??
  IO0CLR |= 0x00003c00;                      // ??0 D4-D7
  data = data << 6;
  IO0SET = (IO0SET | 0x00003c00) & data;     // ??1 D4-D7
  IO0SET_bit.P0_22 = 1;                      // RS = 1  -> êy?Y·?ê?
  E_Pulse();                                 // E????????3?
}


void LCDSendTxt1(char* a) {   //?òLCDD′è?×?·?′?
  for(int i="0"; i<strlen(a); i++) {
    LCDSendChar(a);
  }
}


void LCDSendTxt2(char* a) {   //?òLCDD′è?×?·?′?
  for(int i="0"; i<strlen(a); i++) {
    LCDSendChar(a);
  }
}


 


 


 

广告

文章评论 0条评论)

登录后参与讨论
相关推荐阅读
412922521_325344472 2009-11-15 00:44
通用按键消抖函数 -- 数据与过程分离
AUTO:  nicksean 不务正业          项目里经常处理按键消抖, 本来这个消抖的过程是与具体按下的键无关的, 可以前的代码总是在消抖的同时处理具体的按键值, 再加上长按 短按 组合...
412922521_325344472 2009-11-13 13:16
液晶ST7920串行显示
液晶显示128*64以7920为主控制器,采用3线制,比较经济简单。代码如下.....
412922521_325344472 2009-11-13 13:11
DS18B20 C51完整版
使用WINBOND W78C516单片机,11.0592MHZ晶振,用共阳LED数码管P0口输出段码,P1口扫描/*******************************************...
412922521_325344472 2009-11-12 13:19
74HC164驱动数码管
          74HC164是串行输入,并行输出接口器件,可用在单向的并行输出/并行地址锁存等. 74HC164因为价格便宜,容易使用特别适合使用在在需要用到数码管显示IO口又比较紧张的电子产品...
412922521_325344472 2009-11-10 20:13
at24c512多字节读写函数 欢迎测试
刚写的at24c512多字节读写函数,欢迎测试。/********************************************************************函数功能:EE...
412922521_325344472 2009-11-10 19:59
旋转编码器
    很好的旋转编码器的读码程序,设旋转编码器的输出波形如下                 ______        ______        ______        ______正转时:...
我要评论
0
1
广告
关闭 热点推荐上一条 /3 下一条