Hi Greg, I use the code below and think a modified version of this should work for you.
Whatever settings you make on the _RD, _WR pin in _init() should be retained. Use member functions to access the protected (pins) _RD or _WR.
(Sorry about the ugly layout, no idea why i get this when pasting code...)
BusEnums.h:
-----
/* BusEnums - Use the MBED Port pins for controlling the Bus
- ifndef _BUS_ENUMS_H
- define _BUS_ENUMS_H
Enums for Control Bus and Enable Bus
enum Bit_Level { LOW, HIGH };
- endif
MBED_ControlBus.h:
-------
- ifndef _MBED_CONTROLBUS_H
- define _MBED_CONTROLBUS_H
Enums for Control Bus
- include "BusEnums.h"
/ Create an MBED_ControlBus object connected to the specified Pins
-
- @param PinName WR the Write pin
- @param PinName RD the Read pin
- /
class MBED_ControlBus {
public:
MBED_ControlBus(PinName WR, PinName RD);
void WR (Bit_Level wr_level);
void RD (Bit_Level rd_level);
protected:
DigitalOut _WR; Write pin
DigitalOut _RD; Read pin
void _init();
};
- endif
MBED_ControlBus.cpp:
-------
/* MBED_ControlBus - Use MBED Port Pins for controlling the external Bus
- include "mbed.h"
- include "MBED_ControlBus.h"
/ Create an MBED_ControlBus object connected to the specified Pins
-
- @param PinName WR the Write pin
- @param PinName RD the Read pin
- /
MBED_ControlBus::MBED_ControlBus(PinName WR, PinName RD) :
_WR(WR), WR pin
_RD(RD) { RD pin
_init();
}
/ Set or Clear the WR pin on Control Bus
-
- @param Bit_Level wr_level
- /
void MBED_ControlBus::WR (Bit_Level wr_level) {
if (wr_level == LOW) {
_RD = 1; RD Pin High, make sure there is no collision
_WR = 0; WR Pin Low
}
else {
_WR = 1; WR Pin High
}
}
/ Set or Clear the RD pin on Control Bus
-
- @param Bit_Level rd_level
- /
void MBED_ControlBus::RD (Bit_Level rd_level) {
if (rd_level == LOW) {
_WR = 1; WR Pin High, make sure there is no collision
_RD = 0; RD Pin Low
}
else {
_RD = 1; RD Pin High
}
}
/ Init MBED_ControlBus
void MBED_ControlBus::_init() {
Make sure that all Control pins are disabled
_RD = 1; RD Pin High
_WR = 1; WR Pin High
}
main.cpp:
-------
- include "MBED_ControlBus.h"
MBED_ControlBus controlbus = MBED_ControlBus(p23, p24);
int main() {
controlbus.RD(LOW);
wait(1);
controlbus.RD(HIGH);
}
I was trying to put all the pin declaration in one header file, so the source files just need to include it. However, it turns out if I include more than once of that header file, the compiler is complaining that I declare the pin more than once. Some thing like "Multiple pin declaration found in ??.cpp and ???.cpp". Then I try divided the pin declaration to specific source files, it works. But that would mean I can use only that certain pin in that certain source file, since header file method doesn't work, and I can declare it twice( compiler wouldn't let me). It is quite painful, when come to bebugging using USBTX and USBRX to print, and a lot other inconvinence. I hope you guys can make the header file method work, since I am really just declaring it once, and include it in other files...
Mahalo
Let me know how it goes ;)