News:

Let's find out together what makes a PIC Tick!

Main Menu

Port Manipulation.

Started by dr-zin, Apr 06, 2021, 05:03 PM

Previous topic - Next topic

dr-zin

As I'm trying to round out my knowledge base of this compiler's features, I'll ask another newbie question...
If you assign a PIC's port to a variable, you can use the marvelous bitwise functions to easily move, shift, invert, etc. the bits in that port.  With a chip like the 16F628, there is a full compliment (B0-B7) of pins to make a byte of data from. However, for a device like the 16F630 (14 pins only), the ports consist of A0-A5 and C0-C5.  Is there an easy way to stitch pins from 2 different ports together on a chip like this to get an 8 bit "port" that can be bitwise manipulated using a full sized byte variable?  I know this should be possible, as languages like Verilog and CUPL allow you to group any I/O pins together to make a custom "field" structure.  What magic glue am I missing to make this work in Proton?  Thanks in advance for your time and consideration...

top204

#1
Microcontrollers are very different to FPGA devices, in that an FPGA does not contain "any" ports or any other feature of a microcontroller, and the ports, and other peripherals, and core, are built within them.

On an microcontroller, a shadow byte variable can be used to hold the contents that will be placed on a port, or read from a port, then the shadow variable is transfered to the two seperate port bits individually so that what is in the shadow variable is on the combined ports, or the individual pins are transfererd to a shadow port variable. However, this produces large code and produces slower code for every access to a Pin or Port.

My advice.... Change to a more suitable device, and "any" device other than the now, very outdated, standard 14-bit core types. :-)


m.kaviani

Hi dr.zin
try to assign every individual pin to a variable's bits in the positron compiler.

trisc = $00       ' all output
trisb = %00       ' all output
dim b1 as byte    ' define a variable
symbol b1.0 = portb.0  ' assign a port to a variable's bit
symbol b1.1 = portb.1
symbol b1.2 = portb.2
symbol b1.3 = portb.3
symbol b1.4 = portc.0
symbol b1.5 = portc.1
symbol b1.6 = portc.2
symbol b1.7 = portc.3

b1 = %00001111      ' transfer data to ports
b1 = %11101001

top204

#3
Please test code before posting a suggestion.

Your code will not compile because you cannot assign a constant value or alias to a Bit text as the name. Also, the principle is incorrect... Symbol and Dim are compile-time directives, not run-time commands.

The bits will need to be assigned or read individually using either a procedure or a pre-processor meta-macro. But both ways will produce a lot of code just to write or read a port.

See_Mos

#4
 Have a look at the logical operators starting on page 79 of the current manual PDF.

6 bits on each port = 12 bits so try this instead.   

dummy test variables used for PortX were %110011 and for PortY %001100

Dim Port_Control As Word
Dim Temp As Word

Port_Control = PortX << 6            ' %110011 is placed in bits 6 to 11 of Port_Control
Port_Control = Port_Control | PortY  ' use the OR command to add PortY to bits 0 to 5 of Port_Control
                                     ' Port_Control is now %110011 001100
Temp = Port_Control & %010101111111  ' Temp now = %010001 001100
PortY = Temp >> 6                    ' PortY is now %010001

or instead of using Temp you could simply use
PortY = Port_Control >> 6

doing it this way you can shift all 12 bits in either direction.  When using shift left you may need to remove the unwanted upper four bits of the word variable by & the result with %0000 1111 1111 1111 or $0FFF

dr-zin

Hello all.  Sorry for the slow response, but I'm 8 hrs. west of the Prime Meridian.  Les (I presume), your point is well taken-- I shouldn't compare the structure of GALs and CPLDs to u-processors, nor should I compare Verilog to traditional linear prog. languages.  If there is no built-in provision for handling this problem, then no worries.  I know I can shift, invert, etc. multiple ports within the same routine and CAREFULLY intercept and transfer the end bits to the next port as needed.  See_Mos' solution seems intriguing, and well worth a try.

No, I don't usually use the high end Microchip products; I like to do more with less when I can.  Software serial routines are as good for me as dedicated hardware ports.  I shop on the upper floors only when there is a feature I need that can't be provided by the Plain Jane models.  That's why I ask these kinds of questions-- I want to know if I can get premium horsepower from minimal engines.

The problem is that [atomic particle] BASIC is so powerful and well thought out that I assume that if there is a problem I run into, there MUST somehow be a function or tweek that everyone else is aware of except me.  So please excuse my paranoia and feelings of inadequacy when they crop up.  In a way, I'm glad the answer was non-obvious and made us all think about things in a different way.  Thanks to all who read and/or responded.  This is definitely a positive, friendly environment to ask questions and learn.  Cheers