BasicMicroUK - Forums

www.basicmicro.co.uk
It is currently Fri Oct 19, 2018 9:48 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 6 posts ] 
Author Message
 Post subject: The OUTW0 port variable name
PostPosted: Wed Feb 11, 2015 3:56 am 
Offline
Citizen

Joined: Sun Apr 22, 2012 10:22 pm
Posts: 26
Refer to Pin Variable section on page 39 and 40 of the Syntax manual.
It appears that these variables listed in the table cannot be used to
output a binary state on a port, even though the name contains the word OUT.
Is this true, or is it actually capable of outputting if the port is set to be an output?
I am trying to light one of 10 LEDs on ports 0 to 9 in a FOR-NEXT loop.


Top
 Profile  
 
 Post subject: Re: The OUTW0 port variable name
PostPosted: Thu Feb 12, 2015 10:42 pm 
Offline
Master

Joined: Wed Oct 19, 2011 2:28 am
Posts: 123
Hi,
To output to a pin you must assigned the a port name like P0,P1,P2 or assigned it using a var like temp = P0 etc. Here it is a program that will set the outputs from 0 to 9 ON/OFF.

Temp var byte
main:

'Set pors to high using a for/loop
for Temp = P0 to P9
high Temp
next
pause 500

'Set ports to low using the for/loop

for Temp = P0 to P9
Low Temp
next
pause 500
goto main


Top
 Profile  
 
 Post subject: Re: The OUTW0 port variable name
PostPosted: Thu Apr 30, 2015 11:29 am 
Offline
Guru

Joined: Fri Dec 07, 2012 3:48 pm
Posts: 67
Hi,

You did not say which Nano you are using, but yes, the OUTx ports work as long as you set the corresponding DIRx to Output. However, OUTW0, INW0 and DIRW0 do NOT work on the Nano18 and Nano18x because of the way the PIC16F88 IO Register Addresses (PORTA, PORTB and TRISA, TRISB) are arranged and mapped in the .INC files (They are the wrong way round to be used for WORD addressing). There is a way around this, but it entails doing a logical swap on the Port Addresses in the .INC files for the xW0 mapping and allowing for this in the program code accordingly - rather tedious! Rather use the OUTx, OUTNx or OUTBx ports for the Nano18, or simply address the Pins directly like tauro0221 suggested, but beware of the Nano18x - it has 2 Pins less than the Nano18!

OUTW0, INW0 and DIRW0 work correctly on the Nano28 and Nano28x because the PIC16F886 IO Registers Addresses are in the correct sequence for WORD addressing.


Top
 Profile  
 
 Post subject: Re: The OUTW0 port variable name
PostPosted: Thu Apr 30, 2015 4:04 pm 
Offline
Master

Joined: Wed Oct 19, 2011 2:28 am
Posts: 123
Hi,
I wrote a routine that will allow you to load a variable and it will output bit by bit to P0 to P9. You must have all the P0 to P9 in sequences to be able to use the routine. Hoped it is what are you looking.

'This routine will read bit by bit the data store in the variable name light
'output it bit by bit to the port P0 thru P9

led_light var word
bit_cnt var word
temp var word
out_bit var bit

Main
light = 0xAAAA 'load this variable with the led data matching the pin outputs
bit_cnt = 0 'use to address the bit in the word light

for led_light = P0 to P9
if light.bit(bit_cnt) = 1 then
temp = led_light : High temp
elseif light.bit(bit_cnt) = 0
temp = led_light : low temp

endif

serout s_out, i9600,["Bit",dec bit_cnt," =", dec light.bit(bit_cnt)," " ]
bit_cnt = bit_cnt +1
next
serout s_out, i9600, [13]
pause(5)
goto main


Top
 Profile  
 
 Post subject: Re: The OUTW0 port variable name
PostPosted: Sat May 02, 2015 11:34 pm 
Offline
Guru

Joined: Fri Dec 07, 2012 3:48 pm
Posts: 67
Hi,

Very nifty program :D

I have also been hacking away at the Nano18 OUTW0 issue and have attached 3 sample programs. The way around the Nano18 OUTW0 issue is demonstrated in each program in SUB Set_Output_Ports, which uses the standard Output Ports.

The long version program shows various methods for setting and clearing Pins (LEDs) in the Word Variable, bothconsecutively (FOR..NEXT) andrandomly. It also shows which Word Variable Bit maps to which Output Port Bit.

The 2 short version programs are each just a different method selected from the various methods described in the long version program. The short version program with indexing allows both consecutive and random setting of bits.

The thing to remember for these sample programs is that they Output Nibbles of data, so you may be outputting more Bits than you need. The sample programs show how to Input the Word Variable first (INW0 suffers from exactly the same technical problem as OUTW0), so that we do not inadvertently overwrite other Bits when we Output. But, then again, we will always have this situation when we use the standard OUTBx and OUTNx Output Ports. The same situation applies when we Input using INBx and INNx.

One last thing: Because the SER and RES Pins are slap bang in the middle of OUTN3, we can not use Pins P12 and P13 with these Word Output routines. We can only use Pins P0 to P11.

Cheers
Andre


Attachments:
nano18 and nano18x word port mapping - short version with indexing.bas [2.01 KiB]
Downloaded 263 times
nano18 and nano18x Word port mapping - short version - no indexing.bas [1.63 KiB]
Downloaded 285 times
nano18 and nano18x Word port mapping - long version- various options.bas [6.3 KiB]
Downloaded 156 times
Top
 Profile  
 
 Post subject: Re: The OUTW0 port variable name
PostPosted: Sun May 03, 2015 11:13 am 
Offline
Site Admin
User avatar

Joined: Fri Apr 12, 2013 8:38 pm
Posts: 87
Location: Nottingham, England, UK
Thanks Tauro0221 and Andre for taking the time to post these workarounds here on the forum,

I am sure these will assist less able users get the most out of the fantastic Nano range,

Dave
BasicMicroUK


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 6 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: No registered users and 0 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group

phpBB SEO