Author Topic: Some few error in Assembly Language  (Read 7352 times)

0 Members and 1 Guest are viewing this topic.

Offline tahmodTopic starter

  • Contributor
  • Posts: 31
Some few error in Assembly Language
« on: March 10, 2013, 01:02:11 pm »
Dont know where they are and I dont know how to solve my error?

#include <pl8f87j11.inc>

      org 0
init: clrf TRISD
      movlw 0x55
      movwf LATD
      bsf TRISB,0

statel: clrf LATD
      btfsc PORTB,0
      bra $-2
      btfss PORTB,0
      bra $-2

state2: movlw 0xaa
      movwf LATD

      btfsc PORTB,0
      bra $-2
      btfss PORTB,0
      bra $-2

      bra statel
      end

« Last Edit: April 07, 2013, 08:03:34 pm by tahmod »
 

Offline AlfBaz

  • Super Contributor
  • ***
  • Posts: 2184
  • Country: au
Re: Some few error in Assembly Language
« Reply #1 on: March 10, 2013, 01:21:28 pm »
Looks like you spelt the include file wrong, you wrote PL8... I think it should be p18f...that's why the first error says file not found
 

Offline TerraHertz

  • Super Contributor
  • ***
  • Posts: 3958
  • Country: au
  • Why shouldn't we question everything?
    • It's not really a Blog
Re: Some few error in Assembly Language
« Reply #2 on: March 10, 2013, 01:22:06 pm »
Seriously?
The first error is: Cannot open file (Include File "pl8f87j11.inc" not found)
Your include file, which presumably defines all the symbols you reference, isn't there.
Poor assembler has no idea what your code is talking about.

Tell it where pl8f87j11.inc is, and things will be a lot different.

Edit: And AlfBaz is probably right.
« Last Edit: March 10, 2013, 01:24:00 pm by TerraHertz »
Collecting old scopes, logic analyzers, and unfinished projects. http://everist.org
 

Offline tahmodTopic starter

  • Contributor
  • Posts: 31
Re: Some few error in Assembly Language
« Reply #3 on: March 10, 2013, 01:26:21 pm »
I have change the name of the PIC to PIC18F87J11

« Last Edit: April 07, 2013, 08:04:01 pm by tahmod »
 

Offline TerraHertz

  • Super Contributor
  • ***
  • Posts: 3958
  • Country: au
  • Why shouldn't we question everything?
    • It's not really a Blog
Re: Some few error in Assembly Language
« Reply #4 on: March 10, 2013, 01:32:26 pm »
Actually, the most important lesson here is that in assembly programming, one error can cause a huge cascade of compounding errors. Don't let yourself get overwhelmed by the bulk of secondary errors. Look for the initial cause, ignore everything else, and fix the initial problem. Then try again.

In this case, your run is STILL not finding the include file.
Look for the file yourself. Identify where it is, and make sure the assembler can find it. Maybe it's the l/I/1 substitution thing, or maybe you need to set a pathname somewhere.
« Last Edit: March 10, 2013, 01:35:31 pm by TerraHertz »
Collecting old scopes, logic analyzers, and unfinished projects. http://everist.org
 

Offline HackedFridgeMagnet

  • Super Contributor
  • ***
  • Posts: 2028
  • Country: au
Re: Some few error in Assembly Language
« Reply #5 on: March 10, 2013, 01:43:53 pm »
Yeah the trick is the look at the first compiler/assembler error. If it's an include then dont even look at the other errors because they were probably caused by the missing include file.
In your project somewhere you should set your library directories to the directory that contains the missing include file.

Also watch the path names, some compilers and maybe some assemblers don't like spaces or some characters (. or &) in path names.

So dont run your project or libraries from "C:\USERS\AHMAD\DOCUMENTS\TAHIR\1. MPLAB\PROJECT 4 INPUT&OUTPUT\" unless you know the assembler will be happy with it.

That said the assembler didn't seem unhappy with the path.
 

Offline mariush

  • Super Contributor
  • ***
  • Posts: 5029
  • Country: ro
  • .
Re: Some few error in Assembly Language
« Reply #6 on: March 10, 2013, 01:45:25 pm »
#include <pl8f87j11.inc>

You have a typo there... it probably isn't  PL , change that to  p1

That's the reason you have below

