这些小活动你都参加了吗?快来围观一下吧!>>
电子产品世界 » 论坛首页 » 嵌入式开发 » MCU » 转发来自王晓翠的求助,各位兄弟帮忙看下!

共8条 1/1 1 跳转至

转发来自王晓翠的求助,各位兄弟帮忙看下!

菜鸟
2007-05-28 21:59:29     打赏

以下为转发内容:

我现在在做车速里程表,用到了LCM1010液晶显示,但是我没有它的C语言程序。如果你有C 语言的LCM1010程序,希望能发一份给我。谢谢。




关键词: 转发     来自     王晓翠     求助     各位     兄弟     帮忙     看下    

菜鸟
2007-05-28 22:08:00     打赏
2楼

刚刚在网上找的,不知道是否符合要求~~~~

LPC213X之LCM1010 C++程序源代码


-------------------------------------------------------------------------------*/


#i nclude <LPC213XDEF.H>


#define WDI P0_11//
#define LCMDATA P0_6 //LCM1010数据端
#define LCMWR P0_7 //LCM1010写
#define LCMCS P0_8 //LCM1010片选


#define LedSegS1 0x20
#define LedSegS2 0x40
#define LedSegS3 0x80

#define LedSegS4 0x02
#define LedSegS5 0x04
#define LedSegS6 0x08

//HCBD GAEF
#define LedSegA 0x04
#define LedSegB 0x20
#define LedSegC 0x40
#define LedSegD 0x10
#define LedSegE 0x02
#define LedSegF 0x01
#define LedSegG 0x08
#define LedSegH 0x80

#define LedChar0 (LedSegA + LedSegB + LedSegC + LedSegD + LedSegE + LedSegF )
#define LedChar1 ( LedSegB + LedSegC )
#define LedChar2 (LedSegA + LedSegB + LedSegD + LedSegE + LedSegG)
#define LedChar3 (LedSegA + LedSegB + LedSegC + LedSegD + LedSegG)
#define LedChar4 ( LedSegB + LedSegC + LedSegF + LedSegG)
#define LedChar5 (LedSegA + LedSegC + LedSegD + LedSegF + LedSegG)
#define LedChar6 (LedSegA + LedSegC + LedSegD + LedSegE + LedSegF + LedSegG)
#define LedChar7 (LedSegA + LedSegB + LedSegC )
#define LedChar8 (LedSegA + LedSegB + LedSegC + LedSegD + LedSegE + LedSegF + LedSegG)
#define LedChar9 (LedSegA + LedSegB + LedSegC + LedSegD + LedSegF + LedSegG)
#define LedCharA (LedSegA + LedSegB + LedSegC + LedSegE + LedSegF + LedSegG)
#define LedCharB ( LedSegC + LedSegD + LedSegE + LedSegF + LedSegG)
#define LedCharC (LedSegA + LedSegD + LedSegE + LedSegF )
#define LedCharD ( LedSegB + LedSegC + LedSegD + LedSegE + LedSegG)
#define LedCharE (LedSegA + LedSegD + LedSegE + LedSegF + LedSegG)
#define LedCharF (LedSegA + LedSegE + LedSegF + LedSegG)


static const unsigned char LedTab[] =
{
LedChar0,
LedChar1,
LedChar2,
LedChar3,
LedChar4,
LedChar5,
LedChar6,
LedChar7,
LedChar8,
LedChar9,
LedCharA,
LedCharB,
LedCharC,
LedCharD,
LedCharE,
LedCharF
};


void _delay_loop_(unsigned int);
void _delay_loop_(unsigned int val)
{
unsigned int i;
for(i = 0; i < (val * 60); i ++);
}


class SystemObj {//系统类
public:
SystemObj(void);//SystemObj的构造函数
public:
void SystemInit(void);
void WdtInit(void);
void ClrWdt(void);
};

class LcdObj {//系统显示菜单类
public:
LcdObj(void);//LcdObj的构造函数
public:
void LcdInit(void);
void LcdBuffersClear(void);
void LcdClear(void);
void LcdOpen(void);
void LcdClose(void);
void LcdWrite(unsigned char, unsigned char);
void LcdWriteCommand(unsigned char);
void LcdWriteData(unsigned char, unsigned char);
void LcdDisplay(unsigned char, unsigned char);
void LcdDisplay(unsigned long);
void LcdDisplay(unsigned short);
public:
unsigned char LcdBuffers[32];
};

SystemObj::SystemObj(void)
{
SystemInit();
}

