Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[SOLVED] Assembly learn in PIC MPLAB

Status
Not open for further replies.

vishy71

Full Member level 2
Joined
Dec 16, 2010
Messages
126
Helped
3
Reputation
6
Reaction score
3
Trophy points
1,298
Location
Iran
Activity points
2,296
Hi

let us to learn assembly in full here!

at frist plz who can answer to this question?

way use RB1 equ 0x01! what's it's mean?
and how we can known this addresses?

and how can we discribe marco in assembly!
 

Read the PIC commands in the datasheet - they may help you...
 
  • Like
Reactions: vishy71

    vishy71

    Points: 2
    Helpful Answer Positive Rating
Hi vishy,

RB1 is the 1st bit of portB, that is why it is 0x01. In assembly codes when we mention a bit of a port we need to say "Which port" and "Which bit".

As an example read the datasheet for assembly-code "bcf".
bcf PORTB,RB1 ;This means clear (assign to 0) RB1 bit in PORTB.

Now assembler knows "bcf" but not names "PORTB" and "RB1". We must assign correct values to those names. (Normally this is done in include file). Hence RB1 equ 0x01 is used to say "RB1=0x01". (Also check your include file there are values for PORTB and all other special-function-registers)

Thank you,
 
  • Like
Reactions: vishy71

    vishy71

    Points: 2
    Helpful Answer Positive Rating
It is some time since I used a PIC16 but I thought the first bit (least significant bit) of PORTB was RB0 not RB1
 
  • Like
Reactions: vishy71

    vishy71

    Points: 2
    Helpful Answer Positive Rating
Hi

thanks,I will check the include file.

---------- Post added at 11:19 ---------- Previous post was at 10:32 ----------

Hi!
I undestand!thanks!

so come to speack about marco and also retlw instrcution!

at frist please say what's the marco and how we can use it in our program!
and then how we can make a table with retlw?

thanks,thanks,thanks,thanks,thanks,thanks,thanks,thanks,thanks,thanks,thanks,thanks
 

anybody not found?
 

Hi vishy,

Macro is a code-snippet(ie. set of instructions) in MPLAB assembly ;
when we mention macro name in our code-editor, compiler will replace that macro-name with code-snippet.

Hence if we have exactly-same set-of-instructions in several places of our program, we can write a macro. So you write it only once and easy to edit. When we call macro name compiler automatically insert that set-of-instructions where macro-name is at.

To clarify more; think we have a macro which need 50Bytes in program memory. If we call that macro 4 times, it would take 200Bytes(=50 X 4)

"retlw" is used to return from a function with loading some value to WREG. (see definition on datasheets)

Thanks
 
  • Like
Reactions: vishy71

    vishy71

    Points: 2
    Helpful Answer Positive Rating
thanks

how we can make table with retlw please?!!
 

Assume we need to write "Hello" on LCD;
We store letters H,e,l,l,o on program-memory.

Table1_hello
addwf PCL, f ;Add W reg to program instruction counter, so if W is 5, program counter will advance by 5 and directly read "retlw 'o' "

retlw 'H'
retlw 'e'
retlw 'l'
retlw 'l'
retlw 'o'
retlw 0x00

We run a loop until Wreg<>0. In the loop we write letter in W register on the LCD.

Code:
CLRF counter                ;reset counter for table positioning

loop_start
INCF       counter,F        ;counter=counter+1 , table-position to be read
MOVF       counter,W        ;W=table-position to be read
CALL       Table1_hello     ;read table
XORLW      0x00             ;W=(W xor 0x00)
BTFSC      STATUS, Z        ;if above W=0 (ie. end of table)
     GOTO       exit_loop         
CALL       LCD_Char         ;if W<>0 then write W on LCD
GOTO       loop_start       ;start loop again

exit_loop                    ;end letter writing loop

So you can enter whatever the letter to be print to table and keep last retlw 0x00.

Thank you,
 
  • Like
Reactions: vishy71

    vishy71

    Points: 2
    Helpful Answer Positive Rating
wow!
thanks! it's hard to understand easily! but I try it to learn!
thanks
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top