µTasker Forum
µTasker Forum => NXPTM M522XX, KINETIS and i.MX RT => Topic started by: evgenik on June 05, 2008, 02:27:09 PM
-
Hi Mark.
How I can define ports for In/Out? uTasker have any functions: fnConfigPort(..), fnConfigOutputPort(..), fnSetUserPortOut(..). What is the function that i need for ports defenition. I wrote at the same function (for configuration port QS) as your but don't know correctly or no?
#define PORTQS_IN_OUT_DEFINITION 0x7D; // X111.1101 where 1 = OUT, 0 = IN
PORTQS1 = 1
PORTQS2 = 0
PORTQS3 = 1
PORTQS4 = 1
PORTQS5 = 1
PORTQS6 = 1
PORTQS7 = 1
extern int fnConfigureMyPort()
{
CHAR cType;
CHAR cPortBit = '0';
u8 sPort = 0;
unsigned char ucBit = 1;
unsigned char ucUserOutputs = PORTQS_IN_OUT_DEFINITION;
while (sPort < '8')
{
cType = 'o';
if (!(ucUserOutputs & ucBit))
{
cType = 'i';
}
switch (cType)
{
case 'i': // port to be input
#ifdef _M5223X
DDRQS &= ~(1<<cPortBit); // set port bit to input
#endif
break;
case 'o': // Port to be output
#ifdef _M5223X
DDRQS |= (1<<cPortBit); // set port bit to output
#endif
break;
default:
return -1;
}
sPort++;
ucBit <<= 1;
}
return 0;
}
Thank.
Evgeni.
-
Hi Evgeni
The functions in the demo project are quite special because their interface is suited to control via the web interface. This means that they are possibly not that suitable for general purpose use (although can be used for this).
In your example you could very simply do the following:
DDRQS = PORTQS_IN_OUT_DEFINITION;
I think that your routine has an error - otherwise it probably works (but is possibly rather complicated for the initialisation)
u8 sPort = 0; should be initialised with '0' rather than 0
u8 sPort = '0';
When 0 is used it will execute the loop too many times (although will not actually result in an error).
Regards
Mark