void SystemObj::SystemInit(void)
{
PINSEL->PIN_SEL0 = 0;
PINSEL->PIN_SEL1 = 0;
PINSEL->PIN_SEL2 = 0;
P0->IODIR = 0;
P1->IODIR = 0;
WdtInit();
}

void SystemObj::WdtInit(void)
{
P0->IODIR |= (1 << WDI); // 设置WDI控制口为输出
}

void SystemObj::ClrWdt(void)
{
P0->IOPIN ^= (1 << WDI);
}

LcdObj::LcdObj(void)
{
LcdInit();
}

void LcdObj::LcdClear(void)
{
int i;
for(i = 0;i < 32;i ++) {
LcdWriteData(i, 0);
}
}

void LcdObj::LcdBuffersClear(void)
{
int i;
for(i = 0;i < 32;i ++) {
LcdBuffers[i] = 0;
}
}

void LcdObj::LcdInit(void)
{
P0->IODIR |= (1 << LCMDATA) | (1 << LCMWR) | (1 << LCMCS);
P0->IOSET = (1 << LCMDATA) | (1 << LCMWR) | (1 << LCMCS);
LcdBuffersClear();
LcdWriteCommand(0x24);
LcdWriteCommand(0x18);
LcdWriteCommand(0x01);
LcdWriteCommand(0x03);
LcdClear();
}

void LcdObj::LcdOpen(void)
{
P0->IOSET = (1 << LCMDATA) | (1 << LCMWR) | (1 << LCMCS);
_delay_loop_(1);
P0->IOCLR = (1 << LCMCS);//打开片选信号
_delay_loop_(1);
}

void LcdObj::LcdClose(void)
{
P0->IOSET = (1 << LCMDATA) | (1 << LCMWR) | (1 << LCMCS);
}

void LcdObj::LcdWrite(unsigned char Data, unsigned char Count)
{
int i;
unsigned char val;
val = 1 << (Count - 1);
for(i = 0; i < Count; i ++) {
P0->IOCLR = (1 << LCMWR);//拉低读写时钟
if (Data & val) {
P0->IOSET = (1 << LCMDATA);//发送串行数据'1'
}
else {
P0->IOCLR = (1 << LCMDATA);//发送串行数据'0'
}
_delay_loop_(1);//等待LCM1010读
P0->IOSET = (1 << LCMWR);//抬高读写时钟,打入串行数据
_delay_loop_(1);//等待LCM1010读
Data <<= 1;
}
}

void LcdObj::LcdWriteCommand(unsigned char Command)
{
LcdOpen();
LcdWrite(0x04, 3);
LcdWrite(Command, 8);
LcdWrite(0x00, 1);
LcdClose();
}

void LcdObj::LcdWriteData(unsigned char Addr, unsigned char Data)
{
LcdOpen();
LcdWrite(0x05, 3);
LcdWrite(Addr, 5);
LcdWrite(Data, 4);
LcdClose();
}

void LcdObj::LcdDisplay(unsigned char LcdBit, unsigned char LcdData)
{
unsigned char Addr;
Addr = LcdBit;
LcdOpen();
LcdWrite(0x05, 3);
LcdWrite(Addr, 6);
if (Addr) {
LcdWrite((LcdData >> 4) & 0x0f, 4);//HCB0
LcdWrite((LcdData >> 1) & 0x0f, 4);//DGA0
LcdWrite((LcdData << 1) & 0x06, 4);//0EF0
}
else {
LcdWrite(LcdData >> 4, 4);//S1S2S3 0
LcdWrite(LcdData, 4);//S1S2S3 0
}
LcdClose();

}

void LcdObj::LcdDisplay(unsigned long val)
{
unsigned char LcdData, temp;
int i;
LcdOpen();
LcdWrite(0x05, 3);
LcdWrite(0x0e, 6);
for(i = 0; i < 6; i ++) {
temp = val % 10;
val /= 10;
LcdData = LedTab[temp];
LcdWrite((LcdData >> 4) & 0x0f, 4);//HCB0
LcdWrite((LcdData >> 1) & 0x0f, 4);//DGA0
LcdWrite((LcdData << 1) & 0x06, 4);//0EF0
}
LcdClose();
}

