Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Help me with 8051 Assembly code

Status
Not open for further replies.

stardust

Newbie level 1
Joined
Jun 22, 2007
Messages
1
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,303
Hi there
any one that knows assembley 8051 here?
I developed a program that lets me receive a character from terminal on serial port
compare it to the list that i have define and send message to the terminal that the character is received or is not on the list.

I need to do the same thing except that i need to be able to receive a string on a serial port and compare it with a list of string on the table ex table db: 4 'DANI' but I'm stuck.
I'll paste a code here
Thanks in advance if someone can help


ORG 0000H
LJMP MAIN

ORG 0023H
LJMP SEARCH

ORG 0030H
;;;;;;;;;;;;;;;;;
MAIN:
;;;;;;;;;;;;;;;;;

LCALL SERIAL_INIT

PRITJE: LJMP WAIT
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;;;;;;;;;;;;;;;;
SERIAL_INIT:
;;;;;;;;;;;;;;;;
MOV A,PCON
SETB ACC.7
MOV PCON,A ;SMOD=1
MOV SCON,#52H ;ENABLE TI, MODE 1
MOV TMOD,#20H ;TIMER 1, MODE 2, 8-BIT AUTO RELOAD MODE
MOV TH1,#-35 ;1200 BPS AUTO RELOAD VALUE
SETB EA ;GLOBAL INTERRUPT ENABLE
SETB ES ;SERIAL INTERRUPT ENABLE
SETB PS ;HIGH PRIORITY FOR SERIAL INTERRUPTS
SETB TR1 ;START TIMER
RET
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;TRANSMISSION OF ONE CHARACTER IN BAFER (SERIAL PORT)
;;;;;;;;;;;;;;;;
OUTCHAR:
;;;;;;;;;;;;;;;;
JNB TI,$
CLR TI
MOV SBUF,A
RET
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;READING ON SERIAL PORT
;;;;;;;;;;;;;;;;
SEARCH:
;;;;;;;;;;;;;;;;
JNB RI,EXIT
CLR RI
MOV B,SBUF
MOV DPTR,#LIST
MOV R0,#00H
MOV A,'W'

RPT: CJNE A,#00H,PROCEED
MOV DPTR,#MESSG2
LCALL MESSG1
EXIT: RETI

PROCEED: MOV A,R0
MOVC A,@A+DPTR
CJNE A,B,PROCEED1
MOV DPTR,#MESSG1
LCALL MESSG
MOV A,B
LCALL OUTCHAR
LJMP EXIT
PROCEED1: INC R0
LJMP RPT
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;


;;;;;;;;;
MESSG1:
;;;;;;;;;
MOV A,#0AH
LCALL OUTCHAR
MOV A,#0DH
LCALL OUTCHAR
MOV R1,#00H

RPT1: CJNE A,#00H,VAZHD2
RET
PROCEED2: MOV A,R1
MOVC A,@A+DPTR
LCALL OUTCHAR
INC R1
LJMP RPT1
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

LIST: DB 'A','B','C','D','E','F','G','H','I',00H
MESSG1: DB ' SEARCH COMPLETED SUCCSESFULY, CHAR FOUND : ',00H
MESsG2: DB ' THIS CHAR DOES NOT EXIST ON THE LIST',00H


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;


END
 

8051 help needed

Your code is outrageous, not mentioning the lack of comments. And as it is, it can't be assembled without errors.

Just a few hints:
- you don't want to mix interrupt-driven reception and polled transmission. Stick to one of them for both (I'd recommend you polled for starter).
- think of why MOV A,'W' has unpredictible result
- you want to present us your code as written, copy/paste. If you want to "translate" labels, do so in your original code and verify it works
- comment generously, but say your intentions, not the actions (comment like "mov a,#3 ;store 3 to accumulator" are useless)
- don't use tab character for formatting and learn how to post formatted code here (hint: look at the tags offered on top of edit window)

By the time you will arrive from something "just working" to something more readable, properly formatted, clearly commented and with clean structure, you will certainly already know how to write also the "extension". Just one hint for it: you might want to store the received characters plus the number of them into a buffer, and compare that buffer to the items in the list. But there might be other ways of course.

JW
 

Re: 8051 help needed

when posting your code, use the code tags so the code is easily readable.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top