From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=unavailable autolearn_force=no version=3.4.4 Path: border1.nntp.dca1.giganews.com!buffer1.nntp.dca1.giganews.com!border1.nntp.dca3.giganews.com!backlog3.nntp.dca3.giganews.com!border2.nntp.dca.giganews.com!nntp.giganews.com!usenet.blueworldhosting.com!feeder01.blueworldhosting.com!feeder.erje.net!eu.feeder.erje.net!eternal-september.org!feeder.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: Simon Clubley Newsgroups: comp.lang.ada Subject: Re: Cleanest Ada way to do this? Date: Mon, 23 Jun 2014 00:17:49 +0000 (UTC) Organization: A noiseless patient Spider Message-ID: References: <7eaee5fc-2045-4bb3-8b16-d757b54760da@googlegroups.com> <6yHpv.55741$G37.7010@fx07.iad> Injection-Date: Mon, 23 Jun 2014 00:17:49 +0000 (UTC) Injection-Info: mx05.eternal-september.org; posting-host="e458ff8b81bc0c159989eb0e36c6e372"; logging-data="7389"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/m6ngadxZTZ8W6JG+hwik3P0VEkPcn0u0=" User-Agent: slrn/0.9.8.1 (VMS/Multinet) Cancel-Lock: sha1:/GzStOtHIecLmxyZSHOke23Yvgo= X-Original-Bytes: 3426 Xref: number.nntp.dca.giganews.com comp.lang.ada:187179 Date: 2014-06-23T00:17:49+00:00 List-Id: On 2014-06-22, Shark8 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