Question on Ports interfacing using Visual C++ 5.0

I'm trying to interface between motorola 68HC11 and Visual C++ 5.0. Here's some doubts to clear:

1) Can I access ports using _inp and _outp in Visual C++
   5.0? How do they actually work? What if I'm going to
   input a double word from a port? What function should I
   use?
2) If I want to output a byte say $0A to address $7C00 of
   68HC11, how can I do that in Visual C++ 5.0?
3) And how can I write assembly language codes in visual
   C++ 5.0? For your info, I'm using MFC AppWizard (EXE) to
   create a dialog-based program.


Any help offered is very much appreciated!
justinngAsked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
warmcatConnect With a Mentor Commented:
Well, okay, I'll just settle to date your sister.

Under Win32, you need to use CreateFile to get a grip on the COM port.  MFC does not supply wrappers for the Win32 API function.

Here's a chunk of code

{
      HANDLE handle;
      DCB dcb;
      DWORD dwCountVariants=0;

    // ... open the port

      handle=CreateFile("\\\\.\\com1", GENERIC_READ|GENERIC_WRITE, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL , NULL);
      if(handle==NULL) {
            printf("unable to open com1");
            return(0);
      }

         // set up UART states, eg, baud rate

      dcb.DCBlength=sizeof(dcb);
      if(GetCommState(handle, &dcb)==0) {
            printf("Unable to GetCommState\n");
            return(0);
      }
      dcb.BaudRate=1200;
      dcb.fErrorChar=0;
      dcb.ByteSize=8;
      dcb.StopBits=ONESTOPBIT ;
      dcb.Parity=0;
      dcb.fBinary=1;
      dcb.fDtrControl=DTR_CONTROL_ENABLE;
      dcb.fDsrSensitivity=0;
      dcb.fNull =0;
      dcb.fRtsControl=RTS_CONTROL_ENABLE;
      dcb.fAbortOnError =0;
      dcb.DCBlength=sizeof(dcb);

      if(SetCommState(handle, &dcb)==0) {
            printf("Unable to SetCommState\n");
            return(0);
      }

   // ... perform serial operations here

{
            BYTE baBuffer[24];
            DWORD dwCountRead=3;

            if(ReadFile(handle, &baBuffer[0], 20, &dwCountRead, NULL)) {
            } else {
                  printf("Read failed, %08lX", GetLastError());
                  return(0);
            }
    }

    // ... and close the port when done

      CloseHandle(handle);

      return(0);

}

.continued in comment
0
 
warmcatCommented:
Hi Justin -

See below for expansion of these answers.

1) _inp(wAds) reads a BYTE from the IO location wAds.  _outp(wAds, b) writes BYTE b to IO location wAds.

2) Depends on your glue technology

3) Use the inline assembler
0
 
justinngAuthor Commented:
what do you mean by glue technology and how can I use the inline assembler? Please elaborate.
0
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 
justinngAuthor Commented:
what do you mean by glue technology and how can I use the inline assembler? Please elaborate and give examples if possible...thanks!
0
 
warmcatCommented:
1) as far as ''accessing ports'' goes, the software side is the least of your problems.  You first have to decide what kind of interface to use to the PC.  Using a plugin card is generally considered the right choice only when there are pressing speed/bandwidth issues, and the amount of IO coming out of the card to the back of the PC is limited.

There are several choices.  If it must be plugin, then ISA (the old-style 0.1" pitch edge-connector expansion cards) until recently would have been the natural choice.  It's quite easy to interface to, and runs quite slowly (by modern standards), so you do need any funky technology.  Unfortunately Bill has it in for ISA, because there are a lot of old ISA cards out there that are not plug and play, and make folks' life difficult.  So he has decreed that PCs meeting the 'PC99' standard shall Not Have Any ISA Slots.  Aiiieee!

The only alternative is PCI, which as a protocol is fiendishly complex.  However, two companies, AMCC and PLX make 'PCI bridge' chips which hide the muck and present you with a much simpler asynchronous interface that can run at any speed up to 33MHz.  See http://www.amcc.com/Products/PCI/S5920b.htm and http://www.plxtech.com/products/9050/previews/9050_ds/9050.htm for full datasheets on these products.

. continued
0
 
warmcatCommented:
Hey Justin, I am elaborating, man, it just takes time to type all this junk!  This is what I meant by the first line of my answer.
0
 
warmcatCommented:
.continuation

I have myself used the PLX9050 in a PCI card I designed (picture at <a href="http://warmcat.com/mp3-worship.html">http://warmcat.com/mp3-worship.html</a> and it's not that tough.  One tip is you MUST use a 93CS46 EEPROM, not the more common C due to bugs in the PLX silicon.

Better ways to interface revolve around standing off the PC from the actual HC11, for example, via an RS232 serial port or Parallel printer port, or even USB.

The decision of how to interface the two will affect how you operate the interface via _inp() and _outp().

 ...continued
0
 
warmcatCommented:
.continuation
2) This again is a hardware question before it is a software question.  Only when you've decided how to interface the PC to the private memory of the HC11 can you ask the detail of how to drive that interface.  There are two sides to this too:  a) do you memory-map or io-map the PC side of this interface, assuming it is still plugin?  and b) do you use a modal or biphase multiplexing scheme to give both the PC and the HC11 access to the RAM.

a) This one is easy, if it is plugin, for ISA use IO mapping.  You can have one register holding the RAM address you want to access and another holding the data.  Memory mapping on ISA is poisionous because of the limited range of addresses available that are used as 'Dos high memory', even under '95.  Under PCI it doesn't matter which you choose.

