Forum > Embedded - AVR
Very simple but necessary question
pascalbythree:
A very simple for all my Freepascal members:
Inside UnoLib:
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---unit liquidcrystal;
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---procedure Init(rs, rw, enable, d0, d1, d2, d3: UInt8); overload;
Now i use ccrause/fpc-avr:
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---unit lcd_config; interface const // LCD configuration lcd_lines = 4; // number of visible lines of the display lcd_displayLength = 16; // visibles characters per line of the display // Pin connections lcd_dataPin4 = 3; // pin for 4bit data bit 0 lcd_dataPin5 = 4; // pin for 4bit data bit 1 lcd_dataPin6 = 5; // pin for 4bit data bit 2 lcd_dataPin7 = 6; // pin for 4bit data bit 3 LCD_RS_PIN = 2; // pin for RS line LCD_RW_PIN = 1; // pin for RW line LCD_E_PIN = 2; // pin for Enable line var LCD_DATA4_PORT: byte absolute PORTD; // port for 4bit data bit 0 LCD_DATA5_PORT: byte absolute PORTD; // port for 4bit data bit 1 LCD_DATA6_PORT: byte absolute PORTD; // port for 4bit data bit 2 LCD_DATA7_PORT: byte absolute PORTD; // port for 4bit data bit 3 LCD_RS_PORT: byte absolute PORTB; // port for RS line LCD_RW_PORT: byte absolute PORTB; // port for RW line 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 [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---program TestLCDisplay; {DEFINED(fpc_mcu_atmega328p)} {$mode objfpc} uses timer, liquidcrystal; begin LC.Init(16, 15, 4, 5,6,11,12); LC._begin(16, 4); LC.Write('hello, world!'); while True do begin LC.NoDisplay; Delay(500); LC.Display; Delay(500); end;end.
--- Quote ---PS: I am using DataPin7 DataPin6 DataPin5 DataPin4 on my HD44780 display!
--- End quote ---
ccrause:
--- Quote from: pascalbythree on June 06, 2025, 03:06:33 pm ---
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---unit lcd_config; interface const // LCD configuration lcd_lines = 4; // number of visible lines of the display lcd_displayLength = 16; // visibles characters per line of the display // Pin connections lcd_dataPin4 = 3; // pin for 4bit data bit 0 lcd_dataPin5 = 4; // pin for 4bit data bit 1 lcd_dataPin6 = 5; // pin for 4bit data bit 2 lcd_dataPin7 = 6; // pin for 4bit data bit 3 LCD_RS_PIN = 2; // pin for RS line LCD_RW_PIN = 1; // pin for RW line LCD_E_PIN = 2; // pin for Enable line var LCD_DATA4_PORT: byte absolute PORTD; // port for 4bit data bit 0 LCD_DATA5_PORT: byte absolute PORTD; // port for 4bit data bit 1 LCD_DATA6_PORT: byte absolute PORTD; // port for 4bit data bit 2 LCD_DATA7_PORT: byte absolute PORTD; // port for 4bit data bit 3 LCD_RS_PORT: byte absolute PORTB; // port for RS line LCD_RW_PORT: byte absolute PORTB; // port for RW line LCD_E_PORT: byte absolute PORTD; // port for Enable line
--- End quote ---
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:
--- Quote from: pascalbythree on June 06, 2025, 03:06:33 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
--- End quote ---
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.
pascalbythree:
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 [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} --- 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:
--- Quote from: pascalbythree 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 [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} --- 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?
--- End quote ---
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 [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---"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"Reading 2226 bytes for flash from input file TestBlink.hexWriting 2226 bytes to flashWriting | ################################################## | 100% 0.59sReading | ################################################## | 100% 0.44s2226 bytes of flash verified Avrdude done. Thank you.
Why do you want to change the fusebits?
--- Quote from: pascalbythree on June 08, 2025, 02:51:56 pm ---If i may repeat, the examples can work on a Atmega328P on my breadboard ? Or only at full Arduino's?
--- End quote ---
Examples from UnoLib should work on Arduino Uno and may work on other Arduinos with ATmega328P (for example Arduino Nano).
Navigation
[0] Message Index
[#] Next page