Programming mikroPascal ( I love it )
for a while but I don't get a clear total overview about digital I/O.
Configuring single bits or complete byte as input or output.
This example confuses me "Button" ( from mikroPascal PRO for AVR Help )
1) DDB0_bit := 0; // set PORTB to be input
2) DDRC := 0xFF; // configure PORTC as output
3) PORTC := 0xAA; // initial PORTC value
Makes sence: DDR makes a complete output on port C ( complete byte, 8bit )
Whole port B is set to be input, but it shows DDB followed by 0_bit...
Why/how?
Tnx in advance.
Digital I/O on AVR in mikroPascal
-
- Posts: 161
- Joined: 14 Mar 2016 10:24
- Contact:
Digital I/O on AVR in mikroPascal
To DIY or not to DIY
-
- Posts: 161
- Joined: 14 Mar 2016 10:24
- Contact:
Re: Digital I/O on AVR in mikroPascal
What I have working since starting mikroPascal-AVR on my 2560:
Digital-out ( by byte and/or single bit )
LCD by 6 wires ( 4-data, 2-signal )
RS232 uart: to from pc (Lazarus)
ADC: 8 channels, still have to find out how to reach all 16 channels
Digital input: I don't get it.
Can't be that hard...
Digital-out ( by byte and/or single bit )
LCD by 6 wires ( 4-data, 2-signal )
RS232 uart: to from pc (Lazarus)
ADC: 8 channels, still have to find out how to reach all 16 channels
Digital input: I don't get it.
Can't be that hard...
To DIY or not to DIY
- Aleksandar.Mitrovic
- mikroElektronika team
- Posts: 1697
- Joined: 11 Mar 2015 12:48
Re: Digital I/O on AVR in mikroPascal
Hi,
If you take a look at the datashet for the ATmega2560 you will find :
Number "0" will seet all register to the value 0, no matter how big it is.
If you are setting whole port to "1" we suggest you to use 0xFF.
Can you please explain it which problem exactly do you have with Digital Inputs and ADC?
Kind regards,
Aleksandar
If you take a look at the datashet for the ATmega2560 you will find :
So if you want to use pin as a button it should be input, or in this case DDxn = 0.The DDxn bit in the DDRx Register selects the direction of this pin. If DDxn is written logic one,
Pxn is configured as an output pin. If DDxn is written logic zero, Pxn is configured as an input
pin.
Number "0" will seet all register to the value 0, no matter how big it is.
If you are setting whole port to "1" we suggest you to use 0xFF.
Can you please explain it which problem exactly do you have with Digital Inputs and ADC?
Kind regards,
Aleksandar
-
- Posts: 161
- Joined: 14 Mar 2016 10:24
- Contact:
Re: Digital I/O on AVR in mikroPascal
Tnx.
For the moment, I will study the datasheet.
Want to find out how to acces all the 16 ADC inputs ( channel 8 to 15 ) of the 2560
and a ( better ) understanding of declaration/use of digital input
All regards.
For the moment, I will study the datasheet.
Want to find out how to acces all the 16 ADC inputs ( channel 8 to 15 ) of the 2560
and a ( better ) understanding of declaration/use of digital input
All regards.
To DIY or not to DIY
-
- Posts: 57
- Joined: 09 Oct 2014 17:39
Re: Digital I/O on AVR in mikroPascal
Code: Select all
DDRx := %00110000; <= Input mode where '0', output mode where '1'
PORTx := %01010101; <= In output mode set output level, in input mode '1' enables pullup for input pin
Temp := PINx; <= Read pin state, whatever it mode is.
If you want one bit - you should mask it. F.e. PINx and $01.
Some AVRs support the Pin toggling while it in output mode (2560 does). Writing a logic one to PINxn toggles the value of PORTxn, independent on the value of DDRxn. Note that the SBI instruction can be used to toggle one single bit in a port. That's right: PINx can be written.
As for ADC analog inputs, you should set up DIDR0 and DIDR2 registers to switch off digitall part of port. See ADC section in datasheet.
-
- Posts: 161
- Joined: 14 Mar 2016 10:24
- Contact:
Re: Digital I/O on AVR in mikroPascal
The data sheet makes sence!.
Slowly things are getting clear!
Before I started to use 2560 ( or better said: microcontrollers at all ),
I had only experience with the 82c55a I/O-periphical chip's on my DIY-ISA-slot-pcb's, programmed in TurboPascal 7.
( http://europakade.nl/motion-control-and-robots )
( https://www.youtube.com/playlist?list=P ... uG4mvriLgJ )
Marcel.
Slowly things are getting clear!
Before I started to use 2560 ( or better said: microcontrollers at all ),
I had only experience with the 82c55a I/O-periphical chip's on my DIY-ISA-slot-pcb's, programmed in TurboPascal 7.
( http://europakade.nl/motion-control-and-robots )
( https://www.youtube.com/playlist?list=P ... uG4mvriLgJ )
Marcel.
To DIY or not to DIY
-
- Posts: 161
- Joined: 14 Mar 2016 10:24
- Contact:
Re: Digital I/O on AVR in mikroPascal
See here the ADC's ( channel 0 to 7 ) reading and send by RS232-uart to pc-Lazarus:
( topic: http://forum.mikroe.com/viewtopic.php?f ... 6&start=30 )
( topic: http://forum.mikroe.com/viewtopic.php?f ... 6&start=30 )
To DIY or not to DIY
-
- Posts: 161
- Joined: 14 Mar 2016 10:24
- Contact:
Re: Digital I/O on AVR in mikroPascal
It's functioning!
Here full byte as input:
Don;t mind 'inc[shPosInStOut], it's of the 'upper-loop'.
Here full byte as input:
Code: Select all
// init
DDRC:= 0;
PORTC:= 255;
// some code
for shCntrButton:= 4 to 7 do // hardware 4..7 connected
begin
if ( pinC.shCntrButton )
then stOut[shPosInStOut]:= '1'
else stOut[shPosInStOut]:= '0';
inc(shPosInStOut);
end;
Don;t mind 'inc[shPosInStOut], it's of the 'upper-loop'.
To DIY or not to DIY
-
- Posts: 161
- Joined: 14 Mar 2016 10:24
- Contact:
Re: Digital I/O on AVR in mikroPascal
Ok!
It works in different ways of coding:
Input 'copied' to an LED-output:
One way:
Another way:
It works in different ways of coding:
Input 'copied' to an LED-output:
Code: Select all
// init
portH6_bit:= 0;
DDRC:= %00000000
portC:= %00000000
Code: Select all
// some code
portH6_bit:= pinC3_bit;
Another way:
Code: Select all
// some code
portH.6:= pinC.3;
To DIY or not to DIY
-
- Posts: 161
- Joined: 14 Mar 2016 10:24
- Contact:
Re: Digital I/O on AVR in mikroPascal
My understanding of the ADC-functioning has been increased a lot also!
for example:
Reading the ADC channel above [0..7] shouldn't be a problem anymore...
Need MUX bit5.
Made an overview:
for example:
Reading the ADC channel above [0..7] shouldn't be a problem anymore...
Need MUX bit5.
Made an overview:
To DIY or not to DIY
-
- Posts: 161
- Joined: 14 Mar 2016 10:24
- Contact:
Re: Digital I/O on AVR in mikroPascal
Thanks to subscriber voodle for the code above.
From that point, I contineu and add more code.
From that point, I contineu and add more code.
To DIY or not to DIY