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.

[PIC] Assembly Language in MplabX

Status
Not open for further replies.

Praveen Kumar P S

Member level 4
Joined
Aug 21, 2014
Messages
79
Helped
1
Reputation
2
Reaction score
1
Trophy points
8
Location
India
Activity points
627
Hello guys ..
I have started using asm language for the first time...i m completely new to asm, mpasm and mplabx...

i tried some code which i got from google....
here is the code:::
Code:
list p=16f877a
org 0x00                          ; start at address 0
                                       ; At startup, all ports are inputs.
                                       ; Set Port B to all outputs.
fin:
movlw B'00000000'          ; w := binary 00000000
tris 5                               ; copy w to port B control reg
                                     ; Put a 1 in the lowest bit of port B.
movlw B'00000001'         ; w := binary 00000001
movwf 6                         ; copy w to port B itself
                                     ; Stop by going into an endless loop
goto fin
end

The code build sucessfully....but when i tried to _config it, shows a lot of errors..
also the above code build sucessfully...but with warning messages....

Code:
"C:\Program Files (x86)\Microchip\MPLABX\mpasmx\mpasmx.exe" -d__DEBUG -q -p16f877a -l"build/default/debug/led.lst" -e"build/default/debug/led.err" -o"build/default/debug/led.o" "led.asm" 
Warning[205] E:\PROJECT\MPLABX\INITAL\LED.ASM 1 : Found directive in column 1. (list)
Warning[205] E:\PROJECT\MPLABX\INITAL\LED.ASM 2 : Found directive in column 1. (org)
Warning[203] E:\PROJECT\MPLABX\INITAL\LED.ASM 6 : Found opcode in column 1. (movlw)
Warning[203] E:\PROJECT\MPLABX\INITAL\LED.ASM 7 : Found opcode in column 1. (tris)
Warning[224] E:\PROJECT\MPLABX\INITAL\LED.ASM 7 : Use of this instruction is not recommended.
Warning[203] E:\PROJECT\MPLABX\INITAL\LED.ASM 10 : Found opcode in column 1. (movlw)
Warning[203] E:\PROJECT\MPLABX\INITAL\LED.ASM 11 : Found opcode in column 1. (movwf)
Warning[203] E:\PROJECT\MPLABX\INITAL\LED.ASM 13 : Found opcode in column 1. (goto)
Warning[205] E:\PROJECT\MPLABX\INITAL\LED.ASM 14 : Found directive in column 1. (end)

PLz help me guys.....

Thank You..
 

I didn't see where you configure your outputs. The error "Find directive on first column" means there should always be space in newline before typing.

Code:
      List p=16F877A
   #include <P16F877A.INC>

    BSF 03,5 ; bank1 to configure outputs
    CLRF TRISA.  ; make PORTA output
   CLRF TRISB. ; make trisb output
    BCF 03,5 ; switch to Bank0

Start
    Movlw b'00000001'
   Movwf PORTB 
  Goto start ; endless loop

 End

Hope this help

Competition is the Best driver to success and knowledge
 
The code you found was probably the worst example of PIC assembly language I've ever seen!

As Pulsetronics stated, MPASM (the assembler part of MPLABX) is strict about the presentation of each line. The rules are:
1. A label (a named place that you can use as a target for a jump instruction) MUST be in the first column of a line,
2. An instruction must NOT be in the first column of a line. Common practice is to add a tab or a few spaces to line the instructions up and make it look neat.

In the code itself, the instruction 'tris' gave a warning because it is no longer needed and a more consistent way of addressing the TRIS registers exists. Historically, the first PIC processors needed the instruction but you can achieve the same result by writing directly to the TRIS register in the same way you write to any of the other ones. The other bad example in the code is the use of register and bit numbers instead of using their names. It makes for very confusing code, the names of all the registers and the bits inside them are defined in the 16F877A header file which should be included automatically when you started the project.

For example:
Code:
movwf 6            ;move the value in W to file register 6
is more clear if written like this
Code:
movwf PORTB     ;move the value in W to PORT B

Note that the code won't work anyway! The TRIS and PORT registers are wrong, you need to select bank 1 to access the TRIS registers and bank 0 to select the ports. It's easy to do, just add
Code:
banksel x
before you access the register. 'x' is the bank number or to make it even easier, you can use the register name itself like this:
Code:
banksel PORTB
.

Brian.
 
Hello guys...

i got a lot from above post and made my own program..
Here is my new program::

Code:
           processor 16f877a
           include <p16f877a.inc>
           __config _XT_OSC & _WDT_OFF & _PWRTE_ON

           org 0x00                        ; start at address 0

fin:

           movlw      b'00000000'          ;mov bin 000000000 to w reg
           banksel    TRISC                ;select bank containing TRISC
           movwf      TRISC                ;select trisc as o/p
           banksel    PORTC                ;sel bank containing PORTC

           movlw      b'11111111'          ;mov bin 111111111 to w reg
           movwf      PORTC                ;set all output pin of poetc high
           goto       fin                  ;infinate loop

           nop
           end

but when i tried this own a real hardware, all port C pins remain low....could anyone say where i m wrong....????
also, plz help me with a good reference for asm language..

Thank You...
 

That code is correct and should work. I suspect you have not initialized something or you have a hardware problem. Check the clock is running and MCLR is at VDD voltage. Make sure you connect all the VSS and VDD pins and you added a capacitor across VSS and VDD as close to the PIC as possible.

You can make the program even simpler! To make all the bits of TRISC equal to zero you can use the instruction 'clrf TRISC' then you can remove the first line of your instructions.

Brian.
 

try this
Code:
processor 16f877a
           include <p16f877a.inc>
           __config _XT_OSC & _WDT_OFF & _PWRTE_ON

           org 0x00                        ; start at address 0

           movlw      b'00000000'          ;mov bin 000000000 to w reg
           banksel    TRISC                ;select bank containing TRISC
           movwf      TRISC                ;select trisc as o/p
           banksel    PORTC                ;sel bank containing PORTC


fin:

           movlw      b'11111111'          ;mov bin 111111111 to w reg
           movwf      PORTC                ;set all output pin of poRtc high
           goto       fin                  ;infinate loop

           nop
           end

try connect pin1 of PIC16F877A to VDD via a pull up resistor 10k.
 

Hello guys...

i got a lot from above post and made my own program..
Here is my new program::

Code:
           processor 16f877a
           include <p16f877a.inc>
           __config _XT_OSC & _WDT_OFF & _PWRTE_ON

           org 0x00                        ; start at address 0

fin:

           movlw      b'00000000'          ;mov bin 000000000 to w reg
           banksel    TRISC                ;select bank containing TRISC
           movwf      TRISC                ;select trisc as o/p
           banksel    PORTC                ;sel bank containing PORTC

           movlw      b'11111111'          ;mov bin 111111111 to w reg
           movwf      PORTC                ;set all output pin of poetc high
           goto       fin                  ;infinate loop

           nop
           end

but when i tried this own a real hardware, all port C pins remain low....could anyone say where i m wrong....????
also, plz help me with a good reference for asm language..

Thank You...

Go to http://www.winpicprog.co.uk/pic_tutorial.htm
it has one of the largest and best asm tutorials
 
Last edited:

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top