News:

PROTON pic BASIC Compilers for PIC, PIC24, dsPIC33

Main Menu

Aliasing a PIN on PIC12F1572

Started by rick.curl, Feb 21, 2023, 09:15 PM

Previous topic - Next topic

rick.curl

I must be missing something obvious here. I am updating some simple code that was written for a PIC12F675 to port it over to a PIC12F1572.  The old code aliased output pins like this simplified snippet:
  Dim OutPin as pin
        OutPin = GPIO.0

Mainloop:
    toggle outpin
    delayms 100
    goto Mainloop
...and it worked great, but I can't get the same thing to work on the PIC12F1572.  It compiles without error, but the pin never toggles. If I take out the alias and change it to:
Mainloop:
toggle LATA.0
delayms 100
goto mainloop
it toggles as it should.

Here's a complete snippet that has the problem:
    Device  12F1572
    Xtal 4
    Reminders off

'-------------------------------------------------------------------------------
'**** Added by Fuse Configurator ****
' Use the Fuses Tab to change these settings

Config1 FOSC_INTOSC, WDTE_OFF, PWRTE_ON, MCLRE_OFF, CP_OFF, BOREN_ON, CLKOUTEN_OFF
Config2 WRT_OFF, PLLEN_OFF, STVREN_OFF, BORV_HI, LPBOREN_OFF, LVP_OFF

'**** End of Fuse Configurator Settings ****
'-------------------------------------------------------------------------------
     Reminders On

  osccon = %01101010  '4Mhz internal osc

     trisa = 0            'all pins output
     ANSELa = 0           'all pins digital

 '** Declare aliases **
   Dim OutPin as pin
   OutPin = LATA.0

   LATA = 0   'set all pins to zero
   DelayMS 100 'wait a bit before starting

Mainloop:
   toggle OutPin
   delayms 100
goto mainloop

Can anyone spot the problem?

Many thanks!

-Rick


 

Pepe

#1
Obviously there is an error with some of the 12f devices with Dim Mypin as pin, until it is fixed you should use toggle porta.0

trastikata

Quote from: rick.curl on Feb 21, 2023, 09:15 PMCan anyone spot the problem?

What happens if you change to "OutPin = PORTA.0"?

david

#3
Or change 
Dim OutPin as pin
OutPin = GPIO.0

to
Symbol OutPin=PortA.0

Stephen Moss

Microchip changed how they name the I/O ports in later devices, presumable to create consistency between devices. Consequently on some of the later 8pin device GPIO is named PortA instead.
If you look in the PPI file for the 12F675 the I/O port is defined thus...

GPIO EQU 0X0005
PORTB EQU 0X0005

so you can refer to it as GPIO or PortB, but for the 12F1572 it is only denied as
PORTA EQU 0X000C

so if you added GPIO EQU 0X000C to the PPI file then the original code would work, but that is not a good solution as the modified file maybe overwritten at some point.
As trastikata indicated try OutPin = PortA.0 as the command may expect a Port reference but in the assembler it will act on the Lat register but essentially I think the use of Toggle maybe wrong. See post 5 by Les here which may help.


Pepe

With OutPin = PORTA.0 it also does not work see example in publication #1

rick.curl

Thanks for looking into this, guys.  I had tried the other suggestions above, but as Pepe pointed out, they don't work either. I can work around it, but my code that was very streamlined now becomes bloated because where I had a subroutine that would send output to different pins at different times, now I will have to have several separate subroutines.

Fortunately, Positron always offers many ways to do the same thing. I was hoping I was just missing something.

-Rick

top204

#7
I did spot an anomaly with the enhanced 14-bit core devices and 12-bit core devices and the Pin type variables thanks to this thread, and this has now been corrected and, hopefully, I have also levelled out the pin names for the 8-pin devices. Microchip have kept changing the names of the port on the 8-bit devices from GPIO, PORTA and PORTB etc, for the single Port. So I have made the compiler look for any three of them and the Pin can be assigned as Pin_IO0 or Pin_IO1, Pin_IO2, Pin_IO3 etc...

As soon as I can, I will upload the updated compiler version.

rick.curl

WOW!  Thanks, Les!
Not only did you fix the issue, but you made the compiler better by having it accept other variations of the pin names.

You never cease to amaze me.

-Rick

top204

Many thanks Rick. Every penny is very welcome these days.

Hopefully, I have made the 8-pin devices a bit easier to write for and to keep a standard. I am now adding extra demonstration code listings in the manual for the 8-pin devices for PinHigh, PinLow, PinInput, PinOutput etc...