![]() |
Forum Index : Microcontroller and PC projects : MMbasic IO pin aliasing issue
Author | Message | ||||
58kk90 Regular Member ![]() Joined: 14/06/2023 Location: United KingdomPosts: 61 |
I am trying to alias a few IO pins to give them sensible names to make the code easier to follow, for example LED1 = GP0 LED2 = GP1 etc I have tried this as a quick test OPTION EXPLICIT OPTION DEFAULT NONE const LED1 = GP0 ' red LED Const LED2 = 2 ' green LED setpin (LED1),Dout setpin (LED2),Dout start: pin(LED1) = 1 PIN(LED1) = 1 pause 10 pin(LED1) = 0 PIN(LED1) = 0 pause 10 goto start When I run it, I get an error [5] Const LED1 = GP0 ' red LED Error : GP0 is not declared But the manual states 'An I/O pin is referred to by its pin number and this can be the number (e.g., 2) or its GP number (e.g., GP1)' If I change the Const LED1 = GP0 to Const LED1 = 1 then it works fine, can I not reference the IO pins by the GP number? Anyone give me a clue what I am doing wrong please? This is with mmedit version 5.2.8 and Picomite mmbasic 6.00.02b11 Tony |
||||
disco4now![]() Guru ![]() Joined: 18/12/2014 Location: AustraliaPosts: 983 |
Try const LED1 = MM.INFO(PINNO GP0) ' red LED Latest F4 Latest H7 FotS |
||||
Mixtel90![]() Guru ![]() Joined: 05/10/2019 Location: United KingdomPosts: 7585 |
CONST is (I think) the one instance that insists on a number here. I don't know why. MM.INFO(PINNO GPn) returns the physical pin number for GPn. I've not tested this on a PGA2350B yet. It may be interesting. :) What pin number does it return for, for example, GP42? Mick Zilog Inside! nascom.info for Nascom & Gemini Preliminary MMBasic docs & my PCB designs |
||||
phil99![]() Guru ![]() Joined: 11/02/2018 Location: AustraliaPosts: 2458 |
As Disco4now showed is the way to do it. Const LED1 = GP0 ' red LED Contains letters so it would have to be - Const LED1$ = "GP0" ' red LED But few if any commands will accept strings for the pins. I don't know the actual number but I recall Peter sorting out the extra pins to ensure all such things work. Edited 2025-02-18 21:16 by phil99 |
||||
JohnS Guru ![]() Joined: 18/11/2011 Location: United KingdomPosts: 4006 |
Maybe CONST LED1 = MM.INFO(PINNO GP0) 'if the actual number is needed and maybe setpin (LED1),Dout but the parens may be removed (I think) setpin LED1,Dout The manual probably has a tough time describing when things like GP0 can be used. I think it's anywhere the MMBasic parser is expecting a pin (which it is in SETPIN but isn't in CONST). You may also be able to do CONST LED1 = "GP0" 'er... need STRING somewhere (probably)! and then SETPIN VAL(LED1),DOUT but it's ugly even if the right syntax (i.e. using STRING) is doable. John Edited 2025-02-19 00:04 by JohnS |
||||
phil99![]() Guru ![]() Joined: 11/02/2018 Location: AustraliaPosts: 2458 |
Tested all the options. and Const LED1 = 1 'red LED on GP0 (pin 1) are the only ways (they amount to the same thing) that can use a variable / const. |
||||
58kk90 Regular Member ![]() Joined: 14/06/2023 Location: United KingdomPosts: 61 |
Thanks to everyone who replied with suggestions, i've tested the way @disco4now suggested and that works fine. Coming from Arduino it seems a logical thing to call the pins 'sensible' names that relate to their function, I was quite suprised when I found it so difficult to achieve and there didn't seem to be anything in the manual about it, or after searching the forum. Anyway, it's sorted now and I appreciate the help. Tony |
||||
phil99![]() Guru ![]() Joined: 11/02/2018 Location: AustraliaPosts: 2458 |
Yes, before MM.INFO(PinNo GPxx) was added it was even harder. Here is a thread on the subject. |
||||
Mixtel90![]() Guru ![]() Joined: 05/10/2019 Location: United KingdomPosts: 7585 |
CONST is really what it says, a numeric or string constant that can't be changed in the program. Using it to reference IO pins is really a bit of a kludge, but it can be made to work. The RPi chips always refer to the GPIO pins using GPIOnn references internally, never pin numbers. That allows them to be remapped to any pins on the package. The Pico follows a similar approach, you don't refer to module pin numbers unless you have to as that makes your program incompatible with other modules using the same chip. The GPn numbers will always work even if they are on physically different pin numbers. Here we run into the CONST problem. Everything, from the chip internals upward has used GPIOnn or (the MMBasic abbreviated version) GPn. CONST doesn't know how to handle that as its argument has to be either numeric or string. Mick Zilog Inside! nascom.info for Nascom & Gemini Preliminary MMBasic docs & my PCB designs |
||||
![]() |
![]() |
The Back Shed's forum code is written, and hosted, in Australia. | © JAQ Software 2025 |