Intel 8085 microprocessor

JohnInTX

Joined Jun 26, 2012
4,787
If you don't have something hooked to the other input pins of PORTA, they are floating and will return an unknown value. This is considered bad practice for many reasons. Strap unused inputs to Vdd through a resistor is the preferred method. If you are not using the other ports, you can set them to output 0.
 

absf

Joined Dec 29, 2010
1,968
The 8255 is available in nMOS or CMOS versions. So it should behaves like an nMOS or CMOS inputs ie floating when NC. Unlike TTL inputs, they are normally at High when left unconnected.

Allen
 

Thread Starter

vincent19-mas

Joined Dec 27, 2012
83
If you don't have something hooked to the other input pins of PORTA, they are floating and will return an unknown value. This is considered bad practice for many reasons. Strap unused inputs to Vdd through a resistor is the preferred method. If you are not using the other ports, you can set them to output 0.
By referring to my notes, when IN PORTA, if the switch is closed, what value will the PORTA reads to the accumulator ? Is my calculation correct ?

I am pretty confused about this and also about why ANI 00000001B is there for

Hope you can explain.

Thanks !
 

Attachments

JohnInTX

Joined Jun 26, 2012
4,787
When the switch is closed, the pin will be a logic '1', when open a '0' (assuming the R is a value small enough to pull the pin down).

After IN PORTA, the accumulator value will be ???????0 or ???????1 depending on the switch. The ??????? is the other 7 bits on the port which are undetermined values because they are not connected to anything.

So, how do you determine what PA0 is? You don't have any instructions that test a single-bit in the accumulator. All you can test is the result of an arithmetic or logical instruction. In your case, you do the ANI 00000001B which does a bitwise AND on all of the bits of the accumulator and sets or clears the Z flag in PSW accordingly. Since ANDing with a 0 = 0, all of the 7 ??????? bits will be 0 after the ANI. The LSbit (connected to PA0) will be 0 or 1 depending on the switch. The result in the accumulator is 00000000 or 00000001. You use JZ or JNZ to jump based on the value of the accumulator after ANI which reflects the value at PA0.

You have the right idea.. the notes in red ask 'how about all this? 0 or 1?' Indeed! You don't know so you must use the ANI to clear the other 7 bits to 0 so that the result is Z or NZ based solely on the value of PA0. You'll find that you have to do this for any single bit inputs on any processor that does not have specific bit-test instructions (like PICs btfsc..)
 
Last edited:

Thread Starter

vincent19-mas

Joined Dec 27, 2012
83
When the switch is closed, the pin will be a logic '1', when open a '0' (assuming the R is a value small enough to pull the pin down).

After IN PORTA, the accumulator value will be ???????0 or ???????1 depending on the switch. The ??????? is the other 7 bits on the port which are undetermined values because they are not connected to anything.

So, how do you determine what PA0 is? You don't have any instructions that test a single-bit in the accumulator. All you can test is the result of an arithmetic or logical instruction. In your case, you do the ANI 00000001B which does a bitwise AND on all of the bits of the accumulator and sets or clears the Z flag in PSW accordingly. Since ANDing with a 0 = 0, all of the 7 ??????? bits will be 0 after the ANI. The LSbit (connected to PA0) will be 0 or 1 depending on the switch. The result in the accumulator is 00000000 or 00000001. You use JZ or JNZ to jump based on the value of the accumulator after ANI which reflects the value at PA0.

You have the right idea.. the notes in red ask 'how about all this? 0 or 1?' Indeed! You don't know so you must use the ANI to clear the other 7 bits to 0 so that the result is Z or NZ based solely on the value of PA0. You'll find that you have to do this for any single bit inputs on any processor that does not have specific bit-test instructions (like PICs btfsc..)
Cool ! I think I get you!

By AND-ing the content of PORTA with 00000001B will thus eliminate the floating case of the 7 bits which is not connected to anything ? It will give the 7 bits a solid 0.

Am I correct ?
 

Thread Starter

vincent19-mas

Joined Dec 27, 2012
83
You've got it!
Hey, I have a new question. Regarding the keypad, the schematic is as shown. So when I press a key, what will be the voltages when each row is shorted to ground one by one ? I do hope you understand by reading the picture. I am not really understand yet on how do I determine the voltage when the key is pressed when one of the row is grounded. Do you thin the scheematic is correct ?

Thanks !
 

Attachments

JohnInTX

Joined Jun 26, 2012
4,787
Now, respect the hardware and tie the unused inputs to ground.

You might be thinking 'If I do that, do I still need the ANI since now all of the other bits are 0?' and the answer is still yes because later when you use the other bits of the port you'll need a way to discriminate those.

For the kbd, you scan it by outputting a '1' on one of the columns then see if any of the rows are '1'. If so, you have a key pressed at that row/column. If you keep a counter of the columns 0-3 and assign row numbers 0-3 you can generate a key number 0-15 (shift the column left 2 places and OR with row number) and process that. That's roughly what your posted code is doing. Note how it uses ANI 00001111B to read the rows. Its testing multiple bits at a time i.e. ANY switch closed will cause a NZ condition. When the code finds a hot row, it proceeds to code the result as a combination of the row and column. The code is simple and doesn't account for multiple key presses (that I can discern but I just took a quick look..)

Search the forum for keyboard scanning and there are a few good discussions. Post your code ideas and we can help out there as well..

Looks like you are getting it. Well done.
 
Last edited:

MrChips

Joined Oct 2, 2009
30,806
This is a common method of reading a 4x4 matrix keypad (16 keys) using a single 8-bit port.
One-half of the port (4-bits) is configured as output while the second half (4-bits) is configured as input.

Since you cannot leave inputs floating, they must be pulled up or down through load resistors. Whether you use pull up or pull down is up to you.

What are shown in the diagram are pull down resistors.

The schematic shown is correct.
 

MrChips

Joined Oct 2, 2009
30,806
To answer your inquiry about pm, I prefer answering questions here on the forum because others can benefit from the questions & answers.
 

absf

Joined Dec 29, 2010
1,968
Hey, I have a new question. Regarding the keypad, the schematic is as shown. So when I press a key, what will be the voltages when each row is shorted to ground one by one ? I do hope you understand by reading the picture. I am not really understand yet on how do I determine the voltage when the key is pressed when one of the row is grounded. Do you thin the scheematic is correct ?

Thanks !
John has explain the way the keys are scanned on the program very well. The 8255 control register (83H) is set up so that the upper 4 bits (PC 4-7) are outputs while the lower 4 bits (PC 0-3) are inputs. The keypad can be connected to just on Port C alone.

I have placed some comments on the program so it would make you understand easier how the program works. As I dont have a 4x4 keypad on my schematics drawing program. I would do it with a 3x4 keypad for your reference...

Rich (BB code):
	CPU "8085.TBL"
	LXI  SP,3FF0H
	MVI  A,10000001B	;port c lower 4 bits inputs
	OUT  83H		;upper 4 bits outputs
SCAN:	MVI  A,01110000B	;make col 1-3 high
	OUT  82H		
	IN   82H		;read lower 4 bits 
	ANI  00001111B		;strip off row bits
	JZ   SCAN		;if no key is pressed, loop back again
	MVI  B,3		;key press detected, continue
	MVI  C,00010000B	;make column 1 high
SCAN_NEXT:	MOV  A,C	;output to KBD port
	OUT  82H
	IN   82H		;get row from port c
	ANI  00001111B		;strip off lower 4 bits		
	JZ   NEXT_COL	---+	;Any key pressed on that column?
	ORA  C		   |	;yes, logical OR the lower 4 row bits with
	STA  2100H	   |	;upper 3 column bits, store result in 2100H
	RST  1		   |
NEXT_COL:	MOV  A,C <-+	;No, adjust C to point to next column
	RLC
	MOV  C,A
	DCR  B			;Done all columns?
	JNZ  SCAN_NEXT		;Not yet, do next column
	JMP  SCAN		;Scan next key
	END
Allen
 

Attachments

JohnInTX

Joined Jun 26, 2012
4,787
Nice job, Allen and thanks for the props.

I have to admit that you and MrChips picked up the part where the command register at 83h had changed from the earlier posts to put both in and out on PORTC. I missed that so my description could have been better...

For the OP, what a perfect example of the value of commenting your code from the start.
 

Thread Starter

vincent19-mas

Joined Dec 27, 2012
83
Nice job, Allen and thanks for the props.

I have to admit that you and MrChips picked up the part where the command register at 83h had changed from the earlier posts to put both in and out on PORTC. I missed that so my description could have been better...

For the OP, what a perfect example of the value of commenting your code from the start.


Hey for this, can someone explain to me what is the 3E, 06,80 and D3 ? how do we differentiate between 1-byte instruction , 2-byte instruction and 3 byte instruction ?

Thanks !
 

absf

Joined Dec 29, 2010
1,968
Rich (BB code):
Page 1          4x4_kbd.lst

0001   0000 31 F0 3F     lxi sp,3ff0h
0002   0003 3E 81        mvi a,81h
0003   0005 D3 83        out 83h
0004   0007 3E 70       scan:  mvi a,70h
0005   0009 D3 82        out 82h
0006   000B DB 82        in 82h
0007   000D E6 0F        ani 0fh
0008   000F CA 07 00     jz scan
0009   0012 06 03        mvi b,3
0010   0014 0E 10        mvi c,10h
0011   0016 79          scan_next: mov a,c
0012   0017 D3 82        out 82h
0013   0019 DB 82        in 82h
0014   001B E6 0F        ani 0fh
0015   001D CA 25 00     jz next_col
0016   0020 B1           ora c
0017   0021 32 00 21     sta 2100h
0018   0024 CF           rst 1
0019   0025 79          next_col: mov a,c
0020   0026 07           rlc
0021   0027 4F           mov c,a
0022   0028 05           dcr b
0023   0029 CA 16 00     jz scan_next
0024   002C C3 07 00     jmp scan
0025   002F              end

Number of errors = 0
The above is the same program of your keypad scanner. I put it inside a 8085 assembler and generate the listing. As you can see some of the instructions generate 1 byte, 2 bytes and 3 bytes of hex codes.

If you are going to study 8085, it would be best to get an 8085 assembler and do some hand-on on it. I use the Oshon 8085 simulator and there's an assembler built in.

You may download an evaluation copy from Oshonsoft.com for a trial.

Allen
 

Thread Starter

vincent19-mas

Joined Dec 27, 2012
83
Rich (BB code):
Page 1          4x4_kbd.lst

0001   0000 31 F0 3F     lxi sp,3ff0h
0002   0003 3E 81        mvi a,81h
0003   0005 D3 83        out 83h
0004   0007 3E 70       scan:  mvi a,70h
0005   0009 D3 82        out 82h
0006   000B DB 82        in 82h
0007   000D E6 0F        ani 0fh
0008   000F CA 07 00     jz scan
0009   0012 06 03        mvi b,3
0010   0014 0E 10        mvi c,10h
0011   0016 79          scan_next: mov a,c
0012   0017 D3 82        out 82h
0013   0019 DB 82        in 82h
0014   001B E6 0F        ani 0fh
0015   001D CA 25 00     jz next_col
0016   0020 B1           ora c
0017   0021 32 00 21     sta 2100h
0018   0024 CF           rst 1
0019   0025 79          next_col: mov a,c
0020   0026 07           rlc
0021   0027 4F           mov c,a
0022   0028 05           dcr b
0023   0029 CA 16 00     jz scan_next
0024   002C C3 07 00     jmp scan
0025   002F              end

Number of errors = 0
The above is the same program of your keypad scanner. I put it inside a 8085 assembler and generate the listing. As you can see some of the instructions generate 1 byte, 2 bytes and 3 bytes of hex codes.

If you are going to study 8085, it would be best to get an 8085 assembler and do some hand-on on it. I use the Oshon 8085 simulator and there's an assembler built in.

You may download an evaluation copy from Oshonsoft.com for a trial.

Allen
What is the function of those software ? Can I do hardware simulation ?

Thanks
 
Hey there, I would like to ask if anyone here know about Intel 8085 chip and the assembly language ?

Need some help here.

Thanks !
It contains of Memory Programming which is consider as a next generation.
8085 have also have a high definition for enhancement..

-Intel 8085 contains single 5 Volt power supply.
-Clock oscillator and system controller were integrated on the chip.
-The CPU included serial I/O port.
-Two new instructions were added to 8085 instruction set.
 
Top