Looking for Arduino code

nwrightson
Benutzer
Avatar
Gender:
Location: Newcastle
Age: 63
Homepage: nweha.homeserver.c…
Posts: 362
Registered: 08 / 2003
Subject:

Looking for Arduino code

 · 
Posted: 01.01.2014 - 12:24  ·  #1
Seasons Greetings to everyone,
Instead of reinventing the wheel, I'm wondering if anyone has written code for the Arduino modules and is willing to share. For a start, I'm looking for the LCD and 5 button keyboard (actually this is a A2D input where each button is a different voltage) and also looking for Ethernet modules.

Kind regards,
Neil.
nwrightson
Benutzer
Avatar
Gender:
Location: Newcastle
Age: 63
Homepage: nweha.homeserver.c…
Posts: 362
Registered: 08 / 2003
Subject:

Arduino LCD sort of works?

 · 
Posted: 21.01.2014 - 12:25  ·  #2
Hi All,
I guess no one has code for interfacing to Arduino boards. I'm using a 16*2 LCD.

I've written some code using the LCDUserPort LCD interface and I can write characters to the upper and lower lines.
The issue is that they do not start at 0,0 but start at 2,0 (2 blanks and then the text). After a reset, the upper line is drawn at 4,0. (4 blanks and then the text) etc until the text scrolls of the screen and I'm left with a blank screen.
The same happens for the second line.

Sample screen layout. ~ = Space
================
~~NWE A5
~~Ver3
================
After Reset
================
~~~~NWE A5
~~~~Ver3
================

After Power Cycle
================
~~NWE A5
~~Ver3
================

I have tried LCDType = 44780, 0070, 0073 etc.
The LCD board is labeled as "1602A V1.0" and appears to use a ST7066U controller.
http://www.futurlec.com/LED/ST7066U.shtml

Note - It works fine with the Arduino code that is written with the 44780 as it's base.

Ideas?

Thanks,
Neil.

Code

  LCDport        = LCDUserPort;
  LCDtype        = 0073;
  LCDrows        = 2,2;              {rows}   // No idea what the second 2 is ?
  LCDcolumns     = 16;             {columns per line}



Code

Procedure LCDTest;
Begin
  LCDclr;                               { clear display 1 }
  LCDcursor(true, false);               { display 1 on, cursor off & no blink }
  LCDhome;                              { cursor home }
  LCDxy(0, 0);                          { row 1 }
  Write(LCDout, 'NWE A5');
  LCDxy(0, 1);                          { row 2 }
  Write(LCDout, 'Ver='+Firmware_Version);
End;


Code

{ Const Declarations }
const
     LCD_Delay : Byte = 250 ;
{--------------------------------------------------------------}
{ Var Declarations }
{$IDATA}
var
// LCD Bits
  LCD_D4[@portG,5]    : Bit;
  LCD_D5[@portE,3]    : Bit;
  LCD_D6[@portH,3]    : Bit;
  LCD_D7[@portH,4]    : Bit;
  LCD_RS[@portH,5]    : Bit;
  LCD_EN[@portH,6]    : Bit;


