Recent

Author Topic: avr hardware pins acces from pascal[SOLVED]  (Read 1783 times)

diego bertotti

  • New member
  • *
  • Posts: 14
avr hardware pins acces from pascal[SOLVED]
« on: January 16, 2019, 01:43:19 pm »
hi, im trying fpc/lazarus to avr/arduino and it works! thank you. thank you thank you very very much!!!

but, if we don`t forget the atmega328 is a microcontroller, maybe a bit oriented view will be mandatory

when you need test a pin status , we need to read a whole port, and them mask the wanted bit, and the assembler generated don`t seems efficient (i guess).

when you need to output a bit, the assembler generated is good, but you may type things like that:

Code: Pascal  [Select]
  1.  
  2. PortB:= PortB AND %11111011;
  3.  
  4.  

then assembler generated is: cbi 5,0--its ok! but you must type a whole line!! >:D

or another example

Code: Pascal  [Select]
  1.  
  2. PORTB :=PORTB and not ( 1 shl 5 ) ;  // LED pin5 off
  3.  
  4.  

with a native new class "bit", may will can access bits more directly like turbo51 does for 8051 microcontroller:

example:

Code: Pascal  [Select]
  1.  
  2. P2.5:= true; //set bit 5 of port 2
  3.  
  4. if p2.5 then p2.4:= false; //if pin 5 of port 2 is set, then clear pin 4 of port 2
  5.  
  6.  

i looking the assembler instructions set of avr it can be do it (i guess)

again thank you very very very much!
« Last Edit: January 16, 2019, 11:06:41 pm by diego bertotti »

ttomas

  • Full Member
  • ***
  • Posts: 178
Re: avr hardware pins acces from pascal
« Reply #1 on: January 16, 2019, 01:53:46 pm »
You can use bit packed record TByteBits
http://wiki.freepascal.org/Bit_manipulation

avra

  • Hero Member
  • *****
  • Posts: 1531
    • Additional info
ct2laz - Conversion between Lazarus and CodeTyphon
bithelpers - Bit manipulation for standard types
pasettimino - Siemens S7 PLC lib

diego bertotti

  • New member
  • *
  • Posts: 14
Re: avr hardware pins acces from pascal
« Reply #3 on: January 16, 2019, 07:04:35 pm »
Thanks for replys

Maybe i don't be clear enough. My apologies. Its about assembler code generated by compiler, then only apply to avr.

And also to shortened the typed string. Im lazy

Maybe bitpacked will work. Ill try

I dont found documentation specific of avr feeepascal
Thanks again
« Last Edit: January 16, 2019, 07:08:29 pm by diego bertotti »

diego bertotti

  • New member
  • *
  • Posts: 14
Re: avr hardware pins acces from pascal
« Reply #4 on: January 16, 2019, 10:03:28 pm »
i Found IT!!

Code: Pascal  [Select]
  1. Var
  2. PuertoD: bitpacked array [0..7] of boolean absolute PORTD;
  3.  
  4.  
  5. begin
  6.  PuertoD[5]:= true;
  7.  PuertoD[5]:= false;
  8. end;  
  9.  
  10.  

and the generated assembler code was:
Code: Pascal  [Select]
  1.         sbi     11,5
  2.         cbi     11,5
  3.  
For output. Great news.. it work very well!! :)

remain found the way for read input bits!!
« Last Edit: January 16, 2019, 10:52:39 pm by diego bertotti »

diego bertotti

  • New member
  • *
  • Posts: 14
Re: avr hardware pins acces from pascal
« Reply #5 on: January 16, 2019, 11:02:57 pm »
and another aproach!


Code: Pascal  [Select]
  1. var
  2. PuertoD: bitpacked array [0..7] of boolean absolute PORTD;
  3. PinesD: bitpacked array [0..7] of boolean absolute PinD;  
  4.  
  5. begin
  6.  PuertoD[5]:= true;
  7.  PuertoD[5]:= False;
  8.  If PinesD[1] then
  9.   begin
  10.   PuertoD[5]:= False;
  11.   end;
  12. end.
  13.  

