Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Pic Assembly Dummy Define ?

Status
Not open for further replies.

Wp100

Well-Known Member
Hi,

In a program set up with the ports allocated by Defines eg #define OUTPUT1 PORTD, 1 , if I want to change said program and allocate another new function to that output pin how can I deal with OUTPUT1?
There are no other pins free to allocate it to, and simply removing it is not easy as I would have to remove all the many lines of code it references in the program. ( which I may wish to restore /change in the future)

Though have not seem mention of it, wondered if there was some parameter I could use like OUTPUT1 DUMMY ?
 
Why not just write to a General Purpose Register instead of the Port Register ?

Assuming that you have a spare GPR of course.

JimB
 
Are you thinking of using the same pin for two different functions at run time? If so, you could use two defines involving that pin. They could even be one immediately after the other. Do not be surprised that this could bite you unless you comment the code to warn you later when rereading it.

Or are you looking to selectively compile one of two options? After rereading your post again I think THAT is what you want.

In this case you need to use conditional compile. Look for the IF directive. First example from my code (requires CLEAN_VAL previously defined somewhere else) and do not forget, you need ENDIF!

Code:
;----------------------------------

;Conditional compiling starts here.
;CLEAN_VAL!=0, writes CLEAN_VAL to byte.
;CLEAN_VAL =0, clears the byte.
             
    IF CLEAN_VAL !=0
        LOADREG POSTINC0,CLEAN_VAL    ;write CLEAN_VAL to register
    ELSE
        CLRF POSTINC0                ;clear the register
    ENDIF                     

;Conditional compiling ends here
;----------------------------------

Second example (requires CLOCK defined somewhere else). In my case, I have calculated the delays for not less than 5 different clock frequencies so, depending the define saying CLOCK = XXXX is what makes the compiler to know what part will be compiled.
Also here, do not forget, you need ENDIF!

BTW, the code below is a clasicc used for delays on line.

Code:
;------------------------------------------------------------------------------

  IF CLOCK ==16000000

;------------------------------------------------------------------------------

DELAY_004_MICR              ;Delay = 0,000004 sec with Fosc = 16 MHz
  LOADREG CNTR_INNER,5

DELAY_004_MICR_LOOP
  DECFSZ    CNTR_INNER,1
  BRA DELAY_004_MICR_LOOP
;------------------------------------------------------------------------------

DELAY_010_MICR              ;Delay = 0,000010 sec with Fosc = 16 MHz
  LOADREG CNTR_INNER,13
 
DELAY_010_MICR_LOOP
  DECFSZ    CNTR_INNER,F
  BRA DELAY_010_MICR_LOOP
  RETURN
;------------------------------------------------------------------------------
DELAY_020_MICR              ;Delay =0,000020 s with Fosc =16 MHz
  LOADREG CNTR_INNER,26

DELAY_020_MICR_LOOP
  DECFSZ    CNTR_INNER,F
  BRA DELAY_020_MICR_LOOP
  RETURN
;------------------------------------------------------------------------------

DELAY_050_MICR              ;Delay =0,000050 s with Fosc =16 MHz
  LOADREG CNTR_INNER,66

DELAY_050_MICR_LOOP
  DECFSZ    CNTR_INNER,F
  BRA DELAY_050_MICR_LOOP
  RETURN
;------------------------------------------------------------------------------

DELAY_100_MICR              ;Delay =0,0001 s with Fosc =16 MHz
  LOADREG CNTR_INNER,133
     
DELAY_100_MICR_LOOP
    DECFSZ CNTR_INNER,F
    BRA DELAY_100_MICR_LOOP
    RETURN
;------------------------------------------------------------------------------

DELAY_001_MILI              ;Delay =0,001 s with Fosc =16 MHz
  LOADREG CNTR_MIDDLE,6
  LOADREG CNTR_INNER,49

