Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

8051 assembly code interprating

Status
Not open for further replies.

novschopin

New Member
hi all, can anyone please explain every single line of these codes meaning??? thank you!!
; Fet@89c5x Integrated Development Environment (Assembly Code)

ORG 0000H
JMP MAIN
ORG 000BH
JMP T0ISR
ORG 0023H
JMP SISR

ORG 0030H
MOV R0, #12 ; motor speed on time
MOV R1, #0
MAIN: MOV SCON, #52H
MOV TMOD, #21H
MOV TH1, #-3
SETB TR1
SETB TF0
MOV IE, #10010010B

AGAIN: SETB P3.7
SETB P3.3
CLR P3.4
CLR P3.5

SCAN: CJNE R1, #20, JJ
MOV R1, #0
JMP AGAIN
JJ: MOV A, R1
MOV 22H, R0
CJNE A, 22H, J2
SETB C
J2: JC SCAN
CLR P3.7
CLR P3.3
JMP SCAN

T0ISR: CLR TR0
MOV TH0, #HIGH(-921)
MOV TL0, #LOW(-921)
INC R1
SETB TR0
RETI

SISR: CLR RI
CLR TI
MOV A, SBUF
CJNE A, #"F", N1
MOV R0, #17
RETI
N1: CJNE A, #"M", N2
MOV R0, #10
RETI
N2: CJNE A, #"S", N3
MOV R0, #4
N3: RETI

END
 
I can do that, but I want to know why you need me to do this for you. Is there some reason you can't do it for yourself?

Maybe you could focus on the parts you don't understand. Maybe you could ask some specific questions that will help you understand what is going on.

Some additional background would be helpful. A schematic diagram, a description of what is happening when the code is running, anything really.
 
hi, actually this is a motor driver design and i am not quite sure how the code works so i really need your help
if p3.7 and p3.3 are set and p3.4 and p3.5 are cleared, the motor runs forward. I hope u can explain to me about the subroutine scan, jj, j2 and maybe T0ISR,SISR,N1,N2,N3.
I would like to add the reverse feature as well by setting the p3.4 and p3.5 and clr p3.7 and clr p3.3, so i need a more understanding of this program. direction control will be controlled by external switch or input.
one more thing is that i need to make the motor runs in full speed for 5second, then half speed (half duty cycle as in this code) for 5second, and 0 speed for 5 second. So , i need more understanding in this program.
And hopefully you can help me out in programming those features too.
thank you!! pls help, really need it.
 
Not every label, such as N1, N2, and N3 is a separate routine. Labels can exist within a routine and serve as destinations for jump instructions or just markers to remind the programmer what is going on. You have explained the meaning of the port 3 bits in controlling direction.

SISR:
This is the Serial Port Interrupt Service Routine. This routine is entered via the JMP SISR instruction at location 0023H which was established by the "ORG" pseudo operation. The processor executes the instruction at address 0023H when interrupts are enabled and either the RI flag or the TI flag is set. RI and TI are bits in a special function register associated with the serial port. RI means that the serial port has received a character. TI means the serial port is ready to send another character. In this application only receive is supported.

The serial port interrupt service routine starts by clearing the two flags. It reads the character in the serial port data register, SBUF, into the accumulator. Using the "Compare Jump Not Equal" instruction it tests for the ascii characters "F", "M", and "S", which presumably stand for fast, medium, and slow. If it finds one of these three characters then it changes the value in R0 to either 17, 10, or 4. These values are connected to the speed of the motor I presume. Then in each case there is a return from interrupt instruction(RETI). If the serial port buffer contained non of these characters then the character is ignored and the return from interrupt is executed.

Your homework is to find out what clock frequency the processor is using and which specific flavor of 8051 in terms of manufacturer and model number is being used. When I know that I can tell a bit more of the story like what baud rate the serial port is using and how the timers are working.

Sound fair?
 
Papabravo said:
Your homework is to find out what clock frequency the processor is using and which specific flavor of 8051 in terms of manufacturer and model number is being used. When I know that I can tell a bit more of the story like what baud rate the serial port is using and how the timers are working.

Sound fair?
Why is that? I thought all 8051 based processors works the same way so...

What looks weird to me is that the timer stuff is a complete mixed-up:
1) Only the ISR of timer 0 is declared @ 000Bh not the one for timer 1 @ 001Bh. So one can assume that only timer 0 is used and not timer 1 :wink:
2) With "MOV TMOD, #21H" Timer 0 is used as a 16 bit timer and timer 1 as a 8 bit auto reload timer. So are both timers used :roll:
3) With "SETB TR1" wone can assume that timer 1 is used but not timer 0 because there's no "SETB TR0". Contradiction with first point... :evil:
4) ISR for timer 0 reloads a 16 bit value into the timer's SFR and start the timer with SETB TR0 :? Since it isn't started earlier, we can never enter this ISR and start the timer :roll: :twisted:

Instead of using some code found I don't know where, provide us a schematic of your hardware and we can help you with a flow chart depending on what you want to do.

You want tutorials about the 8051? Than check www.8052.com everything is well explained
 
In the almost 30 years since the 8051 first appeared there have been numerous improvements and variations. The original design had 12 clock cycles per instruction; some new ones have six. Multiplexers and dividers are used internally to give the programmer the option of using various inputs for timers and baudrate generators.

In order to know for certain what is going on you absolutely have to look at the datasheet for the specific make and model being used. Any other approach is pure folly.

I aggree the code has some weaknesses. Did you notice that the serial interrupt routine writes a value to the A register, and the A register also gets a value in the main loop. This can't be good to have two separate processes modify the same register. That way lies disaster.

The original poster would be well advised to throw this piece of crap away and develop his own robust piece of code that does what he wants it to do. In order to do that, he first has to articulate his requirements.

When he completes his homework I'll write the next installment on the use of the timers.
 
Papabravo said:
The original poster would be well advised to throw this piece of crap away and develop his own robust piece of code that does what he wants it to do. In order to do that, he first has to articulate his requirements.
Absolutely :!:
 
I guess the homework I assigned was too onerous, and articulating requirements beyond the relm of possibility.
 
Unemployment Line

I'll catch you in the unemployment line.
 
Status
Not open for further replies.

Latest threads

Back
Top