Welcome! Log In Create A New Profile

Advanced

Addressing individual O/P pins.

Posted by GavinHannah01 
Addressing individual O/P pins.
September 19, 2012 09:41AM
Hi there,

I have the BV500 setup and have been looking through the tutorials. I have a problem that I'm struggling to solve.

If I connect three LED's to Port A RA0 - 1 - 2; How can I activate the output pins individually? I have tried using LATAINV variable name and LATASET.

I use constants to define the LED's i.e:

constant LED 1 << 0
constant LED2 1 << 1
constant LED3 1 << 2

Then in the main function,

while loop

LATAINV LED
LATAINV LED2
LATAINV LED3

close loop

Thanks.
Re: Addressing individual O/P pins.
September 19, 2012 10:35AM
LATAINV is an address, you need to change the contents of the address using @, thus:
@LATAINV=LED
or
poke(LATAINV,LED)
Re: Addressing individual O/P pins.
September 19, 2012 10:48AM
My apologies, I was using @ in my code:

@LATAINV = LED
@LATAINV = LED2
@LATAINV = LED3

That is the code I was using above. But nothing happens except that the LED connected to RA0 flashes on and off.
I'm not getting any response from the LEDs connected to RA1 or RA2.
Re: Addressing individual O/P pins.
September 19, 2012 10:54AM
* Have you set RA1 and RA2 to be output using TRISA or TRISACLR?
* Is RA1 or 2 an analogue? If so they need setting to digital
Re: Addressing individual O/P pins.
September 19, 2012 11:00AM
Before the main function I have;

TRISACLR = 1
ANSELACLR = 1
Re: Addressing individual O/P pins.
September 19, 2012 11:02AM
Should be
@TRISACLR = 1
@ANSELACLR = 1
Re: Addressing individual O/P pins.
September 19, 2012 11:29AM
constant LED 1 << 0
constant LED2 1 << 1
constant LED3 1 << 2


@ANSELACLR = 1
@TRISACLR = 1



while loop

@LATAINV LED
@LATAINV LED2
@LATAINV LED3

close loop



This is my code summarised, I have the register addresses with the @ all set to digital.
I tried doing this on PORT B (I altered the addresses) and I would only get the same result. LED will flash but LED2 and LED3 are non responsive.

I've tested the LED's they all work.

I'm at a loss....
Re: Addressing individual O/P pins.
September 19, 2012 12:59PM
The code shoule look something like this:

function x()
  @ANSELACLR = 1
  @TRISACLR = LED2 | LED3
  while comkey?(2) = 0
     @LATAINV = LED
     @LATAINV = LED2
     @LATAINV= LED3 
     wait(200)
  wend
endf
This will work if all the constant values are correct and the pins are connected okay, if not then you need to keep checking, it is very easy to miss something. Try using LATACLR and LATASET instead, look at the current value in LATA, PORTA and in TRISA, is it what is expected? You can do this interactively, that's what makes debugging so easy.
Re: Addressing individual O/P pins.
September 19, 2012 08:38PM
Magic thanks!

That's done the trick.
Sorry, you do not have permission to post/reply in this forum.