Intel 8085 microprocessor

Discussion in 'Programmer's Corner' started by vincent19-mas, Mar 8, 2013.

  1. vincent19-mas

    Thread Starter Member

    Dec 27, 2012
    83
    1
    Hey there, I would like to ask if anyone here know about Intel 8085 chip and the assembly language ?

    Need some help here.

    Thanks !
     
  2. nigelwright7557

    Senior Member

    May 10, 2008
    487
    71
    Yes, I did a few projects with it in 1985.
    So long ago I cant remember much about it.
     
  3. MrChips

    Moderator

    Oct 2, 2009
    12,449
    3,363
    What is the question?
     
  4. vincent19-mas

    Thread Starter Member

    Dec 27, 2012
    83
    1
    Well, it is about the programming assembly code. I am not used to it :(
    Code ( (Unknown Language)):
    1. CPU"8085.TBL¡±
    2. PORTA: EQU 80H
    3. PORTB: EQU 81H
    4. PORTC: EQU 82H
    5. CTRLPORT:EQU 83H
    6.  
    7. ORG 2000H
    8. LXI SP,3FF0H
    9. [B]MVI A, 10000000B[/B]
    10. OUT CTRLPORT
    11. REPEAT: [B]MVI A, 11111110B[/B]
    12.          OUT PORT C
    13.          CALL DELAY
    14.          MVI A, 11111111B
    15.          OUT PORT C
    16.          CALL DELAY
    17.          JMP REPEAT
    18.  
    19. DELAY: MVI C,255
    20. LOOP1: MVI B,255
    21. LOOP: DCR B
    22.     JNZ LOOP
    23.     DCR C
    24.     JNZ LOOP1
    25.     RET
    26.     END
    27.  
    For this coding, I dont get the difference between the two bolded part. From what my leturer told me, the first bolded one is the configuration bits while the second one is the bit sent to the PORTA ><.

    Hope anyone can help. I am totally new to this programming :)
     
  5. MrChips

    Moderator

    Oct 2, 2009
    12,449
    3,363
    The two instructions are similar.
    What makes the difference is the next instruction following the one shown in bold.
     
  6. JohnInTX

    Moderator

    Jun 26, 2012
    2,347
    1,029
    What if any peripheral chip(s) are you using? Your addresses look like its an 8255? If so the code looks like it should work assuming the processor is up.

    The first bolded part configures the 8255 for ports A,B,and C to be regular output ports. The 8255 has several operating modes and you have to configure the ports at power up. This is one of the MODE 0 (standard IO) modes with all lines output. You only have to configure it once.

    After configuring, you just write to the ports at their IO addresses 80h-82h for ports A-C respectively.

    Since you are using the OUT instruction, the ports must be IO mapped in the hardware. The 8085 bus allows various ways to map IO but most systems use the IO space that is accessed using the IN and OUT instructions. IN and OUT set the IO-M/ pin on the processor to '1' when reading and writing. This pin is decoded by external logic to interpret the address bus as an IO (not memory address).

    So after configuring, the program toggles the LSbit of PORTC not PORTA. The MVI A,xx loads the accumulator which in turn is what gets written to the port by the OUT instruction.

    BTW: the processor starts executing at 0000h and your code starts at 2000h. If you are using some firmware monitor/loader that resides down there and you jump to the code at 2000h via the monitor, OK. If not, you should ORG the code to 0000h.

    absf, good call. It took me an episode of 'West Wing' to remember the 8255.. gettin' old.
     
    Last edited: Mar 9, 2013
  7. absf

    Senior Member

    Dec 29, 2010
    1,493
    372
    I think the 8085 is interfacing to an 8255 PPI.

    Writing 10000000B to the control register is to set Ports A, B and C to output direction and bit 7=1 means control register is in I/O mode. See datasheets attached.
     
    Last edited: Mar 9, 2013
  8. takao21203

    Distinguished Member

    Apr 28, 2012
    3,577
    463
    Learning assembler, you have to examine the instruction set and read what each instruction is doing.

    Assembler is based on putting together several instructions to do something.
     
  9. vincent19-mas

    Thread Starter Member

    Dec 27, 2012
    83
    1
    How do you know that I am using 8255 chip ? Well, so
    MVI A,10000000B <-- configuration bit for 8255 ?
    MVI A, 00000001B <--- load this value of '1' and '0' at each pins of Port A ?

     
  10. JohnInTX

    Moderator

    Jun 26, 2012
    2,347
    1,029
    Are you?

    Based on the addresses of the ports and the value written to the config register its a good guess? I thought it might be an 8155 at first but came to think the 8255 about the same time as absf did, although I was wrong first. So I win.

    MVI A,<data> doesn't do anything to the ports until you do the OUT instruction. If you read the instruction set, you'll see that OUT n copies the value of A (the accumulator) to the output port n. With IO mapped systems, all IO goes through A. (IN reads the port and the value shows up in A).

    If you are NOT using an 8255, most of this does not apply.
     
    Last edited: Mar 9, 2013
  11. vincent19-mas

    Thread Starter Member

    Dec 27, 2012
    83
    1
    Yay! I am using 8255. Oh yea, I missed that. MVI A, <data> is just loading the data at accumulator to be waited to be OUTPUT to a specific PORT right ? So at first MVI A,10000000B is loading 10000000 at accumulator. Then, OUT CTRLPORT means I am configuring the 8255 ?

    Thanks !
     
  12. JohnInTX

    Moderator

    Jun 26, 2012
    2,347
    1,029
    Yup! Like modern microcontrollers, the peripheral chips of the day (8155, 8255, 8256 etc) tried to be as flexible as possible so each one has one or more configuration registers. The programmer has to look at how the hardware is hooked up (Inputs/Outputs etc) and during the system initialization, write to all of the various config registers to set up the chips for the specific application. Its usually done once after reset and before doing anything else.

    If you look carefully at the 8255 datasheet, you'll see that the port/config addresses are specified by A1-A0 and 00=PORTA, 01=PORTB, 10=PORTC, 11=ControlWord (config). When wired up the upper bits of the address are provided by some logic (gates, PAL, GPLD etc) and when 1000 00xx is sent, this logic asserts CE/ on the 8255 but the last two bits are directly connected to the processor's IO address and are decoded by the 8255 internally so when you write to 83h (10000 11) the first 6 bits are fixed by the hardware, the last two are determined specified by the OUT instruction, in this case, the config register.

    Your config is about a simple as it gets, all outputs. If you need inputs from the SAME 8255, you'll have to change the value written to the config register to make one of the ports an input. The 8255 is a bit crude here, ports A and B have to be all the same way. Port C is split into 4 bit groups. Its incumbent on the designer not to mix I and O on the same port/group.

    Question for you - what are you using to assemble/load/debug the code?
     
    Last edited: Mar 9, 2013
  13. absf

    Senior Member

    Dec 29, 2010
    1,493
    372
    I knew the 8155 well as I have a bundle of them from OKI teletype machines. The 8155 has 256 bytes of RAM and a timer inside. And I had a hard time interfacing them to my 8085 SBC. It was transfered from breadboard to a stripboard recently...

    I only has a few (2 or 3) 8255 from old PC XT and I have made an interface board to the PC parallel port that's why I can still remember it.

    Allen
     
  14. JohnInTX

    Moderator

    Jun 26, 2012
    2,347
    1,029
    There was a time when I could roll an 8085 kernel out without looking at a datasheet. But that was with a full CAE package. You, sir, are a stud.

    Have a great weekend.
     
  15. vincent19-mas

    Thread Starter Member

    Dec 27, 2012
    83
    1
    Well, another question. What is the function on ANI 00000001B at read function there ? I am using hyper terminal in my lab..you know where can I download the simulator ?
     
  16. vincent19-mas

    Thread Starter Member

    Dec 27, 2012
    83
    1
    Oops, will post the code later..another code
     
  17. JohnInTX

    Moderator

    Jun 26, 2012
    2,347
    1,029
    IIRC ANI is And Immediate with the accumulator i.e. AND the literal operand with the (A)ccumulator. The result is left in the accumulator. In the IO context, its most useful for stripping off unused bits after an IO read e.g.

    Code ( (Unknown Language)):
    1. IN PORTC ; get 8 bit port C. Value is in accumulator
    2.  ANI 01h   ; strip all but LSbit, result in accumulator. Status flags set.
    3.  JZ   LS_BIT_WAS_0  ; Jump on accumulator==0 i.e. LSbit of portC was 0
    4.  ; continue when LSbit was 1
    5.  ; do something..
    6.  JMP done
    7.  
    8. LS_BIT_WAS_0:
    9.   execute code for when bit was 0
    10.  
    11. done:
    Writing is done similarly but since you only can write bytes, you have to do some logic by reading the current value modifying it then writing it back i.e.

    Code ( (Unknown Language)):
    1. IN PORTC ; get current value to Accumulator
    2.  ORI 80h   ; set MSbit
    3.  ANI FEh   ; clear LSbit
    4.  OUT PORT C ; write result - MSbit set, LSbit cleared, others unchanged
    This works OK but if you are serious, you should maintain a copy of the output port value in RAM, modify that then write the RAM byte to the port.

    As far as a simulator, nope. We did all of the 8085 stuff on a FutureData AMDS with a handrolled firmware monitor/debugger that talked to a terminal (like Hyperterminal)
     
    Last edited: Mar 9, 2013
  18. vincent19-mas

    Thread Starter Member

    Dec 27, 2012
    83
    1
    Code ( (Unknown Language)):
    1. CPU"8085.TBL"
    2. PORTA: EQU 80H
    3. PORTB: EQU 81H
    4. PORTC: EQU 82H
    5. CTRLPORT: EQU 83H
    6.  
    7. ORG 2000H
    8. LXI SP,3FF0H
    9. MVI A, 10010000B
    10. OUT CTRLPORT
    11.  
    12. READ: IN PORTA
    13.        ANI 00000001B
    14.        JZ REPEAT
    15.        JMP NOREPEAT
    16.  
    17.  
    18. REPEAT: MVI A, 11111100B
    19.          OUT PORTC
    20.          CALL DELAY
    21.          MVI A, 11111111B
    22.          OUT PORTC
    23.          CALL DELAY
    24.            JMP READ
    25.          
    26. NOREPEAT: MVI A, 11111110B
    27.          OUT PORTC
    28.          CALL DELAY
    29.          MVI A, 11111101B
    30.          OUT PORTC
    31.          CALL DELAY
    32.          JMP READ
    33.  
    34. DELAY: MVI C,255
    35. LOOP1: MVI B,255
    36. LOOP: DCR B
    37.     JNZ LOOP
    38.     DCR C
    39.     JNZ LOOP1
    40.     RET
    41.     END
    42.  
    Ok, by seeing to this code, whats the function of ANI 00000001B there ? and when IN PORTA, then what value will it read if a siwtch is connected to PORTA0 and the switch is closed ? What will be the value of others pins of PORTA ? Floating ?

    Thanks !
     
  19. absf

    Senior Member

    Dec 29, 2010
    1,493
    372
    Code ( (Unknown Language)):
    1. CPU"8085.TBL"
    2. PORTA: EQU 80H
    3. PORTB: EQU 81H
    4. PORTC: EQU 82H
    5. CTRLPORT: EQU 83H
    6.  
    7. ORG 2000H
    8. LXI SP,3FF0H
    9. MVI A, 10010000B
    10. OUT CTRLPORT
    11.  
    12. ;assuming switch on PA0 is active low pulled high with 10K
    13.  
    14. READ: IN PORTA          ;read port A
    15.        ANI 00000001B        ;mask off bit 1 to bit 7
    16.        JZ REPEAT        ;switch is closed, goto repeat     
    17.        JMP NOREPEAT     ;else goto norepeat
    18.  
    19. ; assuming Green LED on PB0 & red LED on PB1
    20. ; LED lighted when logic 0 is applied
    21.  
    22. REPEAT: MVI A, 11111100B    ;switch on both G & R LED  
    23.          OUT PORTC
    24.          CALL DELAY     ;for a while
    25.          MVI A, 11111111B   ;switch off both LED   
    26.          OUT PORTC
    27.          CALL DELAY     ;wait for a while      
    28.            JMP READ     ;loop back to read key
    29.          
    30. NOREPEAT: MVI A, 11111110B  ;G LED ON and R LED off
    31.          OUT PORTC
    32.          CALL DELAY     ;for a while
    33.          MVI A, 11111101B   ;G LED off and R LED on
    34.          OUT PORTC
    35.          CALL DELAY     ;for a while
    36.          JMP READ       ;loop back to read key
    37.  
    38. DELAY: MVI C,255
    39. LOOP1: MVI B,255
    40. LOOP: DCR B
    41.     JNZ LOOP
    42.     DCR C
    43.     JNZ LOOP1
    44.     RET
    45.     END
    With comments in the program, does things look clearer now?

    What the value read when a switch is closed is totally up to the way you wire the switch. It can be active low with pullup resistor or active high with pulldown R.

    Allen
     
  20. vincent19-mas

    Thread Starter Member

    Dec 27, 2012
    83
    1
    Okay, I get that. However, if I only connect one swtich to PORT A0, then pin A0 will have a value set either to 1 or 0. How about the others pin like A1 A2 A3...A7 ?will it HIGH, LOW or floating ?

    Thanks !
     
Loading...