assembly language question

Discussion in 'Programmer's Corner' started by seesy123, Jun 10, 2010.

  1. seesy123

    Thread Starter Member

    Mar 14, 2008
    13
    0
    datarate equ 5ch

    movlw datarate
    movwf SPBRG

    isit it move the address of datarate(5ch) into SPBRG or move the content of datarate into SPBRG???

    another question
    i using hyperterminal communicate with PIC16f873..so how to write the programming for it..i got an example but cant understand

    outbyte equ 20h
    rxdatahi equ 21h

    movf outbyte,w
    movwf SSPBUF
    bsf STATUS,RP0
    btfss SSPSTAT,BF
    goto $-1
    bcf STATUS,RP0
    movf SSPBUF,w
    mowf rxdatahi
    retlw 0

    anyone can explain it ???thanks
     
  2. Markd77

    Senior Member

    Sep 7, 2009
    2,803
    594
    Address is moved into SPBRG.
     
    seesy123 likes this.
  3. Harrington

    New Member

    Dec 19, 2009
    86
    3
    The code Doesn't actually make any real sense as we cant see all the coding still here is an explanation of what it does and also what you need to place in the forum before you can really ask these questions so that we can help you if we can that is

    First of all there is no initial directive which tells you what processor you are using

    Need to know this first ??

    Example

    Code ( (Unknown Language)):
    1.  
    2.  
    3. list p=16f887 ; this tells us what processor is executing the program
    4.  
    5.  
    Two: What library are you using this is in the form of
    Example
    Code ( (Unknown Language)):
    1.  
    2.  
    3. #include <p16f887.inc> ; the library we are importing from
    4.  
    5.  
    Two A : Next we define what general purpose registers you want these begin depending on the processor that you have Starting normally at 0x20 hex but you need to check up on the devices datasheet that you are using


    This is defined by the following line of code

    Code ( (Unknown Language)):
    1.  
    2.  
    3.  
    4. datarate equ 0x5c ;  variable named datarate this is where you will store your datarate located acc this code at 0x5C hex
    5.  
    6.  
    Three : We need a configuration word for the processor we are using
    This sets the internal fuses so that we can decide external clock internal RC Watchdog timer On / Off Code protect on or off etc
    Example

    Code ( (Unknown Language)):
    1.  
    2.  
    3. __CONFIG, _CPD_OFF & _CP_OFF  & _WDT_OFF & _BODEN_OFF & _PWRTE_OFF  & _MCLRE_ON & _INTRC_OSC_NOCLKOUT
    4.  
    5.  
    Four: Where is the start address normally this at the reset vector of the micro

    Example
    Code ( (Unknown Language)):
    1.  
    2.  
    3. org     0x0000          ; Address of the first program instruction
    4. goto Main  ;  Jump to label named Main and begin execution from there
    5.  
    6.  
    Five : The Interrupt vector should be defined This is where you Interrupt Timer interrupts start from

    Example

    Code ( (Unknown Language)):
    1.  
    2.  
    3. org         0x0004          ; Interrupt vector
    4.  
    5. ; Your Interrupt handler code is situated here
    6.  
    7.  
    8. retfie  ; the return from your interrupt code after being executed
    9.  
    10.  
    11.  
    Now we look at the next lines of code which are

    Code ( (Unknown Language)):
    1.  
    2.  
    3. Main :
    4.  
    5.     movlw datarate  ; this means move the literal value into the working     register so the value of datarate is moved in the working register
    6.         ; working register now contains value held in datarate
    7.  
    8.     movwf SPBRG    ; means move the contents of the working register into file register general purpose register called SPBRG
    9.             ; SPBRG now contains datarate
    10.  
    11.  
    12.     outbyte equ 20h     ; your outbyte is the byte that you are sending to hyper terminal this is located at 0x20 normally general purpose registers
    13.                 ; start from 0x20
    14.     rxdatahi equ 21h    ; Rxdatahi I'm assuming is the high MSB of your byte  , word of your received info  from Hyper terminal
    15.                 ; this is located at address 0x21 in your processor
    16.  
    17.     movf outbyte,w        ; move the contents of general purpose register named outbyte into the working register
    18.     movwf SSPBUF        ; now move that value from the working register into the special purpose register  named SSPBUF
    19.  
    20.  
    21.        ; next lines of code are as follows
    22.  
    23.        bsf STATUS,RP0        ; select bank 1 for general purpose registers or special function registers that you now need to access
    24.        btfss SSPSTAT,BF         ; check to see if  the BF Flag bit of special function register SSPSTAT is set
    25.                  ; if it is then skip the next instruction immediately  below
    26.        goto $-1                 ; if its not set then go back to the previous instruction this is basically a loop until the
    27.                  ; processor has seen this bit as set after which it then skips this line i.e "goto $-1"
    28.  
    29.            bcf STATUS,RP0        ; we land up at this instruction here if BF was set This means $-2 was set when we tested this bit
    30.     movf SSPBUF,w           ; now move the contents of the SSPBUF into the working register
    31.     mowf rxdatahi           ; next move the contents of the working register into the our general purpose register we defined at 0x21 hex called rxdadhi
    32.  
    33.  
    34.     retlw 0             ; finally return  to the original callee of this subroutine and place zero in the working register continuing from where last
    35.                 ;  called this set of instructions popping this method off the stack
    36.  
    37.  
    Hope that explains this to you but this should all be outlined at any rate inside your Datasheet and your processors instructions, mnemonics and how to use them

    Suggested further reading

    http://picprojects.org.uk/projects/pictips.htm
     
  4. Harrington

    New Member

    Dec 19, 2009
    86
    3
    Would you also believe that one of my bosses say's I'm practically unemployable as I'm to old I have to laugh really really hard at this

    Age 46 and I can still do this and better Just shows you doesn't it put your mind to it You can do anything you want in life
     
Loading...