Executing: "C:\Program Files (x86)\Microchip\MPASM Suite\MPASMWIN.exe" /q /p18F87J11 "project 4.asm" /l"project 4.lst" /e"project 4.err" /d__DEBUG=1
Error[105]   C:\USERS\AHMAD\DOCUMENTS\TAHIR\1. MPLAB\PROJECT 4 INPUT&OUTPUT\PROJECT 4.ASM 1 : Cannot open file (Include File "pl8f87j11.inc" not found)  <--- you see the PL there? it should be P1, change in your asm file right at the beginning.




 

Offline tahmodTopic starter

  • Contributor
  • Posts: 31
Re: Some few error in Assembly Language
« Reply #7 on: March 10, 2013, 01:57:25 pm »
Actually, the most important lesson here is that in assembly programming, one error can cause a huge cascade of compounding errors. Don't let yourself get overwhelmed by the bulk of secondary errors. Look for the initial cause, ignore everything else, and fix the initial problem. Then try again.

In this case, your run is STILL not finding the include file.
Look for the file yourself. Identify where it is, and make sure the assembler can find it. Maybe it's the l/I/1 substitution thing, or maybe you need to set a pathname somewhere.
-I don’t know how to look for the file and identify where it is? Can you tell me some direction in the c file of the MPlab program the file is present?
-AlfBaz, TerraHertz  and mariush it was the 1 the problem thanks


-I have still two problem, it says this after I press the button build in
http://postimage.org/image/ulnicj2sx/
-In the tutorial they say to “the oscillator set to internal but there are two type of interna, which one you need to choose
Here a picture
http://tinypic.com/view.php?pic=2najr0o&s=6
« Last Edit: March 10, 2013, 02:12:10 pm by tahmod »
 

Offline mariush

  • Super Contributor
  • ***
  • Posts: 5029
  • Country: ro
  • .
Re: Some few error in Assembly Language
« Reply #8 on: March 10, 2013, 02:16:50 pm »
-I have still two problem, it says this after I press the button build in
http://postimage.org/image/ulnicj2sx/
-In the tutorial they say to “the oscillator set to internal but there are two type of interna, which one you need to choose
Here a picture http://tinypic.com/r/2najr0o/6

read the datasheet for that pic controller, it will say there how to disable the bit that enables the extended instruction set :

http://ww1.microchip.com/downloads/en/DeviceDoc/39778e.pdf

In particular, you're looking for  page 331 and onwards, 25.0 SPECIAL FEATURES OF THE CPU

The bit you need to set is (page 333):

XINST: Extended Instruction Set Enable bit
1 = Instruction set extension and Indexed Addressing mode are enabled
0 = Instruction set extension and Indexed Addressing mode are disabled (Legacy mode)

 

Offline tahmodTopic starter

  • Contributor
  • Posts: 31
Re: Some few error in Assembly Language
« Reply #9 on: March 10, 2013, 02:32:05 pm »
-I have still two problem, it says this after I press the button build in
http://postimage.org/image/ulnicj2sx/
-In the tutorial they say to “the oscillator set to internal but there are two type of interna, which one you need to choose
Here a picture http://tinypic.com/r/2najr0o/6

read the datasheet for that pic controller, it will say there how to disable the bit that enables the extended instruction set :

http://ww1.microchip.com/downloads/en/DeviceDoc/39778e.pdf

In particular, you're looking for  page 331 and onwards, 25.0 SPECIAL FEATURES OF THE CPU

The bit you need to set is (page 333):

XINST: Extended Instruction Set Enable bit
1 = Instruction set extension and Indexed Addressing mode are enabled
0 = Instruction set extension and Indexed Addressing mode are disabled (Legacy mode)

-I have put the extended instruction disabled and now it work

Problem
1.-In the tutorial they say to “the oscillator set to internal but there are two type of interna, which one you need to choose
Here a picture
http://tinypic.com/view.php?pic=2najr0o&s=6
2.-I am doing a tutorial and it says “Make portD an output – ready to drive the LEDs. Write a test pattern to portD. Make portB,0 an input, ready for the switch. That is all the code needed for initialisation in this system.  “
                 -How to make the PortD and output?, 
                 -how to initialise a code, for example you write PORTD equ Output? (like c programmimg)


3. in the tutorial it says a text about how does it work but did not understood it.

"In state1, we output all zeros to portD to turn all the LEDs off.”
-how they turn off all the LED?

“ In state2 we output the pattern ‘AA’ to the LEDs.”
-The AAh =10101010b, so it turn on 4 LED and turn off 4 LED? There are 8 LED?

