Gerardo Carmona
/
info_04_sumador2datos2bits
main.cpp@0:1d6044b1911c, 2014-05-09 (annotated)
- Committer:
- gcarmonar
- Date:
- Fri May 09 15:30:17 2014 +0000
- Revision:
- 0:1d6044b1911c
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
gcarmonar | 0:1d6044b1911c | 1 | #include "mbed.h" |
gcarmonar | 0:1d6044b1911c | 2 | |
gcarmonar | 0:1d6044b1911c | 3 | DigitalIn A(D2); |
gcarmonar | 0:1d6044b1911c | 4 | DigitalIn B(D3); |
gcarmonar | 0:1d6044b1911c | 5 | DigitalIn C(D4); |
gcarmonar | 0:1d6044b1911c | 6 | DigitalIn D(D5); |
gcarmonar | 0:1d6044b1911c | 7 | |
gcarmonar | 0:1d6044b1911c | 8 | BusOut bout(D13, D12, D11, D10); |
gcarmonar | 0:1d6044b1911c | 9 | |
gcarmonar | 0:1d6044b1911c | 10 | int sumador(int a, int b, int ci){ |
gcarmonar | 0:1d6044b1911c | 11 | int x,s,co; |
gcarmonar | 0:1d6044b1911c | 12 | x = a&!b | !a&b; |
gcarmonar | 0:1d6044b1911c | 13 | s = x&!ci | !x&ci; |
gcarmonar | 0:1d6044b1911c | 14 | co = x&ci | a&b; |
gcarmonar | 0:1d6044b1911c | 15 | return s | (co << 1); |
gcarmonar | 0:1d6044b1911c | 16 | } |
gcarmonar | 0:1d6044b1911c | 17 | |
gcarmonar | 0:1d6044b1911c | 18 | int main() { |
gcarmonar | 0:1d6044b1911c | 19 | while(1) { |
gcarmonar | 0:1d6044b1911c | 20 | int c = 0; |
gcarmonar | 0:1d6044b1911c | 21 | bout = sumador (A,B,c); |
gcarmonar | 0:1d6044b1911c | 22 | bout = bout & 0x01 | (sumador(C,D,bout>>1) << 1); |
gcarmonar | 0:1d6044b1911c | 23 | wait(.1); |
gcarmonar | 0:1d6044b1911c | 24 | } |
gcarmonar | 0:1d6044b1911c | 25 | } |