{--------------------------------------------------------------}
{ functions }
UserDevice LCDIOS(cmd : byte; data : byte) : byte;
begin
  (* commands passed to user defined function "LCDIOS" *)
  (*  0  init               data = none    result = none       init user's hardware   *)
  (*  1  select display     data = 0/1     result = none       select display 1 or 2  *)
  (*  2  write dataport     data = byte    result = none       character output       *)
  (*  3  read  dataport     data = none    result = byte       character input        *)
  (*  4  write controlport  data = byte    resul  = none       command to display     *)
  (*  5  read  controlport  data = none    result = byte       get display state      *)

  // the display is operated in 4bit mode
  case cmd of
    0  : // hardware init
           DDRG.5 := 1 ; // D4
           DDRE.3 := 1 ; // D5
           DDRH.3 := 1 ; // D6
           DDRH.4 := 1 ; // D7
           DDRH.5 := 1 ; // LCD_RS
           DDRH.6 := 1 ; // LCD_EN
         LCD_RS := false;
         LCD_EN := false;
         cmd:= 0;
       |
    1  : // select display
         cmd:= 0;
       |
    2  : // write to data port
         LCD_RS := true;
         LCD_D4 := data.4;
         LCD_D5 := data.5;
         LCD_D6 := data.6;
         LCD_D7 := data.7;
         LCD_EN := true;
         uDelay(LCD_Delay);
         LCD_EN := false;
         
         LCD_D4 := data.0;
         LCD_D5 := data.1;
         LCD_D6 := data.2;
         LCD_D7 := data.3;
         LCD_EN := true;
         uDelay(LCD_Delay);
         LCD_EN := false;
       |
    3  : // read from dataport
         cmd:= 0;
       |
    4  : // write to control port
         LCD_RS := false;
         LCD_D4 := data.4;
         LCD_D5 := data.5;
         LCD_D6 := data.6;
         LCD_D7 := data.7;
         LCD_EN := true;
         uDelay(LCD_Delay);
         LCD_EN := false;
         
         LCD_D4 := data.0;
         LCD_D5 := data.1;
         LCD_D6 := data.2;
         LCD_D7 := data.3;
         LCD_EN := true;
         uDelay(LCD_Delay);
         LCD_EN := false;
       |
    5  : // read from control port
         cmd:= 0;
       |
  endcase;
  return(cmd);
end;
{$D+}

procedure LCDportInit;
begin
  mDelay(10);

    LCDclr;                               { clear display 1 }
    LCDcursor(True, true);      { display 1 on, cursor off & no blink }

    mDelay(10);
end;


initialization
// at StartUp
   LCDportInit;
Harry
Moderator
Avatar
Gender:
Location: zwischen Augsburg und Ulm
Age: 59
Posts: 2133
Registered: 03 / 2003
Subject:

Re: Looking for Arduino code

 · 
Posted: 21.01.2014 - 13:27  ·  #3
Hello Neil,

some displays need a delay after some functions. e.g. the DOGM162 with ST7036-controller must have a delay >1.03ms after clear and home.

greetings
Harry

[Edit]1.52ms delay at ST7066 (clear/home) :angry1:
nwrightson
Benutzer
Avatar
Gender:
Location: Newcastle
Age: 63
Homepage: nweha.homeserver.c…
Posts: 362
Registered: 08 / 2003
Subject:

Re: Looking for Arduino code

 · 
Posted: 21.01.2014 - 21:11  ·  #4
Thanks Harry,
Unfortunatley this did not work. :(
I inserted a 50mS delay between every LCD statement and added a 50mS delay at the actual area for writing to the control port but neither made a difference (other than going slower).

Maybe internally AVRCo is doing other things that require delays?

Code

Procedure LCDTest;
Var D : Word ;
Begin
D:=50;
  LCDclr;                               { clear display 1 }
    mDelay(D);
  LCDcursor(true, false);               { display 1 on, cursor off & no blink }
    mDelay(D);
  LCDhome;                              { cursor home }
    mDelay(D);
  LCDxy(0, 0);                          { row 1 }
    mDelay(D);
  Write(LCDout, 'N.W.E. A5');
    mDelay(D);
  LCDxy(0, 1);                          { row 2 }
    mDelay(D);
  Write(LCDout, 'Ver='+Firmware_Version);
    mDelay(D);
End;


Code

    4  : // write to control port
         LCD_RS := false;
         LCD_D4 := data.4;
         LCD_D5 := data.5;
         LCD_D6 := data.6;
         LCD_D7 := data.7;
         LCD_EN := true;
         uDelay(LCD_Delay);
         LCD_EN := false;
    mDelay(50);

         LCD_D4 := data.0;
         LCD_D5 := data.1;
         LCD_D6 := data.2;
         LCD_D7 := data.3;
         LCD_EN := true;
         uDelay(LCD_Delay);
         LCD_EN := false;
    mDelay(50);
       |
Merlin
Administrator
Avatar
Gender:
Age: 24
Posts: 1408
Registered: 03 / 2005
Subject:

Re: Looking for Arduino code

 · 
Posted: 22.01.2014 - 11:14  ·  #5
Hi Neil.

I know that software guys are always prone to blame hardware, but.. Have you checked with another display (indeed is this an option)?

Also I would have thought that LCDhome and LCDXY(0,0) did the same thing. It might be worth removing one of them and seeing if it just moved right by one space per reset. It might give a clue as to what is going on.
Harald_K
 
Avatar
 
Subject:

Re: Looking for Arduino code

 · 
Posted: 22.01.2014 - 17:37  ·  #6
first, you should remove the ",2" at your LCDrows = 2,2 statement.

(typical "handbook not read error" ;) )

the ,2 means, that you have connected an LCD module with 2 Enable lines - this means the module has so many character positions that it is not adressable with a single lcd controller (more than 80 chars), and so the module uses 2 controllers which are separated only at he E-line of the lcd interface.

second problem is your lcd init routine ....

if you want to use the lcd in 4bit mode, you must use the init sequence of the controller data sheet -
normally, this means:
15ms delay after power-up
send 8bit-Datalength command by 1 single E- up & down
wait 5ms
send 8bit Datalength command by 1 single E up & down
wait 1ms
send 4bit Datalength command by 1 singe E up & down
wait 1ms
now you can send further commands by the 4bit-I/F-sequence with upper/lower nibble and 2 E up&down clockings

the 1st "set4bit" you must send as 8-Bit-command, because the lcd expects 8bit Data after power-up.

the 2 initially sent "set8bitI/F" are needed because the lcd might still be in 4bit-mode when the atmel is resettet but the display has remained in 4bit-mode e.g. after brown-out reset or something ...


probably, it is a good idea to use the normal LCD interface routines of the AVRco and look in the generated assembler listing how the compiler initializes the display.
Selected quotes for multi-quoting:   0

Registered users in this topic

Currently no registered users in this section

The statistic shows who was online during the last 5 minutes. Updated every 90 seconds.
MySQL Queries: 15 · Cache Hits: 14   108   122 · Page-Gen-Time: 0.046075s · Memory Usage: 2 MB · GZIP: on · Viewport: SMXL-HiDPI