Recent

Author Topic: Very simple but necessary question  (Read 627 times)

pascalbythree

  • Sr. Member
  • ****
  • Posts: 277
Very simple but necessary question
« on: June 06, 2025, 03:06:33 pm »
A very simple for all my Freepascal members:

Inside UnoLib:
Code: Pascal  [Select][+][-]
  1. unit liquidcrystal;
Code: Pascal  [Select][+][-]
  1. procedure Init(rs, rw, enable, d0, d1, d2, d3: UInt8); overload;

Now i use ccrause/fpc-avr:
Code: Pascal  [Select][+][-]
  1. unit lcd_config;
  2.  
  3. interface
  4.  
  5. const
  6.   // LCD configuration
  7.   lcd_lines         = 4;     // number of visible lines of the display
  8.   lcd_displayLength = 16;    // visibles characters per line of the display
  9.  
  10.   // Pin connections
  11.   lcd_dataPin4      = 3;         // pin for 4bit data bit 0
  12.   lcd_dataPin5      = 4;         // pin for 4bit data bit 1
  13.   lcd_dataPin6      = 5;         // pin for 4bit data bit 2
  14.   lcd_dataPin7      = 6;         // pin for 4bit data bit 3
  15.   LCD_RS_PIN        = 2;            // pin  for RS line
  16.   LCD_RW_PIN        = 1;            // pin  for RW line
  17.   LCD_E_PIN         = 2;            // pin  for Enable line
  18.  
  19. var
  20.   LCD_DATA4_PORT: byte absolute PORTD;     // port for 4bit data bit 0
  21.   LCD_DATA5_PORT: byte absolute PORTD;     // port for 4bit data bit 1
  22.   LCD_DATA6_PORT: byte absolute PORTD;     // port for 4bit data bit 2
  23.   LCD_DATA7_PORT: byte absolute PORTD;     // port for 4bit data bit 3
  24.   LCD_RS_PORT: byte absolute PORTB;        // port for RS line
  25.   LCD_RW_PORT: byte absolute PORTB;        // port for RW line
  26.   LCD_E_PORT: byte absolute PORTD;         // port for Enable line

Question: can somebody help me out with formatting the LC.Init(12, 11, 5, 4, 3, 2); procedure ?
Is it possible at all to use liquidcrystal.pas on a Atmega328p already own etched board ? or does it only work on Arduino?
Must i change something in the defined section ?

Greets, Wouter van Wegen, pascalbythree

I tried:
Code: Pascal  [Select][+][-]
  1. program TestLCDisplay;
  2.  
  3. {DEFINED(fpc_mcu_atmega328p)}
  4.  
  5.  
  6. {$mode objfpc}
  7.  
  8. uses
  9.   timer, liquidcrystal;
  10.  
  11. begin
  12.   LC.Init(16, 15, 4, 5,6,11,12);
  13.   LC._begin(16, 4);
  14.   LC.Write('hello, world!');
  15.  
  16.   while True do
  17.   begin
  18.     LC.NoDisplay;
  19.     Delay(500);
  20.  
  21.     LC.Display;
  22.     Delay(500);
  23.   end;
  24. end.

Quote
PS: I am using DataPin7 DataPin6 DataPin5 DataPin4 on my HD44780 display!
« Last Edit: June 06, 2025, 03:31:39 pm by pascalbythree »

ccrause

  • Hero Member
  • *****
  • Posts: 1025
Re: Very simple but necessary question
« Reply #1 on: June 06, 2025, 04:29:21 pm »
Code: Pascal  [Select][+][-]
  1. unit lcd_config;
  2.  
  3. interface
  4.  
  5. const
  6.   // LCD configuration
  7.   lcd_lines         = 4;     // number of visible lines of the display
  8.   lcd_displayLength = 16;    // visibles characters per line of the display
  9.  
  10.   // Pin connections
  11.   lcd_dataPin4      = 3;         // pin for 4bit data bit 0
  12.   lcd_dataPin5      = 4;         // pin for 4bit data bit 1
  13.   lcd_dataPin6      = 5;         // pin for 4bit data bit 2
  14.   lcd_dataPin7      = 6;         // pin for 4bit data bit 3
  15.   LCD_RS_PIN        = 2;            // pin  for RS line
  16.   LCD_RW_PIN        = 1;            // pin  for RW line
  17.   LCD_E_PIN         = 2;            // pin  for Enable line
  18.  
  19. var
  20.   LCD_DATA4_PORT: byte absolute PORTD;     // port for 4bit data bit 0
  21.   LCD_DATA5_PORT: byte absolute PORTD;     // port for 4bit data bit 1
  22.   LCD_DATA6_PORT: byte absolute PORTD;     // port for 4bit data bit 2
  23.   LCD_DATA7_PORT: byte absolute PORTD;     // port for 4bit data bit 3
  24.   LCD_RS_PORT: byte absolute PORTB;        // port for RS line
  25.   LCD_RW_PORT: byte absolute PORTB;        // port for RW line
  26.   LCD_E_PORT: byte absolute PORTD;         // port for Enable line