b) modal: Either the PC or the HC11 has control of the RAM, the other is locked out until the one with control relinquishes it, biphase: On every clock, for half the time the PC has an opportunity to access the RAM, and the other half of the time the HC11 has control of it.  Your choice.

Either way you will need some 'glue logic' in an FPGA or EPLD to perform the interface and multiplexing logic, and its this that I was referring to.

In fact recently I have done several designs where the entire system logic, including in one case a UART and the sequencing logic to send and receive characters down it, was written in VHDL and stuffed entirely into the EPLD, enabling me to get rid of the processor completely: if your job is simple you might like to consider that, because it's sure as hell easier than what you're planning.

continued
0
 
warmcatCommented:
...continuation:

3) Avoid writing in assembler.  It is not necessary: the quality of the object code produced from your compiler will be more than adequate.  If you must, because Real Men Write In Asssembler, then simply drop this stuff into your C code:

 _asm // everything after the { until the } is assembler
{
    mov eax, ebx ;// use this comment style
    nop    ;// whoa!  I'm a Real Man!
label:
    jnz  label
 }


0
 
warmcatCommented:
My full answer is below
0
 
justinngAuthor Commented:
Hold on.... your solution seem excellent to me but before I surrender the points to you... please help me with my doubts. The technology that you've mentioned is far beyond my scope of study :) However I'm building a Pole-Balancing Robot and I'm using Motorola 68HC11 as the microprocessor for the robot and I'm using a software program to monitor the process of the robot and the program is written in MSVC 5.0 as I mentioned earlier... hehe..

I'm interfacing the 68HC11 through a RS232 serial communication line. When I'm using the Shell program for the 68HC11, I can input and output bytes or words to 68HC11 after linking the assembly file. But I'm now trying to perform the same job using
my own program written in MSVC 5.0. Of course the executable file created by MSVC should enable me to input or output byte to 68HC11.... Do you have any suggestion for me?

Thanks a lot!
0
 
warmcatCommented:
Justin,

You don't have to reject an answer if you have followup questions, you just have to take no action and post a comment.  Reject an answer if you feel it is inadequate or useless.

My first suggestion is that your original question was complete junk for what you were actually asking, and I just spent 30 minutes responding to a request that is going to be of no use at all to you.  Aiiiieeee!

Let me bounce a rephrase of your question off you before I try to answer it this time.  Just tell me if this is what you're really really asking.

''Hi!  I'm Justinng!  I have this serial device connected to a PC via a COM Port!  How can I send and receive bytes down the serial link using Win32/MFC or whatever?  And another thing... you know M68HC11s?  How does the on-chip UART work?  Any suggestions for a command protocol?  Please help me!  I'll give you all my money!  And you can date my sister!  Is it a deal?''

-Andy
0
 
justinngAuthor Commented:
I guess I've missed out some hardware parts which I do not know is crucial to the problem-solver :P forget about the date and money and come back to the question please.... well I'm happy enough if you can answer your questions which I think is also my questions :)

At least you're 100 points richer than before :)
Your help is very much appreciated!
0
 
warmcatCommented:
You cannot directly perform writes into the memory map of the HC11 from the serial port.  Instead you must use a command protocol to describe what function the PC is asking for.

An example might be,( []= is what the PC sends, <> what the HC11 sends )

[00] [12] [34] [55]   request to write 55 into HC11 ads 1234
[01] [12] [34] <55>   request to read HC11 ads 1234 (HC11 returns 55)

and so on.  Or you might choose to give higher-level meanings to the command protocol, such that

[00] [01] [5A]  means turn axis 01 90 degrees

it's up to you.

You do not need to use 80x86 Assembler at any point though... CreateFile() and friends will take care of the interface to the actual COM port.

Regards,

-Andy
0
 
justinngAuthor Commented:
Thanks dude! How abt Garfield for a date?
0
 
justinngAuthor Commented:
Wait a minute, Win32? but I'm using MFC AppWizard (EXE)....
does your still applicable?
0
 
warmcatCommented:
I guess that'd make me desperate for pussy
0
 
warmcatCommented:
If you're using the 32-bit compiler, then MFC is running on top of Win32, so it's all cool.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.