DELAY_001_MILI_LOOP
  DECFSZ    CNTR_INNER,F
    BRA DELAY_001_MILI_LOOP
    DECFSZ    CNTR_MIDDLE,F
    BRA    DELAY_001_MILI_LOOP
    RETURN
;------------------------------------------------------------------------------

DELAY_005_MILI              ;Delay =0,005 s with Fosc =16 MHz
  LOADREG CNTR_MIDDLE,26
  LOADREG CNTR_INNER,249

DELAY_005_MILI_LOOP
  DECFSZ  CNTR_INNER,F
    BRA    DELAY_005_MILI_LOOP
    DECFSZ    CNTR_MIDDLE,F
    BRA    DELAY_005_MILI_LOOP
    RETURN
;------------------------------------------------------------------------------

DELAY_100_MILI              ;Delay =0,100 s with Fosc =16 MHz
  LOADREG CNTR_OUTER,3
  LOADREG CNTR_MIDDLE,8
  LOADREG CNTR_INNER,119

DELAY_100_MILI_LOOP
  DECFSZ    CNTR_INNER,F
  BRA    DELAY_100_MILI_LOOP
  DECFSZ    CNTR_MIDDLE,F
  BRA    DELAY_100_MILI_LOOP
  DECFSZ    CNTR_OUTER,F
  BRA    DELAY_100_MILI_LOOP     
  RETURN
;------------------------------------------------------------------------------

DELAY_300_MILI              ;Delay =0,300 s with Fosc =16 MHz
  LOADREG CNTR_OUTER,7
  LOADREG CNTR_MIDDLE,23
  LOADREG CNTR_INNER,107

DELAY_300_MILI_LOOP
  DECFSZ  CNTR_INNER,F
  BRA    DELAY_300_MILI_LOOP
  DECFSZ  CNTR_MIDDLE,F
  BRA    DELAY_300_MILI_LOOP
  DECFSZ  CNTR_OUTER,F
  BRA    DELAY_300_MILI_LOOP
  RETURN
;------------------------------------------------------------------------------

DELAY_001_SEC               ;Delay =1,000 s with Fosc =16 MHz
  LOADREG CNTR_OUTER,21
  LOADREG CNTR_MIDDLE,75
  LOADREG CNTR_INNER,191

DELAY_001_SEC_LOOP
  DECFSZ  CNTR_INNER,F
  BRA    DELAY_001_SEC_LOOP
  DECFSZ  CNTR_MIDDLE,F
  BRA    DELAY_001_SEC_LOOP
  DECFSZ  CNTR_OUTER,F
  BRA    DELAY_001_SEC_LOOP
  RETURN

  ENDIF
;------------------------------------------------------------------------------

Hope this helps.
 
Hi Atferrari,

Thanks I have used IF/EndIF etc in my code before but I just wanted to add in an extra function/ port pin and remove reference to an earlier define not now needed.
With the program being over 10k lines and the port pin is spread all over it, was thinking too hard as to ways to get the old port pin /define out of the way.

As JimB said simply use a variable - so easy to miss the obvious !
 
I don't quite understand. It is used in the program and you want to make it dummy? But if you do that, the program will be outputing something to a fake pin. Don't you want to remove all this unnecessary output?
 
I don't quite understand. It is used in the program and you want to make it dummy? But if you do that, the program will be outputing something to a fake pin. Don't you want to remove all this unnecessary output?

Hi,

I originally had a #define OUTPUT1 PORTD, 2 for a function of the program code. All the i/o pins were used up.

Needed to add in a totally new function which needed an output port.

As I no longer wanted to use the function and output port relating to the #define OUTPUT1 PORTD, 2 , but wanted to retain the relevant program code for possible future use, I just needed a way to change OUTPUT1 to somewhere that was not a i/o PORT.
I could not just delete it as then all references to it withing the rest of the program code would create compile errors.

What I had missed / blocked myself on, was the obvious way to simply re-define OUTPUT1 to a normal user register, so the relevant code executes as normal but its output just resides in a ram register rather than an output ports register, so allowing the new function to use the output pin.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top