The Arduino framework maps from hardware ports and pins to Arduino digital pin numbers:
Arduino digital pin 0 - 7 maps to PORTD pins 0 - 7
Arduino digital pin 8 - 13 maps to PORTB pins 0 - 5

Mapping the config above to Arduino pins:
rs = 10
rw = 9
enable = 10 (?)
d0 = 3
d1 = 4
d2 = 5
d3 = 6

ackarwow

  • Full Member
  • ***
  • Posts: 143
    • Andrzej Karwowski's Homepage
Re: Very simple but necessary question
« Reply #2 on: June 07, 2025, 07:10:28 pm »
Question: can somebody help me out with formatting the LC.Init(12, 11, 5, 4, 3, 2); procedure ?
Is it possible at all to use liquidcrystal.pas on a Atmega328p already own etched board ? or does it only work on Arduino?
Must i change something in the defined section ?

Greets, Wouter van Wegen, pascalbythree

Hi @pascalbythree.
liquidcrystal.pas is (or more precisely - should be) compatible with Arduino Uno board. As @ccrause mentioned - all parameters of the Init procedure are pin numbers according to Arduino nomenclature (pin numbering). Of course you can use it with Arduino Uno board and compile it with FPC/Lazarus or AVRPascal editor, as you prefer.

Edit liquidcrystal.pas is a translation of the Arduino LiquidCrystal.cpp/h library and should be used exactly as shown in the Arduino LiquidCrystal examples.
« Last Edit: June 07, 2025, 07:42:43 pm by ackarwow »

pascalbythree

  • Sr. Member
  • ****
  • Posts: 277
Re: Very simple but necessary question
« Reply #3 on: June 08, 2025, 02:51:56 pm »
In the mean while, when i want to use my own programmer / SH script. Are these parameters correct to run a UnoLib.0.9 example on my atmega328p?

Code: Pascal  [Select][+][-]
  1.  avrdude -c usbasp -p atmega328p -U flash:w:TestBlink.hex -C /home/pascalbythree/WVW_AVRDUDE/avrdude-5_10/avrdude.conf -U lfuse:r:-:h -U hfuse:r:-:h -U efuse:r:-:h -v

Or do i got the fuses wrong?

If i may repeat, the examples can work on a Atmega328P on my breadboard ? Or only at full Arduino's?

--> Back later at the LCD

ackarwow

  • Full Member
  • ***
  • Posts: 143
    • Andrzej Karwowski's Homepage
Re: Very simple but necessary question
« Reply #4 on: June 08, 2025, 04:49:15 pm »
In the mean while, when i want to use my own programmer / SH script. Are these parameters correct to run a UnoLib.0.9 example on my atmega328p?

Code: Pascal  [Select][+][-]
  1.  avrdude -c usbasp -p atmega328p -U flash:w:TestBlink.hex -C /home/pascalbythree/WVW_AVRDUDE/avrdude-5_10/avrdude.conf -U lfuse:r:-:h -U hfuse:r:-:h -U efuse:r:-:h -v

Or do i got the fuses wrong?

Hi @pascalbythree

Here are the command line parameters used by the AVRPascal editor on my computer with Windows OS. You need to change the paths to avrdude.exe, avrdude.conf and the hex file to your own, as well as the port number (com3 on my computer): 

Code: Text  [Select][+][-]
  1. "C:\Programs\avr\avrpascal\bin\x86_64-win64\avrdude.exe" "-CC:\Programs\avr\avrpascal\bin\x86_64-win64\avrdude.conf" -pm328p -Pcom3 -carduino -b115200 "-Uflash:w:C:\Programs\avr\avrpascal\examples\TestBlink.hex:i"
  2. Reading 2226 bytes for flash from input file TestBlink.hex
  3. Writing 2226 bytes to flash
  4. Writing | ################################################## | 100% 0.59s
  5. Reading | ################################################## | 100% 0.44s
  6. 2226 bytes of flash verified
  7.  
  8. Avrdude done.  Thank you.
  9.  
  10.  

Why do you want to change the fusebits?

If i may repeat, the examples can work on a Atmega328P on my breadboard ? Or only at full Arduino's?

Examples from UnoLib should work on Arduino Uno and may work on other Arduinos with ATmega328P (for example Arduino Nano).



pascalbythree

  • Sr. Member
  • ****
  • Posts: 277
Re: Very simple but necessary question
« Reply #5 on: June 09, 2025, 03:50:55 pm »
Yay ! it got to work. thank you all.

I just needed this table:


 

TinyPortal © 2005-2018