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, look up table and sending x^2 to P2

Status
Not open for further replies.

PG1995

Active Member
Hi

Please help me with the query enclosed in the attachment. Thank you.

Code:
ORG	0
		MOV	DPTR,#300H	
		MOV	A,#0FFH		
		MOV	P1,A			
BACK:	MOV	A,P1			
		MOVC	A,@A+DPTR		
		MOV	P2,A			
		SJMP	BACK			
		ORG	300H
XSQR_TABLE:
		DB	0,1,4,9,16,25,36,49,64,81
		END
 
I think I understand it a little. I will let you know if there is some problem. Thanks a lot for giving it a look. I will continue this thread with some related problem. I'm sorry that it took me a while to understand this.

Kind regards
PG
 
i am also studying 8051 microcontroller from the same book, hence if you find something interesting, please post it here. thanks
 
Last edited:
X is a binary value input from port 1, (0-9 only). It is moved to the accumulator then added to the data pointer (DPTR) The result "points" to the entry in the data table which is the square of the number inputed. That number is then output on port 2.
 
fourth line means you are making P1 as input port. that is all 1 written to P1 (as ff means 11111111)

now in 5th line, you read P1 (as it is input port) and save it in A

the MOVC instruction load the accumulator with a code byte, or constant from program memory. the address of the byte fetched is the sum of the original unsigned eight-bit accumulator contents and the contents of a sixteen-bit base register, which may be either the data pointer or the PC. in the latter case, the PC is incremented to the address of the following instruction before being added to the accumulator; otherwise the base register is not altered. sixteen-bit addition is performed so a carry-out from the low-order eight bits may propagate through higher-order bits...

now according to value of A (from input port P1) the lookup table is seen and corresponding value is sent out to port P2 which is the output port. you need not initialize a port as output port because all ports are by default output ports.
 
now according to value of A (from input port P1) the lookup table is seen and corresponding value is sent out to port P2 which is the output port. you need not initialize a port as output port because all ports are by default output ports.

This is incorrect. The ports are defaulted high/input mode.

A note on the functioning of 8051 ports. They are known as a "quasi-bidirectional" port and they operate bi-state only unlike a PIC, which is why they don't have a tristate register (TRIS) to turn the port output drivers on/off. The ports are either in a high or a low state. When port pins are driven high by writing 1's to them, the pin is set to 5V and is high impedance so can function as either an input or an output depending on what hardware is on the pin. However, when port pins are driven low by writing 0's to it, the pin is set to 0V and is low impedance. When in the low state, the pin will function as output only as there is no way to externally drive a low pin high.
 
read this
**broken link removed**

there and in all books i have read, default mode is output. :confused:
 
read this
**broken link removed**

there and in all books i have read, default mode is output. :confused:

Again...they are a quasi-bidirectional design. There is no "input/output" mode like some describe it. There is no TRIS register to turn the port output drivers on/off. They're not a tri-state design like a PIC.

The 8051 port pins have a strong internal active pull-down with a weak internal pull up that is either passive (NMOS designs) or active (CMOS designs). This is why it can sink 15mA but only sources about 200nA. When 0's are written to a pin, the active pull down is turned on, thus pulling the pin low and the pin can only function as an output when in the low state. When writing 1's to a pin, the active pull down is turned off and the weak internal pull up pulls the pin to a high state, where it can function as either an input or an output.

Believe it or not, if you set up PORTB on a PIC to input mode (or any port with weak pull ups), clear the PORT register, and turn on the weak internal pull ups, you can make the port work just like an 8051 port by toggling the bits in the TRIS register instead of the PORT register (read instructions would have to address the PORT registers though for reading inputs).

Port 0 however is open drain. There is no internal pull up on port 0 so the two states are "high impedance" and "low". You must use an external pull up on port 0 pins in order to pull them high when 1's are written to their pins.

The default state of all ports on power up or reset is all 1's written to the ports (active internal pull downs in the "off" state). Not sure why the link above states otherwise but it is simply incorrect.
 
Last edited:
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top