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.

[SOLVED] Problem Reading Memory Addressed input port 8031/8051

Status
Not open for further replies.

3BABY

Member level 5
Joined
Jan 14, 2011
Messages
91
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,286
Location
New Zealand
Activity points
2,252
Hi Guys,

so ive been putting together a 8031/8051 system on a breadboard with external PROM and going to be using external RAM, i can write to an External Memory address (by way of latch) and display the value on 8 LEDs no problem, the problem i have is i want to read an 8 bit value from a memory addresses input and then move that value to the 8bit memory addressed output port just to verify everything is working, my input port is a 74LS244 (there is only one 74LS244 attached to the RD line so i dont need any Read address decoding at the moment) so on reset whatever value i have sitting at the 74244 (0x01) is displayed on the output port.. but while the program is running if i change the value on the input 74244 i does not change the on the output port.. if i hit reset on the uC the value changes but will not change dynamicly iwhile the loop is running.. i have hooked up the logic analyzer to the WR, RD and Data 0-1 lines and it looks like it reads the input port only once and then doesnt read it again even though its going around the loop in code to read and then write.. please see below.

any help would be much appreciated

Code:
;test input port
	L1:
		MOV DPTR,#0xFF01
		MOVX A,@DPTR
		MOV R4, A

	
		MOV DPTR,#101h		; writes the byte that was read out to 0x101
		MOVX @DPTR,A
		
		NOP
		CJNE R4, #01h, L1

start1:

**broken link removed**
 

whats the CJNE for ? Shouldn't you be doing an unconditional Jmp if you want to output ANY value read ?
What happens if A <> 01 ?

cheers!
:)
 

whats the CJNE for ? Shouldn't you be doing an unconditional Jmp if you want to output ANY value read ?
What happens if A <> 01 ?

cheers!
:)

Hi there,

thanks for the reply, the CJNE will compare R4 to the value 0x01 and Jump to the below code "start1:" etc if R4 is equal to 0x01 if not it will jump to L1: (and test the input port again) is this correct (sorry a little new to 8051 assembly) or am i jumping to relative address of "L1:" if R4 matches the value of 0x01 ?

CJNE Rn,#data,rel - Compare immediate to register and Jump if Not Equal


blow should write the value that was read in straight back out ..
Code:
		MOV DPTR,#101h		; writes the byte that was read out to 0x101
		MOVX @DPTR,A
 

Yes of course. Thats obvious.
My point is ... what happens at Start1 ? There's no code shown.

Your code will go right away to Start1 if your initial value at your '244 is 01.
So if there's no further MOVX there, then you WILL get only 1 RD pulse

Have you tried putting a NON - #01 input to your '244 to see what happens ?
 

Yes of course. Thats obvious.
My point is ... what happens at Start1 ? There's no code shown.

Your code will go right away to Start1 if your initial value at your '244 is 01.
So if there's no further MOVX there, then you WILL get only 1 RD pulse

Have you tried putting a NON - #01 input to your '244 to see what happens ?


HI,

yes sorry there is code below Start1: i just didnt put it above as it had no relevance to the problem, (basically just moves onto flash some lights on that same output port so i can see that the program has gotten past the first loop if the input was 0x01 - there is no further user input to the program after the first loop)

i have tried putting a non 0x01 value into the input port and it shows on the output port (upon power up reset) but if i change this value while the unit is running the output port does not change to represent this, if i hit reset the new value appears on the output port.. the weird thing is even if i power on with 0x01 loaded on the input port the program still doesn't go on to Start1:
 
Last edited:

Hmmm..... i suspect that ALL of your observations are explainable very easily. But without a look at your full code its hard to predict exactly where the problem is.

However do note that a 'power-on' reset, and a 'reset' are different beasties. At power on during voltage ramp-up strange things can happen, especially within the few uSecs that your code runs. E.g. your '244 may still be in a transient state when your uC does its 1st read of the port. A delay loop of a few mSecs at power-up might solve that. Depends on your power supply chain.

