0% found this document useful (0 votes)
25 views

Programas Digitales 2 1

The document contains 9 C++ programs that demonstrate using digital inputs, outputs, interrupts and timers with an Mbed microcontroller. Program 1 blinks LEDs in a sequence. Programs 2-3 toggle an LED based on a button press. Program 4 displays 7-segment digits. Programs 5-6 increment a displayed number with a button. Program 7 uses a timer to increment display. Program 8 uses timers for display and an LED. Program 9 uses an interrupt for button input.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
25 views

Programas Digitales 2 1

The document contains 9 C++ programs that demonstrate using digital inputs, outputs, interrupts and timers with an Mbed microcontroller. Program 1 blinks LEDs in a sequence. Programs 2-3 toggle an LED based on a button press. Program 4 displays 7-segment digits. Programs 5-6 increment a displayed number with a button. Program 7 uses a timer to increment display. Program 8 uses timers for display and an LED. Program 9 uses an interrupt for button input.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 15

Programas digitales 2

#include "mbed.h"

BusOut led(A0, A1, A2, A3, A4);

int vec[10]={0,1,3,7,15,31,15,7,3,1};

int main()

while (true)

for(int h = 0; h < 10; h++)

led=vec[h];

wait(1);

Programa 2

#include "mbed.h"

DigitalOut led(A0);

DigitalIn boton(A1);
int main(void)