“ After driving the LEDs with the appropriate value, there is code to check for the switch being pressed and then released (active low, Table 3.1).”
-where is the code?

“The instruction bra $-2 effectively hold the processor at the test until it is TRUE.”
-When it is low, it skip the bra $-2? The role of the bra $-2 is to keep the counter 2 place backward?

 “When the software exits state1 it ‘drops into’ state 2 – but when exiting state2 a specific instruction is required to get back to state1."
-Confuse about this sentence


-Is btfsc PORTB,0  and btfss PORTB,0 is a if function?
« Last Edit: March 10, 2013, 02:43:41 pm by tahmod »
 

Offline mariush

  • Super Contributor
  • ***
  • Posts: 5029
  • Country: ro
  • .
Re: Some few error in Assembly Language
« Reply #10 on: March 10, 2013, 04:03:45 pm »
All the questions you have are mostly due to the fact that you DID NOT READ THE DATASHEET for this microcontroller.

Now I can understand if you don't read it completely, because it's huge, over 300 pages, but you can jump at the chapters you want to learn more about.

GOING BACK TO THE DATASHEET I LINKED ABOVE ... OPEN IT AND BE READY TO BROWSE IT.

Problem
1.-In the tutorial they say to “the oscillator set to internal but there are two type of interna, which one you need to choose


from page 37 onwards it explains everything about external and internal oscillators. on page 43 you have internal oscillators explained. Basically there are two, one high frequency but which uses more power and one very low frequency (which can be used for example when you want your pic to use super low power sleeping).
You also have several options that allow you to expose the oscillator on the pins usually used for external oscillator (in case you want some other chip to sinchronize to your pic frequency for example) or disable that so that you can use those pins for input/output


2.-I am doing a tutorial and it says “Make portD an output – ready to drive the LEDs. Write a test pattern to portD. Make portB,0 an input, ready for the switch. That is all the code needed for initialisation in this system.  “
                 -How to make the PortD and output?,
                 -how to initialise a code, for example you write PORTD equ Output? (like c programmimg)


page 117 and onwards : i/o ports

Basically you have two registers, TRIS and PORT , for each set of eight pins that can be each either input or output.  Eight input/output pins are grouped into a port and you can set the individual mode of a pin in that port, by setting a particular bit in the TRIS register for that port to 1 or 0.   The PORT register tells you what state that pin is.

Depending on how you connect the leds, you need to either set the pins the leds are connected to as OUTPUT (to send power to the led)  or as INPUT (so that power comes into the led and the microcontroller completes the circuit). Your circuit is probably the first case.. you set the pins as output and when you say 1 on the pin, the microcontroller sends power through the pin lighting up the led.
So if you have four leds, you set four pins of you microcontroller to output but as the pins are grouped into  a port of 8 pins, you need to set all those 8 pins... so you have TRISD  (tris for port D) = 11110000b;  <-- pins 0,1,2,3  are output, pins 4,5,6 and 7 are input... 0 is the one at the end.

Now with the PORTD you can actually set the pins on or off, but again you have to work with the set of 8 pins no matter if you have 4 leds or not ... the other 4 pins are just there with nothing connected to them.



3. in the tutorial it says a text about how does it work but did not understood it.

"In state1, we output all zeros to portD to turn all the LEDs off.”
-how they turn off all the LED?

“ In state2 we output the pattern ‘AA’ to the LEDs.”
-The AAh =10101010b, so it turn on 4 LED and turn off 4 LED? There are 8 LED?


So when PORTD = 0, it means all pins in port D are set to off, no power sent to them.

AAh is the hex value,  AA in hexadecimal =10101010b ... this tells me that at least pins 1,3,5,7 were set initially to ouput mode with TRISD (TRISD = 01010101b - pins 0,2,4,6 are left as input, pins 1,3,5,7 are output). 

