View Full Version : I/O - From Define to code ... must be easy
mister_e
- 30th June 2011, 08:56
Oki, so here's the question assuming the following way to define Aliases to I/O
DEFINE LowBeerLevel PORTB,1
OR
#DEFINE LowBeerLevel PORTB,1
On ASM level.
It's still easy to use them later with MOVE?CT macro, or BSF/BCF whatever floats your boat.
What if I wanted to use it with say I2CREAD, HIGH or whatever else PBP command?
Tried few variants of EXT modifier thing.. but LOL...
http://www.your3dsource.com/images/headbangsoncomputer_t_01.gif
Seems I'm too idiot to make it work.
I could still work on asm level... but if there's any other way, I would really like to hear them.
Thanks!
http://www.your3dsource.com/images/goneinsanegif.gif
cncmachineguy
- 30th June 2011, 12:46
I think the preferred way is this:
LowBeerLevel var portb.1
GoToBeerStore var portb.2
while !LowBeerLevel
:):)
while end
ASM
BSF _GoToBeerStore
ENDASM
If GoToBeerStore = 1 then
:(
Ok, silly example, but the point is create your var's or alias as usual, then to use in ASM block stick an underscore before the name.
HTH
mister_e
- 30th June 2011, 13:03
You missed the DEFINE thing, however I came up with the following
DEFINE SData PORTB,1
DEFINE SClock PORTB,2
And then in the compilation time section you use
CreateVar MACRO PortIn,BitIn, PortOut, BitOut
PortOut = PortIn
BitOut = #V(BitIn)
ENDM
;
;
; somewhere later
;
@ CreateVar SData, SerData, DataBit
@ CreateVar SClock, SerClock, ClockBit
SerData VAR BYTE EXT
DataBit CON EXT
SerClock VAR BYTE EXT
ClockBit CON EXT
just need to use 'em like
HIGH SerClock.0[ClockBit]It has some success, ugly... and we also know this method is not going to work all the time... good example? Shiftout :D
Keep thinking...
mister_e
- 30th June 2011, 13:39
I think of some other ways, but it's damn too much coding for a so simple thing :D The asm side's still good enough though. It would have been soo easy if we could do
DEFINE LCD_EN_LINE PORTC,1
and then
LCD_EN_LINE VAR BIT EXT... BUT NOPE
OR
even easier.. have them ready to use, nothing to hack...
Why I do prefer the DEFINE way... hahaha, I have no idea :D Probably to fit with PBP LCDOUT, HSEROUT, DEBUG etc etc etc
Darrel Taylor
- 30th June 2011, 17:03
This will blink an LED on any pin, as specified in the BLINK_TEST define.
If the define is commented out, it will bypass the blinky and start at the main program.
DEFINE BLINK_TEST PORTB,0
'
' Variables, Constants etc.
'
;----[Blinky test]------USE( DEFINE BLINK_TEST PORTB,0 )-----------------
BLINK_LED VAR BIT EXT
@ #undefine BLINK_LED
@ #define BLINK_LED BLINK_TEST
@ ifdef BLINK_TEST
INCLUDE "AllDigital.pbp"
Blink:
TOGGLE BLINK_LED
PAUSE 500
GOTO Blink
@ endif
mister_e
- 30th June 2011, 18:34
hhhhhhhhhhhhhhhhhhhhhaaaaaa! I knew it was something "easy", just never though of the #undefine twist...mmm... something else to chew on :D
http://toons.artie.com/alphabet/words/arg-dancin-wo0hoo-url.gif
Thanks Mr Tech Support ;)
HenrikOlsson
- 30th June 2011, 19:41
Hi,
So, are you saying that this is almost like conditional compilation? By almost I mean that as far as I understand it, it will alwyas compile the code but depending on if the DEFINE exists or not the compiled ASM code will or will not be assembled?
Is that correct? If not, could Steve or Darrel elaborate a bit as I'm curious?
Thanks!
/Henrik.
mister_e
- 30th June 2011, 20:36
Yup, some black magic in conditional compilation, IFDEF, IFNDEF, #DEFINE, #UNDEFINE, to name only but those. Pretty slick and so usefull once you get the concept and play with.
Lots of great feature in asm and MPASM. If you' wanted, you may have one code template and it will fit every hardware depending how you deal with the conditional compilation. Good example, Microchip Framework. One code fits all(most) of their development boards.
On the top of your code, you provide some USER configurable setting, says regular LCD or GLCD, USB to RS232, PIC model and so forth... endless possibilities.
Pretty addictive.
Ioannis
- 5th July 2011, 09:23
I smell that you are cooking something here Steve, but cannot follow you.
I'll wait to see the smartie that you will show us... anxiously :)
Ioannis
mister_e
- 5th July 2011, 11:40
Always looking for convenience, but don't always use it :D
"What you smell is a fart, not much " <-- highlight with your mouse...
Powered by vBulletin® Version 4.1.7 Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.