Email: Password: Remember Me | Create Account (Free)

Back to Subject List

Old thread has been locked -- no new posts accepted in this thread
???
01/14/02 17:57
Read: times


 
#18644 - RE: help in assembly code?(serial and lcd)


TING,

There are some mistakes here.
First of all don't forget that body of subroutine must be end by RET instruction.
Second, when you call H_4 there is endless loop, and code loses the DPTR value.

Try this code, I have changed it a little bit. Of course, the algorithm is up to you
only.



ORG 0
JMP MAIN

ORG 13H
SETB P2.7 ;turn on LED
MOV DPTR, #MSG1 ;load pointer for message
CALL message ;stay in loop indefinitly

MOV DPTR, #MSG2 ;load pointer for message
CALL message

JNB INT1, REC3
CLR P2.7
MOV DPTR, #MSG3 ;load pointer for message
CALL message
RETI

MAIN:
CALL INIT_LCD
CALL INIT_SERIAL
MOV IE, #10000100B ;enable external INT1

message1:
MOV DPTR, #STANDBY ;load pointer for message
next:
CLR A
MOVC A, @A+DPTR ;get the character
JZ B_1 ;if last character get out
CALL TRANS ;otherwise call transfer
CALL DATA_DISPLAY ;dispaly on LCD
INC DPTR ;next one
JMP next ;stay in loop indefinitly

B_1:
CALL RECV ;wait for data from serial port
CALL DATA_DISPLAY ;display data on lcd
JMP message1 ;stay in loop indefinitly


INIT_LCD:
MOV A, #30H ;initialize. lcd 1 lines,5*7 matrix
ACALL COMMAND ;issue command
MOV A, #0EH ;lcd on, cursor on
ACALL COMMAND ;issue command
MOV A, #01H ;clear lcd command
ACALL COMMAND ;issue command
MOV A, #06H ;shift cursor rigth
ACALL COMMAND ;issue command
MOV A, #86H ;cursor: line 1, pos.6
ACALL COMMAND ;issue command
RET

INIT_SERIAL:
MOV TMOD, #20h ;timer 1, mode 2(auto-reload)
MOV TH1, #0FDh ;9600 baud rate
MOV SCON, #50h ;8-bit,1 stop, REN enabled
SETB TR1 ;start timer 1
RET

message:
CLR A
MOVC A, @A+DPTR ;get the character
JZ eomess ;if last character get out
ACALL TRANS ;otherwise call transfer
ACALL DATA_DISPLAY ;dispaly on LCD
INC DPTR ;next one
SJMP message ;stay in loop indefinitly
eomee: ret


;serial data transfer. ACC has the data
TRANS:
MOV SBUF, A ;load the data

TRANS1:
JNB TI, TRANS1 ;stay here until last bit gone
CLR TI ;get ready for next character
RET ;return to caller

RECV: ;receive data serially in ACC
JNB RI, RECV ;wait here for character
MOV A, SBUF ;save it in ACC
CLR RI ;get ready for next character
RET ;return to caller

COMMAND:
ACALL READY ;is lcd ready
MOV P1, A ;issue command code
CLR RS ;RS=0 for command
CLR RW ;R/W=0 to write to lcd
SETB CE ;E=1 for H to L pulse
CLR CE ;E=0, latch in
RET

DATA_DISPLAY:
ACALL READY ;is lcd ready?
MOV P1, A ;issue data
SETB RS ;RS=1 for data
CLR RW ;R/W=0 to write to lcd
SETB CE ;E=1 for H to L pulse
CLR CE ;E=0, latch in
RET

;receive data serially in ACC
READY:
SETB P1.7 ;make p1.7 input port
CLR RS ;RS=0 access command reg
SETB RW ;R/W=1 read command reg

;read command reg and check busy flag
READY1:
CLR CE ;E=1 for H to L pulse
SETB CE ;E=0 H to L pulse
JB P1.7,READY1 ;stay until busy flag=0
RET

STANDBY: DB "STANDBY", 0
MSG1: DB "START RECORD", 0
MSG2: DB "FISNISH PRESS BUTTON", 0
MSG3: DB "THANK YOU", 0

END

List of 4 messages in thread
TopicAuthorDate
help in assembly code?(serial and lcd)            01/01/70 00:00      
RE: help in assembly code?(serial and lcd)            01/01/70 00:00      
RE: help in assembly code?(serial and lcd)            01/01/70 00:00      
RE: help in assembly code?(serial and lcd)            01/01/70 00:00      

Back to Subject List