2nd... why the choice of FF01 and 0101 as the addresses ? That 01 in the LSbyte is suspicious & might be causing some trouble.

Also, if "there's no further user input after....", then how will it ever LED-flash anything except 01 ?!?

Lastly - how about a look at your test circuit ?

cheers!
:)
 
  • Like
Reactions: 3BABY

    3BABY

    Points: 2
    Helpful Answer Positive Rating
Hmmm..... i suspect that ALL of your observations are explainable very easily. But without a look at your full code its hard to predict exactly where the problem is.

However do note that a 'power-on' reset, and a 'reset' are different beasties. At power on during voltage ramp-up strange things can happen, especially within the few uSecs that your code runs. E.g. your '244 may still be in a transient state when your uC does its 1st read of the port. A delay loop of a few mSecs at power-up might solve that. Depends on your power supply chain.

2nd... why the choice of FF01 and 0101 as the addresses ? That 01 in the LSbyte is suspicious & might be causing some trouble.

Also, if "there's no further user input after....", then how will it ever LED-flash anything except 01 ?!?

Lastly - how about a look at your test circuit ?

cheers!
:)

ok so if i flick the power switch and then hold reset for a second or two and the take my finger off i get the above exibit.

address FF01 and 0101 are explained like this: i want the input ports (all the ones i plan to address in the upper 255bits of address range so i chose FF01 as my first (yes i know FF00 would have been the correct choice for the "first" but hey), this was for the reason that it will be easy for me to decode later when i put in some SRAM memory, output to 0101 was again just easy for me to do some decoding.. to be honest i dont even need any decoding but im planning ahead a little.. any RD or WR strobe is connected only to those two I/O ports at the moment. ( i have tested output port for days and its ok)

the test circuit is almost exactly like **broken link removed** except for the GAL device im using a 74138 as my decode to my WR strobe (which is working and tested) and i dont have any address decoding on the RD strobe.. its a very basic skeleton circuit at the moment.. i will draw a schematic if you like.. but its really very text book easy

below you will see full code, nothing exciting

Code:
ORG 0x00

mov 0x81, #70h


MOV A,#05h
MOV DPTR,#101h
MOVX @DPTR,A
;register 0x101 cleared


;test input port
	L1:
		MOV DPTR,#0xFF01
		MOVX A,@DPTR
		MOV R4, A

	
		MOV DPTR,#101h		; writes the byte that was read out to 0x101
		MOVX @DPTR,A
		
		NOP
		CJNE R4, #01h, L1

start1:
again1:


NOP
MOV A,#01010101b
MOV DPTR,#102h
MOVX @DPTR,A
NOP
acall delay400ms

NOP
MOV A,#10101010b
MOV DPTR,#102h
MOVX @DPTR,A
NOP
acall delay400ms


sjmp again1

ORG 0x3F3
delay400ms:
MOV R6,#0x00
MOV R7,#0xFF
delay1_1:
sjmp delay1
delay1_2:
DJNZ R7,delay1_1
ret
delay1:
DJNZ r6,delay1
sjmp delay1_2

- - - Updated - - -

can i see the problem ?

Code:
MOV DPTR,#102h


btw i havnt implemented output address 102 in hardware yet, i just used it to verify my WR decoding was working... i will check this when i get home.. i guess the rest of the code had the most relevance ... 8-O
 
Last edited:

umm... strange.

My last one... i STRONGLY suggest you make the CJNE into an SJMP (hard loop), and see what happens. Should set you on the right path imo.

cheers!
:)
 
  • Like
Reactions: 3BABY

    3BABY

    Points: 2
    Helpful Answer Positive Rating
umm... strange.

My last one... i STRONGLY suggest you make the CJNE into an SJMP (hard loop), and see what happens. Should set you on the right path imo.

cheers!
:)

Thanks rohitkhanna (sorry about the late reply).. i will look into CJNE to SJMP , changed MOV DPTR,#102h to #101h and works great now.. i guess thats what i get for copy/paste my old test code and not checking it enough.. thanks for your help!!
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top