We help IT Professionals succeed at work.

Check out our new AWS podcast with Certified Expert, Phil Phillips! Listen to "How to Execute a Seamless AWS Migration" on EE or on your favorite podcast platform. Listen Now


Question on Ports interfacing using Visual C++ 5.0

justinng asked
Medium Priority
Last Modified: 2013-12-14
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
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!
Watch Question

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


what do you mean by glue technology and how can I use the inline assembler? Please elaborate.


what do you mean by glue technology and how can I use the inline assembler? Please elaborate and give examples if possible...thanks!

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

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.


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().


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.



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!
    jnz  label

My full answer is below


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!


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?''



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!
Unlock this solution with a free trial preview.
(No credit card required)
Get Preview

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.




Thanks dude! How abt Garfield for a date?


Wait a minute, Win32? but I'm using MFC AppWizard (EXE)....
does your still applicable?

I guess that'd make me desperate for pussy

If you're using the 32-bit compiler, then MFC is running on top of Win32, so it's all cool.
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a free trial preview!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.


Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.