Question : Problem: pic microcontroller

i have problem understanding the relation between the codes bellow the line and the codes above the line
Code Snippet:
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
;Demo program to turn on all LEDs on a seven segment display... include  
codes starts from here;
 
status		equ 03h	  ; Status register address
trisA		equ 05h	  ; Sets direction of the I/O register (port A). This register is in memory bank 1
trisB		equ 06h	  ; Sets direction of the I/O register (port B). This register is in memory bank 1
port_A		equ 05h	  ; address of port A
port_B		equ 06h	  ; address of port B
pulse_on	equ 0ffh  ; turn pulse on
pulse_off	equ 0ffh  ; turn pulse off
rp0	    	equ 05h	  ; bit in status register to select register
			          ; bank 1 where trisA reg is stored
all_out		equ 00h   ; sets all register bits as output
;*******************************************************************
		org 0h			; gives instruction to the assembly program to set the program at the first memory location
		goto main		; instructs the program to jump to the label "Main"
		org 010h		; gives instruction to the assembly program to set this line of the program 				
						;at memory address 0X10
main	bsf status, rp0	; sets the status register so that the program is 
						;looking a memory block 1
		movlw all_out	; moves the value of all_out to the working register
		movwf trisB		; puts the value from the working register to the special register trisA
		bcf status, rp0	; unsets the flag to the program is back looking at memory block 0
						; now port_c is set up as an out put port 
						; it has taken four lines of to initialise port_c
signal	movlw pulse_on	; Now the program can move the value pf Pulse_on to the working register
		movwf port_B	; it now moves the value in the working register to port_c
						; so the last two lines of code have out put the hex value of 0xff
		nop				; this line just increments the program counter but changes nothing else in the system
		goto signal		; this line loops the program so it runs for ever
		end				; this is an instruction to the assembler to end the program
Open in New Window Select All

Answer : Problem: pic microcontroller

I'm not sure I understand your question.  At the risk of oversimplifying your problem, here's a brief and superficial explanation of the relationship between both segments.

The "equ" instruction defines a label to a memory location.  It is typically used in Assembly to define "variables".  That is, when you do something like:
     status   equ 03h
the assembler associates the value $03 hex with the label "status", so that from then on, if you want to read or write to location $03, you can address it by its label name.

One thing to note is that this is only an "alias" offered by the assembler, not a real variable in the sense of a higher-level language, such as C.  By that I mean that "status" does not hold any value, nor points to a memory location, really; it just "means" the number $03.  So if you use it with instructions that call for an address, it looks like it points to that address, but if you use it with instructions that call for an immediate value, it will look like an immediate value.  In essence, you are saying "status equals $03" (which is where the "equ" comes from), or "whereever the assembler sees 'status', replace it with $03."

The code below the line is explained very well by the comments, but just to expound on it further, here are some more points on it:

The following section is typical of a program "Header".  I'm not familiar with PIC microcontrollers specifically, so I don't really recognize the sequence, but most code segments requirea "signature" that specifies to the assembler in which area of memory to store the code, how big the data segment is and where to put it, and (if available) where to set up a stack.  This information is then used by the program launcher to appropriately set up the code and feed it to the processor.  Usually, program headers require a minimum size, because they are treated as a data record with specific values by the launcher.

By the way "org" tells the launcher "from here on, start storing all these instructions from the following address on."

            org 0h          ; gives instruction to the assembly program to set the program at the first memory location
            goto main       ; instructs the program to jump to the label "Main"
            org 010h        ; gives instruction to the assembly program to set this line of the program                            


The following section initializes "port_c" as an output port.  Some processors cannot transfer data directly from core memory into other memory locations or devices; so in this case, the data is first moved from the location "all_out" ($00) into a local register, and then copied it over to the "port_c" device.

main        bsf status, rp0 ; sets the status register so that the program is
                            ; looking a memory block 1
            movlw all_out   ; moves the value of all_out to the working register
            movwf trisB     ; puts the value from the working register to the special register trisA
            bcf status, rp0 ; unsets the flag to the program is back looking at memory block 0
                            ; now port_c is set up as an out put port

The last part just creates a loop, pressumably to pulse the lights on and off.

       -dZ.
Random Solutions  
 
programming4us programming4us