void LcdObj::LcdDisplay(unsigned short val)
{
unsigned char LcdData, temp;
int i, div;
div = 1000;
LcdOpen();
LcdWrite(0x05, 3);
LcdWrite(0x02, 6);
for(i = 0; i < 4; i ++) {
temp = (val / div) % 10;
div /= 10;
LcdData = LedTab[temp];
if (i >= 2) {
LcdData |= LedSegH;
}
LcdWrite((LcdData >> 4) & 0x0f, 4);//HCB0
LcdWrite((LcdData >> 1) & 0x0f, 4);//DGA0
LcdWrite((LcdData << 1) & 0x06, 4);//0EF0
}
LcdClose();
}

SystemObj Sys;
LcdObj Lcd;

int main(void)
{
unsigned char K = LedSegS1;
unsigned long S = 1234;
unsigned short V = 0;
// Lcd.LcdDisplay(0x00, LedSegS1 + LedSegS4 + LedSegS6);//S1

/*
Lcd.LcdDisplay(0x02, LedChar1);//下LED1
Lcd.LcdDisplay(0x05, LedChar2);//下LED2
Lcd.LcdDisplay(0x08, LedSegH + LedChar3);//下LED3
Lcd.LcdDisplay(0x0b, LedSegH + LedChar4);//下LED4
*/
/*
Lcd.LcdDisplay(0x0e, LedCharF);//上LED5
Lcd.LcdDisplay(0x11, LedCharE);//上LED6
Lcd.LcdDisplay(0x14, LedCharD);//上LED7
Lcd.LcdDisplay(0x17, LedCharC);//上LED8
Lcd.LcdDisplay(0x1a, LedCharB);//上LED9
Lcd.LcdDisplay(0x1d, LedCharA);//上LED10
*/
Lcd.LcdDisplay(0x00, K);
Lcd.LcdDisplay(S);
Lcd.LcdDisplay(V);
while(1) {
S ++;
Lcd.LcdDisplay(S);
if ((S % 100) == 0) {
V ++;
Lcd.LcdDisplay(V);
if ((S % 500) == 0) {
if (K == LedSegS1) {
K = LedSegS2;
}
else if (K == LedSegS2) {
K = LedSegS3;
}
else if (K == LedSegS3) {
K = LedSegS4;
}
else if (K == LedSegS4) {
K = LedSegS5;
}
else if (K == LedSegS5) {
K = LedSegS6;
}
else K = LedSegS1;
Lcd.LcdDisplay(0x00, K);
}
}
Sys.ClrWdt();
_delay_loop_(500);
__nop();
}
}


菜鸟
2007-05-28 23:55:00     打赏
3楼

这个程序我也看到了,可是这个程序写的怪怪的(C++我不了解)有些地方的命令格式都看的不是很明白。我有的相关资料我发上来大家看看。我自己也努力 一下,尽量做。也希望大家帮忙。


菜鸟
2007-05-29 00:03:00     打赏
4楼

;********* LCD1010 TEST **********************
;/CS=P1.5 /WR=P1.3 DATA=P1.2 ********************
;RAM 20H:COMMAND CODE ********************
;RAM 21H: LCD ADDR ***
;RAM 25H: LCD DATA ***
ORG 0000H
JMP START
ORG 0100H

START: MOV P1,#0FFH
SETB P3.7
CALL DLY500
MOV 20H,#00100100B ;INITIALIZE
CALL WRCOM
MOV 20H,#00011000B ;RC
CALL WRCOM
MOV 20H,#00000001B ;SYS EN
CALL WRCOM
MOV 20H,#00000011B ;LCD ON
CALL WRCOM
MOV 21H,#00000000B ;CLEAR DISPLAY
MOV 23H,21H
MOV R6,#0
CALL WRDD
MOV 25H,#00000000B ;FIRST ADDR
MOV 27H,25H
CALL WRDA
CALL WALP
CALL DLY1S

MOV 21H,#00000000B ;DISPLAY 8
MOV 23H,21H
MOV R6,#0
CALL WRDD
MOV 25H,#00001111B
MOV 27H,25H
CALL WRDA
CALL WALP
MOV P1,#0FFH
CALL DLY1S

CALL DLY500 ;DISPLAY 123
MOV P1,#0FFH
CALL DLY1S
CALL WR123
MOV P1,#0FFH
CALL DLY1S
CALL DLY1S

