comp.lang.ada
 help / color / mirror / Atom feed
From: Simon Clubley <clubley@remove_me.eisner.decus.org-Earth.UFP>
Subject: Re: Cleanest Ada way to do this?
Date: Mon, 23 Jun 2014 00:17:49 +0000 (UTC)
Date: 2014-06-23T00:17:49+00:00	[thread overview]
Message-ID: <lo7rnc$76t$1@dont-email.me> (raw)
In-Reply-To: 6yHpv.55741$G37.7010@fx07.iad

On 2014-06-22, Shark8 <OneWingedShark@gmail.com> wrote:
> On 22-Jun-14 10:51, Mike Silva wrote:
>> I'd like some help on the cleanest, or most elegant, way to do this in Ada.
>>  I'm writing to an LCD character display, in 4-bit mode, which requires writing
>> an 8 bit character or command value as two 4 bit pieces.  The port (a memory
>> address) being written to is 32 bits wide.  What I would like to be able to do
>> is some form of this (not valid Ada, I know):
>>
>>   Port32(4..7) := Some_Char(4..7);
>>   ..twiddle some other control bits..
>>   Port32(4..7) := Some_Char(0..3);
>>   ..twiddle some other control bits..
>>
>> Any thoughts?
>>
>
> Depends on the situation, I think; if there's a lot of them [ports] like 
> say one for each 'character' you may be better off making a generic 
> package to interface with it.
>

There will probably only be one 32 bit port in use for the LCD and only
a small subset of the bits will probably be in use (at least for driving
the LCD if it's the type of LCD I think it is).

It looks like Mike is implementing the traditional character LCD driver.
Intermixed with the display data will probably be command data including
things like cursor addressing and there will probably be additional I/O
lines for things like Read/Write select and data/command mode.

However, to reduce the amount of I/O pins you need to wire up, you can
command the LCD module to switch from 8-bit mode to 4-bit mode so you
end up sending each command or data character as two nibbles and that
looks like what Mike has done here.

My first pass at a design for this would be a 32-bit record type with
the bitfields laid out to correspond with the actual wiring of the I/O
port, so he has separate bitfields for both the R/W and data/command
lines as well as a 4-bit wide field for the above data lines.

If Mike needs to modify more than one of the bitfields at the same
time, then he will have to use a temporary variable. However, I've
just looked at some C code from a few years ago which does the same
thing and in that code, I don't appear to need to do that.

However, Pragma Atomic (and/or Volatile) are probably required.

Simon.

-- 
Simon Clubley, clubley@remove_me.eisner.decus.org-Earth.UFP
Microsoft: Bringing you 1980s technology to a 21st century world


  reply	other threads:[~2014-06-23  0:17 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-06-22 16:51 Cleanest Ada way to do this? Mike Silva
2014-06-22 19:07 ` Simon Clubley
2014-06-22 21:20   ` Mike Silva
2014-06-22 21:05 ` Shark8
2014-06-23  0:17   ` Simon Clubley [this message]
2014-06-23  6:46     ` hungupharps
2014-06-23  7:32       ` Georg Bauhaus
2014-06-23 11:48         ` Simon Clubley
2014-06-23 15:40           ` G.B.
2014-06-23  9:02 ` rrr.eee.27
2014-06-23 11:57   ` Simon Clubley
2014-06-23 12:05     ` rrr.eee.27
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox