这些小活动你都参加了吗?快来围观一下吧!>>
电子产品世界 » 论坛首页 » 综合技术 » 基础知识 » 有没有好心的汇编和c语言高手?

共3条 1/1 1 跳转至

有没有好心的汇编和c语言高手?

院士
2006-09-17 18:14:16     打赏
有没有好心的汇编和c语言高手?



关键词: 有没有     好心     汇编     语言     高手    

院士
2006-12-22 22:43:00     打赏
2楼
问 我最近买了个lcd,怎么都点不亮?我把使用手册和测试程序都翻烂了,调试了半个月,还没成功!
估计是我汇编和c语言功底不行,有些细节没注意到,能不能浪费您点时间帮我把这个51汇编程序给翻译成AVR上的c语言程序?
我非常感谢您的帮助!

;*********    LCD10-3V 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
1: 你用的是什么LCD?前些天我刚写了个程序16*2标准的点阵字符型,点亮LCD必须正确初始化 2: 我用的是段式的lcm1010,至于驱动程序我都快翻烂了我检查了半个月也没检查出来错误,不知是什么原因?
我身边有个人用51汇编12m晶振写的程序都可以
所以我怀疑atmega8l单片机会不会有问题,比如驱动不了,这是我猜测的
我用的是8M晶振,iccAVR编译的,使用c语言,我们这里没人用过AVR也没人用过c语言
你能不能帮个忙,我可以把lcd资料发给您,上面是他的测试程序 3: 初始化很重要的应该没什么问题啊
有电路图吗? 4: 电路图很简单的,只是一个单片机和lcdlcd的vdd--+5v
     vlcd--32k电阻---+5v
     data---portd6
     cd-----portd7
     wr-----portb0
单片机使用内部8m晶振,再就是连一个电源和gnd,另外5k电阻++5v电源接reset,单片机工作正常,我用指示灯看过,置高置低都像我预期的那样,估计是在细节方面出错 5: 你的DELAY是不是太段了,可以用长一点的时间。
6: 怎么不考虑直接将它转换成AVR的汇编程序如果这个51汇编程序没问题,怎么不考虑直接将它转换成AVR的汇编程序?两者的指令系统有很大的相似之处 7: 已经够长了吧,要求200ms,我都500ms了 8: 我建议你从硬件查起将你的发送数据的程序写成一个死循环,然后让程序全速运行,用示波器观察信号看看是否正常,如果你要详细的指导,请回应信息给我。 9: to wyaner8非常感谢您,怎么和您联系
我需要详细的指导,着急 10: 如果是用44780核心的lcd,我发的给你(c)。lcm1010我没用过 11: 谢谢!我得用段式的 12: 你可以找相关的c源程序一般LCD使用说明里会带C程序的例程!
还有就是要注意对比度就是正压负压要调整好
我也是刚开始弄了半天没显示,原来是负压调太低了
还有,写入的时序要对 13: 这些我都试过了,电源跟定没问题,因为我用别人的51单片机都行 14: 请看看我的意见这位老兄,你若有兴趣可把lcd的资料与本来用51编的那个原理图发到我e-mail里(nbshl@tom.com)!反正我这几天没事做!和现在要用AVR的原理图! 15: 看看1621!

专家
2022-08-20 17:12:26     打赏
3楼

了解一下


共3条 1/1 1 跳转至

回复

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