Now PORTD = AAh, so those 4 pins are turned on, and the others are left as OFF ( if those pins were set to input with TRISD, the microcontroller ignores the 0 for those bits as it doesn't make sense)



“ After driving the LEDs with the appropriate value, there is code to check for the switch being pressed and then released (active low, Table 3.1).”
-where is the code?


i don't know, i don't have the code in front of me . I would guess since you mention it later, it's those btfsc and btfss instructions which test if a bit on the port is set (which happens when the pin is set to input and the pin receives voltage because the button is pressed) and either skip an instruction that follows them or execute it, so they're like an if then else code.


“The instruction bra $-2 effectively hold the processor at the test until it is TRUE.”
-When it is low, it skip the bra $-2? The role of the bra $-2 is to keep the counter 2 place backward?


page 347 and onwards .. instruction set

page 350 PIC18F87J11 FAMILY INSTRUCTION SET

page 359  BRA  ... Branch unconditionally,  with the parameter being the new value of the program counter.

$ is the current position in the program... if you say $-2, it means it jumps two instructions back

Not exactly sure how the code is in the tutorial, but I assume it's a sort of loop  and the BRA command simply moves the microcontroller to the start of the loop


 “When the software exits state1 it ‘drops into’ state 2 – but when exiting state2 a specific instruction is required to get back to state1."
-Confuse about this sentence



I don't know what you're trying to say.

-Is btfsc PORTB,0  and btfss PORTB,0 is a if function?

btfsc and btfss are instructions of the microcontroller

BTFSC Bit Test File, Skip if Clear

BTFSS Bit Test File, Skip if Set


Think of them as " if bit is set then do the next instruction otherwise jump it", or something like that. Useful to get out of an infinite loop, an exit condition.

Again, read the datasheet , page 350 and onwards, each instruction is explained.


« Last Edit: March 10, 2013, 04:11:22 pm by mariush »
 

Offline tahmodTopic starter

  • Contributor
  • Posts: 31
Re: Some few error in Assembly Language
« Reply #11 on: March 10, 2013, 06:13:21 pm »
I am doing a tutorial on Assembly language and dont really understand the full functions of the program. This is my third tutorial and I am really confuse.
-I do not understand how the program work, so I tried to write some comment and search some code from the datasheet what does the code mean.

 Can you tell me if my understanding of the code is correct or wrong written in the comment of the code?Can you tell me if each line are correct or wrong?
 
The code is
http://oi49.tinypic.com/nv7250.jpg
And the flowachart is
http://oi45.tinypic.com/bx278.jpg

org 0            ;force the program to start at init?
init: clrf TRISD      ;when you are using clrf, this initialise the variable?
            ;it is a variable or a memory location that we create in the RAM?
            ;A memory location take place in a register?
      movlw 0x55      ;This move the binary 0101 0101 into the w register?
      movwf LATD      ; this move the binary 0101 0101 previously stored in w into LATD?
            ;LATD is the register that contain the information for the output LED?
      bsf TRISB,0      ;bsf= Bit Set f  in the datasheet, this mean it set the TRISB=0, the TRISB control the output             port of B to be either input or output, so a 0=input?

-I dont understand the code put a value of 0x55 into LATD then clrf the LATD




statel: clrf LATD   ;-I dont understand the code put a value of 0x55 into LATD then clrf the LATD
   btfsc PORTB,0   ;btfsc= Bit Test f, Skip if Clear in the datasheet, so when it is high it keep on going 2             place backward and if the output go low it goes on btsff PORTB,0
         ; So this line mean btfsc wait for the PORTB input? And what does the number 0 mean?
   Bra $-2      
   btfss PORTB,0   ;btfss=Bit Test f, Skip if Set, this is similar to the btfsc but it wait to be high to skip the function bra?
   bra $-2


state2: movlw 0xaa      ;set  the LED on 1010 1010?
   movwf LATD   ;LEDS 7,5,3,1 are on, they are on because the LATD tell them to be on? The LATD is the memory for the          LED on or off
   
   btfsc PORTB,0
   bra $-2
   btfss PORTB,0
   bra $-2

   bra statel   ;what does this mean?
   end

-TRISB, LATD and state1 are fixed name? Can I change their name?
-We can change the labels name but the opcode and operant are fixed.?
-the “BIT-ORIENTED FILE REGISTER OPERATIONS” are if else function, input function?
For example btfss and btfsc can be used as if and else
-in the code bra-£2. $-2 make the file go 2 place backward, what does the bra mean?
 

Online IanB

  • Super Contributor
  • ***
  • Posts: 11891
  • Country: us
Re: Some few error in Assembly Language
« Reply #12 on: March 10, 2013, 06:16:20 pm »
Maybe you would be happier with an Arduino?
 

Online IanB

  • Super Contributor
  • ***
  • Posts: 11891
  • Country: us
Re: Some few error in Assembly Language
« Reply #13 on: March 10, 2013, 06:22:55 pm »
You seem to be trying to do things which are several steps beyond your current state of learning.
 

Offline mariush

  • Super Contributor
  • ***
  • Posts: 5029
  • Country: ro
  • .
Re: Some few error in Assembly Language
« Reply #14 on: March 10, 2013, 06:43:26 pm »
Please read what I wrote to you in that other thread.

clrf , movlw, bsf etc are all instruction names,  each processor has a set of instructions it can understand. These instructions are specific to pic microncontroller.

If you read the chapter about instructions, each instruction is explained there.

TRISD, PORTD, LATD  are keywords defined in that  p18xxxx.inc file ....they're just some words meant to make it easier for you to write assembly code, instead of writing all the time the memory location of the register, you just say TRISD, PORTD or LATD.

Read the IO ports section of the datasheet to understand what TRISx , PORTx and LATx  mean. I've tried to explain it in my previous comment.

"-I dont understand the code put a value of 0x55 into LATD then clrf the LATD"

it isn't doing that. It loads a value into memory, then copies the value from memory to LATD.

init, state1 and state 2  are LABELS. 

In assembler they don't have any meaning, they're just there to make it easier for you to read and write assembly code.  They're visual indicators for you to know a block of code ends there and another starts.  You can change those with anything you want as long as it's not a keyword already defined somewhere.

The microcontroller executes instructions one after another, as they appear  in the assembly. Imagine each line of assembly with instructions has a number to the left.  If you put a label in front of a line, further down the code you can just say  <<go to "label name" >>  instead of saying << go to line 100 >>  It's much better this way because if you add some lines before that line 100, that line is no longer line 100, so you'd have to go all over the assembly code to change 100 to 114 or whatever number the line has now.

 

Offline mariush

  • Super Contributor
  • ***
  • Posts: 5029
  • Country: ro
  • .
Re: Some few error in Assembly Language
« Reply #15 on: March 10, 2013, 06:53:56 pm »
Here, read this pdf , it explains a lot about pic and assembly language, maybe it clears some things up for you : 

PIC Assembly Language for the Complete Beginner

http://www.ai.uga.edu/mc/microcontrollers/pic/picassem2004.pdf

Even if it explains everything with examples for a PIC16, once you understand his explanation you will be able to easily understand what the PIC18 datasheet says and what are the differences (they're not big differences)
 

Offline mrflibble

  • Super Contributor
  • ***
  • Posts: 2051
  • Country: nl
Re: Some few error in Assembly Language
« Reply #16 on: March 10, 2013, 07:02:42 pm »
Maybe you would be happier with an Arduino?

Sounds like a reasonable hint.

Either do that, or you know ... read the actual documentation for your chosen microcontroller. And it might be on step easier to first do C, and then mess with asm. At least that way you don't need to know what a BRA instruction is, and why your program branches unconditionally at that point.

Anyways, I suggest you read the material that's been suggested in this + the other thread  first.
 

Offline blewisjr

  • Frequent Contributor
  • **
  • Posts: 301
Some few error in Assembly Language
« Reply #17 on: March 10, 2013, 09:48:54 pm »
Arduino might be a good idea great learning hardware.  I have been learning on a pic devboard using asm but I have a very strong background in c already and I am learning quite well but it seems as if the op does not have a strong programming background to start off of.  Even I picked up an arduino for the shear ease of slapping circuits together and I like it so far may switch to it from pic and use the avr assembler.  Just seems like the options with arduino can cater to any direction.  Not sure if I will switch but thinking about it.
 

Online IanB

  • Super Contributor
  • ***
  • Posts: 11891
  • Country: us
Re: Some few error in Assembly Language
« Reply #18 on: March 10, 2013, 10:12:12 pm »
I am doing a tutorial on Assembly language

Based on your comments and questions here, you don't seem to be prepared for this.

Before you start trying to do such tutorials, you should begin by getting familiar with the basic operations of a PC. Learn about the file system, how to find files in the file system, how to run programs, how programs know where to load and save the files they work with.

Then think about learning programming concepts with a high level language like Visual Basic. Do some tutorials writing programs on a PC and learn the various program concepts of data, program instructions, loops, conditionals and how they work together. Learn how to read and understand the diagnostic messages when your program contains a mistake.

After you have spent some time doing that, then go back and think about learning assembly language.

Right now you seem to be trying to run before you can walk.
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf