Connect with us

assembly program for 8051

Discussion in 'Microcontrollers, Programming and IoT' started by vead, Sep 28, 2013.

Scroll to continue with content
  1. vead

    vead

    473
    14
    Nov 27, 2011
    I want to learn how to write statement for input and output pins
    2 LED connected to PINS P01 and P02
    2 SWITCH connected to PINS P11 and P12

    how to write statement for input and output pin in assembly
     
  2. Harald Kapp

    Harald Kapp Moderator Moderator

    11,794
    2,749
    Nov 17, 2011
    If you want to write assembly language code for any microcontroller, you need to get acquainted with the mnemonics and the syntax of the particular microcontroller. You will find all that in the manual of the controller.
    You need to get that manual. It is my opinion that you will not come far without it.

    The 8051 uses MOV instructions to move data from and to ports. Here is a tutorial.
     
  3. vead

    vead

    473
    14
    Nov 27, 2011
    thanks for reply i have read this, in this tutorial shown how to make port as input but not shown how to make port as output
    i have read some where to make port as input we write
    MOV A; #FFh
    MOV P1; A
    If it is correct how to make statement for output port
     
  4. brevor

    brevor

    87
    16
    Apr 9, 2013
    With an 8051 you dont "make a statement for an output port" it is quasi bidirectional. You need to read the databook concerning port reads and writes.
    It would be MOV P1,A
     
  5. KrisBlueNZ

    KrisBlueNZ Sadly passed away in 2015

    8,393
    1,271
    Nov 28, 2011
    The standard 8051's digital I/O ports are "quasi-bidirectional" and are not explicitly configured for either input or output. There is no data direction register or tri-state control register as there is on most other microcontrollers.

    Each port has an output register and an input register. When you set a bit in the output register to 1, the corresponding pin goes high but is only pulled high weakly (this is called a "weak pullup"). External circuitry (such as a pushbutton connected from the pin to GND/VSS) can then pull that pin low, and the pin state can be read on the input register.

    When you set a bit in the output register to 0, the corresponding pin goes low with a strong pull-down, and cannot be used for input. For this reason, pins that are used for output functions are normally arranged to be active low, and loads (e.g. LEDs) are normally connected from VCC to the pin.

    Edit: Port 0 (if present) does not have weak pullups.

    Edit2: The read-only input register and the write-only output register are actually accessed through the same location in the SFR (special function register) address space. The port registers are directly bit-addressable using the 8051's bit-processing instructions (CLR bit to drive the pin low, SETB bit to set it high so it can be used for input, and MOV C,bit to read the state of the pin).
     
    Last edited: Sep 29, 2013
  6. vead

    vead

    473
    14
    Nov 27, 2011
    ok i am trying to write code please correct me if i am wrong
     
  7. KrisBlueNZ

    KrisBlueNZ Sadly passed away in 2015

    8,393
    1,271
    Nov 28, 2011
    Last edited: Sep 29, 2013
  8. vead

    vead

    473
    14
    Nov 27, 2011
    this statement is correct or wrong
    HTML:
     ORG 00H             ;Start from 000
    MOV  P0,#0FFH              ; load value FFH in to P0 as input port  
    MOV  P1,#00H                ; load value 00H into P1 as output port
    
     
  9. KrisBlueNZ

    KrisBlueNZ Sadly passed away in 2015

    8,393
    1,271
    Nov 28, 2011
    Wrong.

    1. It's better to use the 8051's bit manipulation instructions on the ports instead of reading and writing whole 8-bit bytes from/to them. The syntax for referencing bits in SFRs is different for different assemblers. What assembler are you using?

    2. You haven't shown a schematic, but from your description, I don't think you've connected the switch and the LED(s) correctly. Post a schematic.

    3. You have limited value as a hardware or software engineer if you are not able to (or worse, don't even try to) answer your questions through your own research and prior knowledge. The information you need is all freely accessible on the internet. Start by learning about the following topics (Google them): MOSFET switch, open-drain output, weak pullup, active-low, quasi-bidirectional. (These terms all come from the 8051 data sheet and tutorials. Whenever you find unfamiliar terms in a data sheet, Google them. D'oh!) Then read the 8051 tutorials and the data sheet (mainly the data sheet) and make sure you understand everything in there. If you don't understand something... you know what do do, right?
     
    Last edited: Oct 1, 2013
Ask a Question
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.
Electronics Point Logo
Continue to site
Quote of the day

-