
BusIn HelloWorld
Fork of BusIn_HelloWorld by
Embed:
(wiki syntax)
Show/hide line numbers
main.cpp
00001 /* mbed Example Program 00002 * Copyright (c) 2006-2014 ARM Limited 00003 * 00004 * Licensed under the Apache License, Version 2.0 (the "License"); 00005 * you may not use this file except in compliance with the License. 00006 * You may obtain a copy of the License at 00007 * 00008 * http://www.apache.org/licenses/LICENSE-2.0 00009 * 00010 * Unless required by applicable law or agreed to in writing, software 00011 * distributed under the License is distributed on an "AS IS" BASIS, 00012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00013 * See the License for the specific language governing permissions and 00014 * limitations under the License. 00015 */ 00016 00017 #include "mbed.h" 00018 00019 BusIn nibble(D0, D1, D2, D3); // Change these pins to buttons on your board. 00020 00021 int main() { 00022 00023 // Optional: set mode as PullUp/PullDown/PullNone/OpenDrain 00024 nibble.mode(PullNone); 00025 00026 while(1) { 00027 // check bits set in nibble 00028 switch(nibble & nibble.mask()) { // read the bus and mask out bits not being used 00029 case 0x0: printf("0b0000, D3,D2,D1,D0 are low \n\r");break; 00030 case 0x1: printf("0b0001, D0 is high \n\r");break; 00031 case 0x2: printf("0b0010, D1 is high \n\r");break; 00032 case 0x3: printf("0b0011, D1,D0 are high \n\r");break; 00033 case 0x4: printf("0b0100, D2 is high \n\r");break; 00034 case 0x5: printf("0b0101, D2, ,D0 are high \n\r");break; 00035 case 0x6: printf("0b0110, D2,D1 are high \n\r");break; 00036 case 0x7: printf("0b0111, D2,D1,D0 are high \n\r");break; 00037 case 0x8: printf("0b1000, D3 is high \n\r");break; 00038 // ... 00039 case 0xF: printf("0b1111, D3,D2,D1,D0 are high \n\r");break; 00040 } 00041 wait(1); 00042 } 00043 }
Generated on Tue Jul 12 2022 16:06:07 by