while (1) {

if(boton==1)

led=1;

else

led=0;

Programa 3

#include "mbed.h"

DigitalOut led(A0);

DigitalIn boton(A1);

int main(void)

led=0;

while (1) {

if(boton==1)
{

wait(0.1);

while(boton==1)

led=!led;

Programa 4

#include "mbed.h"

BusOut display(PA_8,PB_10,PB_4,PB_5,PB_3,PA_10,PA_2);

int main() {

while(1) {

display=0b1111110;

wait(1);

display=0b0110000;

wait(1);

display=0b1101101;//

wait(1);

display=0b1111001;

wait(1);

display=0b0110011;
wait(1);

display=0b1011011;//

wait(1);

display=0b1011111;

wait(1);

display=0b1110000;

wait(1);

display=0b1111111;

wait(1);

display=0b1110011;

wait(1);

Programa 5

#include "mbed.h"

BusOut display(PTC8, PTA5, PTA4, PTA12, PTD4, PTA2, PTA1);

char SegConvert(char SegValue); // function prototype

int main()

{ // main program

while (1) { // infinite loop

for (char i=0;i<10;i++)

display=SegConvert(i);

wait(1);
}

char SegConvert(char SegValue)

{ // function 'SegConvert'

char SegByte=0x00;

switch (SegValue) { //DPGFEDCBA

case 0 : SegByte = 0x7e;

break; // 00111111 binary

case 1 : SegByte = 0x30;

break; // 00000110 binary

case 2 : SegByte = 0x6d;

break; // 01011011 binary

case 3 : SegByte = 0x79;

break; // 01001111 binary

case 4 : SegByte = 0x33;

break; // 01100110 binary

case 5 : SegByte = 0x5b;

break; // 01101101 binary

case 6 : SegByte = 0x5f;

break; // 01111101 binary

case 7 : SegByte = 0x70;

break; // 00000111 binary

case 8 : SegByte = 0x7f;

break; // 01111111 binary

case 9 : SegByte = 0x73;

break; // 01101111 binary


}

return SegByte;

Programa 6

#include "mbed.h"

BusOut display(PA_8, PB_10, PB_4, PB_5, PB_3, PA_10, PB_8);

DigitalIn boton(PB_9);

char SegConvert(char SegValue); // function prototype

int a=0;

int main()

{ // main program

while (1) { // infinite loop

if(boton==1)

while(boton==1)

{}

a++;

if(a==10)

{a=0;}

wait(0.2);

display=SegConvert(a);
}

char SegConvert(char SegValue)

{ // function 'SegConvert'

char SegByte=0x00;

switch (SegValue) { //DPGFEDCBA

case 0 : SegByte = 0x7e;

break; // 00111111 binary

case 1 : SegByte = 0x30;

break; // 00000110 binary

case 2 : SegByte = 0x6d;

break; // 01011011 binary

case 3 : SegByte = 0x79;

break; // 01001111 binary

case 4 : SegByte = 0x33;

break; // 01100110 binary

case 5 : SegByte = 0x5b;

break; // 01101101 binary

case 6 : SegByte = 0x5f;

break; // 01111101 binary

case 7 : SegByte = 0x70;

break; // 00000111 binary

case 8 : SegByte = 0x7f;

break; // 01111111 binary

case 9 : SegByte = 0x73;

break; // 01101111 binary


}

return SegByte;

Program 7

#include "mbed.h"

BusOut display(PA_8, PB_10, PB_4, PB_5, PB_3, PA_10, PB_8);

DigitalIn boton(PB_9);

Ticker conteo;

char SegConvert(char SegValue); // function prototype

int a=0;

void cuenta()

a++; //niega el pin

if(a==10)

{a=0;}

int main()

{ // main program

conteo.attach(&cuenta,20);
while (1) { // infinite loop

display=SegConvert(a);

char SegConvert(char SegValue)

{ // function 'SegConvert'

char SegByte=0x00;

switch (SegValue) { //DPGFEDCBA

case 0 : SegByte = 0x7e;

break; // 00111111 binary

case 1 : SegByte = 0x30;

break; // 00000110 binary

case 2 : SegByte = 0x6d;

break; // 01011011 binary

case 3 : SegByte = 0x79;

break; // 01001111 binary

case 4 : SegByte = 0x33;

break; // 01100110 binary

case 5 : SegByte = 0x5b;

break; // 01101101 binary

case 6 : SegByte = 0x5f;

break; // 01111101 binary

case 7 : SegByte = 0x70;


break; // 00000111 binary

case 8 : SegByte = 0x7f;

break; // 01111111 binary

case 9 : SegByte = 0x73;

break; // 01101111 binary

return SegByte;

Programa 8

#include "mbed.h"

BusOut display(PA_8, PB_10, PB_4, PB_5, PB_3, PA_10, PB_8);

DigitalIn boton(PB_9);

DigitalOut luz(LED1);

Ticker conteo;

Ticker led;

char SegConvert(char SegValue); // function prototype

int a=0;

void cuenta()

a++; //niega el pin

if(a==10)

{a=0;}

}
void prender()

luz=!luz;

int main()

{ // main program

conteo.attach(&cuenta,5);

led.attach(&prender,1);

while (1) { // infinite loop

display=SegConvert(a);

char SegConvert(char SegValue)

{ // function 'SegConvert'

char SegByte=0x00;

switch (SegValue) { //DPGFEDCBA

case 0 : SegByte = 0x7e;

break; // 00111111 binary

case 1 : SegByte = 0x30;


break; // 00000110 binary

case 2 : SegByte = 0x6d;

break; // 01011011 binary

case 3 : SegByte = 0x79;

break; // 01001111 binary

case 4 : SegByte = 0x33;

break; // 01100110 binary

case 5 : SegByte = 0x5b;

break; // 01101101 binary

case 6 : SegByte = 0x5f;

break; // 01111101 binary

case 7 : SegByte = 0x70;

break; // 00000111 binary

case 8 : SegByte = 0x7f;

break; // 01111111 binary

case 9 : SegByte = 0x73;

break; // 01101111 binary

return SegByte;

Programa 9

#include "mbed.h"

BusOut display(PA_8, PB_10, PB_4, PB_5, PB_3, PA_10, PB_8);

InterruptIn boton(PA_6);

char SegConvert(char SegValue); // function prototype


int a=0;

void IRS_PA_6()

a++; //niega el pin

if(a==10)

{a=0;}

int main()

{ // main program

boton.mode(PullUp); // pone el pin pullup osea 5 voltios

boton.rise(&IRS_PA_6); // funciona interupcion falco de bajada

while (1) { // infinite loop

display=SegConvert(a);

char SegConvert(char SegValue)


{ // function 'SegConvert'

char SegByte=0x00;

switch (SegValue) { //DPGFEDCBA

case 0 : SegByte = 0x7e;

break; // 00111111 binary

case 1 : SegByte = 0x30;

break; // 00000110 binary

case 2 : SegByte = 0x6d;

break; // 01011011 binary

case 3 : SegByte = 0x79;

break; // 01001111 binary

case 4 : SegByte = 0x33;

break; // 01100110 binary

case 5 : SegByte = 0x5b;

break; // 01101101 binary

case 6 : SegByte = 0x5f;

break; // 01111101 binary

case 7 : SegByte = 0x70;

break; // 00000111 binary

case 8 : SegByte = 0x7f;

break; // 01111111 binary

case 9 : SegByte = 0x73;

break; // 01101111 binary

return SegByte;

You might also like