MOV 21H,#00000000B ;DISPLAY D0
MOV 23H,21H
MOV R6,#0
CALL WRDD
MOV 25H,#00000001B
MOV 27H,25H
CALL WRDA
CALL WALP
MOV P1,#0FFH
CALL DLY1S
MOV 21H,#00000000B ;DISPLAY D1
MOV 23H,21H
MOV R6,#0
CALL WRDD
MOV 25H,#00000010B
MOV 27H,25H
CALL WRDA
CALL WALP
MOV P1,#0FFH
CALL DLY1S
MOV 21H,#00000000B ;DISPLAY D2
MOV 23H,21H
MOV R6,#0
CALL WRDD
MOV 25H,#00000100B
MOV 27H,25H
CALL WRDA
CALL WALP
MOV P1,#0FFH
CALL DLY1S
MOV 21H,#00000000B ;DISPLAY D3
MOV 23H,21H
MOV R6,#0
CALL WRDD
MOV 25H,#00001000B
MOV 27H,25H
CALL WRDA
CALL WALP
MOV P1,#0FFH
CALL DLY1S

STOP: MOV P1,#0FFH
CALL DLY1S
MOV 20H,#02H ;LCD OFF
CALL WRCOM
MOV P1,#0FFH
MOV 20H,#00H ;SYS DI


MOV 20H,#00001101B ;CTC=0
CALL WRCOM
MOV 20H,#00001001B ;BZ ON
CALL WRCOM
MOV 20H,#01100000B ;BZ =2KHZ
CALL WRCOM
CALL DLY1S
MOV 20H,#00001000B ;BZ OFF
CALL WRCOM
CALL DLY500

SETB P3.7 ;WDT LED OFF
SETB P1.7 ;TEST WDT
JNB P1.7,SE0
SETB 20H
JMP SS1
SE0: CLR 20H
SS1: NOP
MOV 20H,#10100110B ;WDT=1/16 S
CALL WRCOM
MOV 20H,#00001101B ;CTC=0
CALL WRCOM
MOV 20H,#00001110B ;WDT=0
CALL WRCOM
MOV 20H,#00000111B ;WDT ON
CALL WRCOM
MOV 20H,#10001000B ;WDT/CTC EN
CALL WRCOM
CALL DLY500 ;1S
CALL DLY500 ;1S
JNB P1.7,SE00
SETB 21H
JMP SS2
SE00: CLR 21H
SS2: JNB 20H,SS3
JB 21H,SS3
CLR P3.7 ;WDT LED OK
CALL DLY1S ;1S
CALL DLY1S ;1S
JMP SS4
SS3: SETB P3.7 ;WDT LED OFF
SS4:
MOV 20H,#00000101B ;WDT OFF
CALL WRCOM
MOV 20H,#10000000B ;WDT/CTC DIS
CALL WRCOM
MOV 20H,#00001110B ;WDT=0
CALL WRCOM


MOV 20H,#03H ;LCD ON
CALL WRCOM

JMP START

;**** LCD DRIVER MODE SUB. **************
;**** WRITE COMMAND SUB. ***********
WRCOM: SETB P1.5 ;/CS=1
NOP
CALL DLY5
CLR P1.5 ;/CS=0
CALL DLY5
CLR P1.3 ;/WR=0
CALL DLY5
NOP
SETB P1.2 ;D=1 (100)
CALL DLY5
NOP
SETB P1.3 ;/WR=1
CALL DLY5
NOP
CLR P1.3 ;/WR=0
CALL DLY5
NOP
CLR P1.2 ;D=0
CALL DLY5
NOP
SETB P1.3 ;/WR=1
CALL DLY5
NOP
CLR P1.3 ;/WR=0
CALL DLY5
NOP
CLR P1.2 ;D=0
CALL DLY5
NOP
SETB P1.3 ;/WR=1
CALL DLY5
NOP

MOV R7,#9 ;LOOP=DATA 8 BIT +1X
CLR C
LOOPWR: NOP
CALL DLY5
CLR P1.3
CALL DLY5
MOV A,20H
RLC A
MOV 20H,A
JC WR1
CLR P1.2 ;DATA=0
CALL DLY5
JMP WRR
WR1: SETB P1.2 ;DATA=1
CALL DLY5
WRR: SETB P1.3
CALL DLY5
DJNZ R7,LOOPWR
RET

;************************************************************
;**** LOOP WRDA SUB. ****
WALP:
ST1: MOV 21H,23H
MOV A,21H
ADD A,#00000100B
MOV 21H,A
MOV 23H,A
INC R6
CALL WRDD
MOV 25H,27H
CALL WRDA
CJNE R6,#31,ST1
RET

