Output a byte

Output a byte

Postby mamcgu » Tue Feb 19, 2013 8:24 pm

It is discouraging to have to inquire about such a simple operation, but...
The job is to read and ADC and put the result on an LCD. I have gone over the manual multiple times and can't find a way to write a byte to 8 output pins.
Presumably after the ADC read you would have the result in string format in something like:
Code: Select all
dim lcdout$(4)
for i=1 to 4 step 1
character= lcdout(i)
' ?? here would go the byte move ??
next i

The question is how to get the 8 bit value from character to the 8 output pins. If there were an "and" instruction you could shift the bits one at a time, "and" out all but one, test the value and then "outd" a pin, for each pin. But that is not available. Is it really true that one can't move a byte to the output pins?
In PIC assembler you have
movf filereg1,w
movwf portc


Re: Output a byte

Postby admin » Wed Feb 20, 2013 12:18 am

One of the downsides of a 32-bit processor is that some byte oriented operations are a bit awkward; you have found one. On an LPC2136 the IO ports are 32-bits wide and IO can be awkward. Since bit-banging pins are a common operation I implemented bit IO and lived with some bulky code to do four bit IO for stepper drives and LCD's. Later there was a need for faster, wider and simultaneous IO and the PORT0, PORT1 and PORT instructions were added to the interpreter. See page 38 of the Language Reference for the details.

The bitwise and operator & and or operator + is described on page 23 of the Language Reference. To move a byte to the IO pins you should choose pins that are next go each other in the IO-port. The port status is read as P0=PORT0. Now AND P0 with a mask word to zero the bits not
used for the LCD, lets call it Mask0 and the data to output is New0 and the first used pin in Port0 is pinX.
P0 = PORT0 ' Read Port0
NewWord = ( New0 LSL pinX ) & Mask0 ' Shift the byte to the correct place in the 32-bit word and zero the other bits
P0 = P0 & ~Mask0 ' Zero the bits that are going to be updated
P0 = P0 + NewWord ' Or the IO bits into the 32-bit word
PORT0 = P0 ' Update the port

A few lines can be combined to make faster and more compact code but I have left them as separate lines for clarity. I have not tested this because I'm traveling but it should work or be close to correct.

Site Admin
Posts: 23
Joined: Thu Sep 27, 2012 12:22 pm

Re: Output a byte

Postby basic_mark » Sun May 12, 2013 2:23 pm

Have you had any success with outputting bytes?
Or anyone else had success?
I have not been able to write any text that doesn't return a syntax error on the port command.

None of these work for me:

Can anyone post an actual line for the port command that doesn't return a syntax error, or tell me what I am doing wrong?
Should x be a integer --> 13 or a binary as string --> "1101"?

Posts: 5
Joined: Thu Apr 25, 2013 6:04 pm
Location: Pennsylvania, USA

Re: Output a byte

Postby Andries Pretorius » Wed May 15, 2013 9:35 pm

I have not yet used the PORT functions, but reading through the language reference, I find it a bit obscure in terms of both syntax and usage. A few brief practical examples of the available options will help.

Can you assist Daniel?

Andries Pretorius
Posts: 37
Joined: Thu Nov 01, 2012 10:57 am
Location: Johannesburg, South Africa

Re: Output a byte

Postby basic_mark » Tue May 21, 2013 5:05 pm


I have figured out the syntax for the PORT function. There is no "=" sign, just the variable or value. I'm really not sure why I didn't think of this before.


These examples above will satisfy the syntax. I'll return later with some behavior after more experimentation.

Posts: 5
Joined: Thu Apr 25, 2013 6:04 pm
Location: Pennsylvania, USA

Return to EzSBC1

Who is online

Users browsing this forum: No registered users and 1 guest