# assembly language question

#### seesy123

Joined Mar 14, 2008
13
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 #### Markd77 Joined Sep 7, 2009 2,806 movlw datarate movwf SPBRG isit it move the address of datarate(5ch) into SPBRG or move the content of datarate into SPBRG??? Address is moved into SPBRG. #### Harrington Joined Dec 19, 2009 85 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 Rich (BB code): list p=16f887 ; this tells us what processor is executing the program Two: What library are you using this is in the form of Example Rich (BB code): #include <p16f887.inc> ; the library we are importing from 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 Rich (BB code): datarate equ 0x5c ; variable named datarate this is where you will store your datarate located acc this code at 0x5C hex 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 Rich (BB code): __CONFIG, _CPD_OFF & _CP_OFF & _WDT_OFF & _BODEN_OFF & _PWRTE_OFF & _MCLRE_ON & _INTRC_OSC_NOCLKOUT Four: Where is the start address normally this at the reset vector of the micro Example Rich (BB code): org 0x0000 ; Address of the first program instruction goto Main ; Jump to label named Main and begin execution from there Five : The Interrupt vector should be defined This is where you Interrupt Timer interrupts start from Example Rich (BB code): org 0x0004 ; Interrupt vector ; Your Interrupt handler code is situated here retfie ; the return from your interrupt code after being executed Now we look at the next lines of code which are Rich (BB code): Main : movlw datarate ; this means move the literal value into the working register so the value of datarate is moved in the working register ; working register now contains value held in datarate movwf SPBRG ; means move the contents of the working register into file register general purpose register called SPBRG ; SPBRG now contains datarate outbyte equ 20h ; your outbyte is the byte that you are sending to hyper terminal this is located at 0x20 normally general purpose registers ; start from 0x20 rxdatahi equ 21h ; Rxdatahi I'm assuming is the high MSB of your byte , word of your received info from Hyper terminal ; this is located at address 0x21 in your processor movf outbyte,w ; move the contents of general purpose register named outbyte into the working register movwf SSPBUF ; now move that value from the working register into the special purpose register named SSPBUF ; next lines of code are as follows bsf STATUS,RP0 ; select bank 1 for general purpose registers or special function registers that you now need to access btfss SSPSTAT,BF ; check to see if the BF Flag bit of special function register SSPSTAT is set ; if it is then skip the next instruction immediately below goto$-1                 ; if its not set then go back to the previous instruction this is basically a loop until the
; processor has seen this bit as set after which it then skips this line i.e "goto $-1" bcf STATUS,RP0 ; we land up at this instruction here if BF was set This means$-2 was set when we tested this bit
movf SSPBUF,w           ; now move the contents of the SSPBUF into the working register
mowf rxdatahi           ; next move the contents of the working register into the our general purpose register we defined at 0x21 hex called rxdadhi

retlw 0             ; finally return  to the original callee of this subroutine and place zero in the working register continuing from where last
;  called this set of instructions popping this method off the stack
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

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

#### Harrington

Joined Dec 19, 2009
85
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