原创 iar lpc2131 4线lcd1602_test

2008-8-5 23:35 2742 17 17 分类: 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);
  }
}


 


 


 

PARTNER CONTENT

文章评论0条评论)

登录后参与讨论
EE直播间
更多
我要评论
0
17
关闭 站长推荐上一条 /1 下一条