and assembler was....
Code: Pascal  [Select]
  1.         sbi     11,5
  2.         cbi     11,5
  3.         in      r18,9
  4.         sbrs    r18,1
  5.         rjmp    .Lj95
  6. .Lj94:
  7.         cbi     11,5
  8. .Lj95:
  9.        
  10.  

excellent! but for brach/ jump (if statement)

diego bertotti

  • New member
  • *
  • Posts: 14
Re: avr hardware pins acces from pascal[SOLVED]
« Reply #6 on: April 30, 2019, 02:10:15 pm »
hi

im back

in last example, assembler use IN instruction to move port data to a r18 register, and then test bit. Will be better use branch instruction reading real port pin.

¿anybody know who can change this in the avr compiler?

where can i make contributions?

thanks

Laksen

  • Hero Member
  • *****
  • Posts: 611
    • J-Software
Re: avr hardware pins acces from pascal[SOLVED]
« Reply #7 on: April 30, 2019, 07:00:45 pm »
I just added that to trunk.

diego bertotti

  • New member
  • *
  • Posts: 14
Re: avr hardware pins acces from pascal[SOLVED]
« Reply #8 on: May 02, 2019, 01:44:37 pm »
I just added that to trunk.
hi
thanks laksen!
how i can know when update/fix is online?
again, thanks

sstvmaster

  • Full Member
  • ***
  • Posts: 100
Re: avr hardware pins acces from pascal[SOLVED]
« Reply #9 on: May 02, 2019, 04:45:54 pm »
Lazarus 2.0.2 x32
Lazarus 2.1.0 Trunk x32
OS Win 7 32bit

diego bertotti

  • New member
  • *
  • Posts: 14
Re: avr hardware pins acces from pascal[SOLVED]
« Reply #10 on: May 03, 2019, 01:28:48 pm »
thanks sstvmaster

diego bertotti

  • New member
  • *
  • Posts: 14
Re: avr hardware pins acces from pascal[SOLVED]
« Reply #11 on: May 03, 2019, 10:39:59 pm »
hi

congratulations!!!

for this pascal code

Code: Pascal  [Select]
  1.    If Not PDin[2] Then PBout[0]:= True else PBout[0]:= False;
  2.    If Not PDin[4] Then PDout[7]:= True else PDout[7]:= False;
  3.    If Not PBin[5] Then PDout[6]:= True else PDout[6]:= False;
  4.    If Not PBin[4] Then PDout[5]:= True else PDout[5]:= False;
  5.    If Not PBin[3] Then PCout[0]:= True else PCout[0]:= False;
  6.    If Not PBin[2] Then PDout[3]:= True else PDout[3]:= False;
  7.  

now the compiler generated assembler is:

Code: Pascal  [Select]
  1. .Lj80:
  2.         sbic    9,2
  3.         rjmp    .Lj57
  4. .Lj58:
  5.         sbi     5,0
  6.         rjmp    .Lj59
  7. .Lj57:
  8.         cbi     5,0
  9. .Lj59:
  10.         sbic    9,4
  11.         rjmp    .Lj61
  12. .Lj62:
  13.         sbi     11,7
  14.         rjmp    .Lj63
  15. .Lj61:
  16.         cbi     11,7
  17. .Lj63:
  18.         sbic    3,5
  19.         rjmp    .Lj65
  20. .Lj66:
  21.         sbi     11,6
  22.         rjmp    .Lj67
  23. .Lj65:
  24.         cbi     11,6
  25. .Lj67:
  26.         sbic    3,4
  27.         rjmp    .Lj69
  28. .Lj70:
  29.         sbi     11,5
  30.         rjmp    .Lj71
  31. .Lj69:
  32.         cbi     11,5
  33. .Lj71:
  34.         sbic    3,3
  35.         rjmp    .Lj73
  36. .Lj74:
  37.         sbi     8,0
  38.         rjmp    .Lj75
  39. .Lj73:
  40.         cbi     8,0
  41. .Lj75:
  42.         sbic    3,2
  43.         rjmp    .Lj77
  44. .Lj78:
  45.         sbi     11,3
  46.         rjmp    .Lj50
  47. .Lj77:
  48.         cbi     11,3
  49.         rjmp    .Lj50      
  50.  
:D :D :D