;**** WRITE DATA SUB.****************************
WRDD: SETB P1.5 ;/CS=1
CALL DLY5
NOP
CLR P1.5 ;/CS=0
CALL DLY5
CLR P1.3 ;/WR=0
CALL DLY5
SETB P1.2 ;D=1 (101)
CALL DLY5
SETB P1.3 ;/WR=1
CALL DLY5
CLR P1.3 ;/WR=0
CALL DLY5
CLR P1.2 ;D=0
CALL DLY5
SETB P1.3 ;/WR=1
CALL DLY5
CLR P1.3 ;/WR=0
CALL DLY5
SETB P1.2 ;D=1
CALL DLY5
SETB P1.3 ;/WR=1
CALL DLY5

MOV R4,#6
MOV 22H,21H
ADDWR2: NOP
CALL DLY5
CLR P1.3
CALL DLY5
MOV A,21H
RLC A
MOV 21H,A
JC WR11
CLR P1.2 ;DATA=0
CALL DLY5
JMP WRR1
WR11: NOP
CALL DLY5
SETB P1.2 ;DATA=1
CALL DLY5
WRR1: NOP
CALL DLY5
SETB P1.3
CALL DLY5
DJNZ R4,ADDWR2
RET

WRDA: MOV R5,#4 ;LOOP=DATA 4 BIT
ADDWR3: NOP
CALL DLY5
CLR P1.3
CALL DLY5
MOV A,25H
RRC A
MOV 25H,A
JC WR12
CLR P1.2 ;DATA=0
CALL DLY5
JMP WRR2
WR12: NOP
CALL DLY5
SETB P1.2 ;DATA=1
CALL DLY5
WRR2: NOP
CALL DLY5
SETB P1.3
CALL DLY5
DJNZ R5,ADDWR3
RET

DLY5: NOP
NOP
NOP
NOP
RET
DLY25M: MOV R1,#250 ;12M/2.5MS
DLOP: CALL DLY5
CALL DLY5
DJNZ R1,DLOP
RET
DLY1S: MOV R0,#20 ;1S
DLOP1: CALL DLY25M
CALL DLY25M
DJNZ R0,DLOP1
RET
DLY500: MOV R0,#5
DLOP11: CALL DLY25M
CALL DLY25M
DJNZ R0,DLOP11
RET

;**** LIANXV WR SUB. ****
WR123: NOP
SETB P1.5 ;/CS=1
CALL DLY5
NOP
CLR P1.5 ;/CS=0
CALL DLY5
CLR P1.3 ;/WR=0
CALL DLY5
SETB P1.2 ;D=1 (101)
CALL DLY5
SETB P1.3 ;/WR=1
CALL DLY5
CLR P1.3 ;/WR=0
CALL DLY5
CLR P1.2 ;D=0
CALL DLY5
SETB P1.3 ;/WR=1
CALL DLY5
CLR P1.3 ;/WR=0
CALL DLY5
SETB P1.2 ;D=1
CALL DLY5
SETB P1.3 ;/WR=1
CALL DLY5

MOV R2,#6
LOOP: CLR P1.3 ;/WR=0
CALL DLY5
CLR P1.2 ;D=0
CALL DLY5
SETB P1.3 ;/WR=1
CALL DLY5
DJNZ R2,LOOP

MOV R3,#32
MOV DPTR,#TABDA
LOOP1: CLR A
MOVC A,@A+DPTR
MOV 25H,A
CALL WRDA
INC DPTR
DJNZ R3,LOOP1
RET
TABDA: DB 05H,02H,06H,05H,06H,06H,07H,04H,07H,07H,06H,07H,04H,00H,02H,07H;
DB 06H,02H,07H,04H,06H,02H,04H,06H,07H,00H,04H,07H,02H,06H,00H,00H;

END


菜鸟
2007-05-30 16:50:00     打赏
5楼
val = 1 << (Count - 1);请问这个语句什么意思呀,1<< 是什么命令格式呀。我看了C++里也没有这个定义方式呀。这是什么C++呀?

菜鸟
2007-06-02 06:43:00     打赏
6楼
以下是引用wangwxcui在2007-5-30 8:50:00的发言:
val = 1 << (Count - 1);请问这个语句什么意思呀,1<< 是什么命令格式呀。我看了C++里也没有这个定义方式呀。这是什么C++呀?

移位吧,知道各个寄存器如何配置,可以自己写驱动的,不是很复杂吧那种点阵液晶


菜鸟
2007-06-04 17:35:00     打赏
7楼
看着是够复杂的~

菜鸟
2007-06-12 16:53:00     打赏
8楼
问题已解决,以后有问题大家讨论哟。

共8条 1/1 1 跳转至

回复

匿名不能发帖!请先 [ 登陆 注册 ]