03-05 SevenSegDisplay
From Manuals
(Difference between revisions)
| Line 1: | Line 1: | ||
A program to demonstrate the BusOut function to display digits on a 7-segment display with a common cathode. It displays digits 0, 1, 2, 3 in turn. | A program to demonstrate the BusOut function to display digits on a 7-segment display with a common cathode. It displays digits 0, 1, 2, 3 in turn. | ||
| + | |||
| + | /*Program Example 3.5: Simple demonstration of 7-segment display. Display digits 0, 1, 2, 3 in turn. | ||
| + | */ | ||
| + | #include "mbed.h" | ||
| + | BusOut display(D0,D1,D2,D3,D4,D5,D6,D7); // segments a,b,c,d,e,f,g,dp | ||
| + | |||
| + | int main() | ||
| + | { | ||
| + | while(1) { | ||
| + | for(int i=0; i<4; i++) { | ||
| + | switch (i) { | ||
| + | case 0: | ||
| + | display = 0x3F; | ||
| + | break; //display 0 | ||
| + | case 1: | ||
| + | display = 0x06; | ||
| + | break; //display 1 | ||
| + | case 2: | ||
| + | display = 0x5B; | ||
| + | break; | ||
| + | case 3: | ||
| + | display = 0x4F; | ||
| + | break; | ||
| + | } //end of switch | ||
| + | wait(0.2); | ||
| + | } //end of for | ||
| + | } //end of while | ||
| + | } | ||
[[Image:BAM210_SevenSegDis.jpeg|center|]] | [[Image:BAM210_SevenSegDis.jpeg|center|]] | ||
Revision as of 14:41, 14 August 2014
A program to demonstrate the BusOut function to display digits on a 7-segment display with a common cathode. It displays digits 0, 1, 2, 3 in turn.
/*Program Example 3.5: Simple demonstration of 7-segment display. Display digits 0, 1, 2, 3 in turn.
*/
#include "mbed.h"
BusOut display(D0,D1,D2,D3,D4,D5,D6,D7); // segments a,b,c,d,e,f,g,dp
int main()
{
while(1) {
for(int i=0; i<4; i++) {
switch (i) {
case 0:
display = 0x3F;
break; //display 0
case 1:
display = 0x06;
break; //display 1
case 2:
display = 0x5B;
break;
case 3:
display = 0x4F;
break;
} //end of switch
wait(0.2);
} //end of for
} //end of while
}


