Saltar al contenido principal
LibreTexts Español

11.2: Asignación

  • Page ID
    83192
  • \( \newcommand{\vecs}[1]{\overset { \scriptstyle \rightharpoonup} {\mathbf{#1}} } \) \( \newcommand{\vecd}[1]{\overset{-\!-\!\rightharpoonup}{\vphantom{a}\smash {#1}}} \)\(\newcommand{\id}{\mathrm{id}}\) \( \newcommand{\Span}{\mathrm{span}}\) \( \newcommand{\kernel}{\mathrm{null}\,}\) \( \newcommand{\range}{\mathrm{range}\,}\) \( \newcommand{\RealPart}{\mathrm{Re}}\) \( \newcommand{\ImaginaryPart}{\mathrm{Im}}\) \( \newcommand{\Argument}{\mathrm{Arg}}\) \( \newcommand{\norm}[1]{\| #1 \|}\) \( \newcommand{\inner}[2]{\langle #1, #2 \rangle}\) \( \newcommand{\Span}{\mathrm{span}}\) \(\newcommand{\id}{\mathrm{id}}\) \( \newcommand{\Span}{\mathrm{span}}\) \( \newcommand{\kernel}{\mathrm{null}\,}\) \( \newcommand{\range}{\mathrm{range}\,}\) \( \newcommand{\RealPart}{\mathrm{Re}}\) \( \newcommand{\ImaginaryPart}{\mathrm{Im}}\) \( \newcommand{\Argument}{\mathrm{Arg}}\) \( \newcommand{\norm}[1]{\| #1 \|}\) \( \newcommand{\inner}[2]{\langle #1, #2 \rangle}\) \( \newcommand{\Span}{\mathrm{span}}\)\(\newcommand{\AA}{\unicode[.8,0]{x212B}}\)

    Este ejercicio implica una cantidad considerable de cableado y una cantidad no trivial de código. Hay muchas cosas que pueden salir mal si solo te sumerjas y tratas de hacer todo a la vez. Por ejemplo, si un segmento o un dígito completo no se enciende, ¿cómo saber si el problema está en el hardware o en el software? Depurar ambos simultáneamente no es una tarea menor. Es mejor asegurarse de que los trozos del código funcionen como se esperaba primero, luego construir sobre eso. Por ejemplo, es posible que simplemente codifique el pedazo que enciende una pantalla y luego expanda a una pantalla multiplexada. Considera algo como esto:

    // Port B.0:2 for 7 segment mux
    #define DIGIT1   0x01
    #define DIGIT10  0x02
    #define DIGIT100 0x04
    #define DIGIT111 0x07
    
    #define FSRMASK  0x08
    
    unsigned char numeral[]={
       //ABCDEFG,dp
       0b00000011,   // 0
       0b10011111,   // 1 
       0b00100101,   // 2
       0b00001101,   // 3
       0b10011001,
       0b01001001,
       0b01000001,
       0b00011111,
       0b00000001,
       0b00011001,   // 9
       0b11111111,   // blank
       0b01100001,   // E
       0b01110011,   // r
       0b00001001,   // g
       0b00111001    // o  
    };
    
    #define LETTER_BLANK  10
    #define LETTER_E      11
    #define LETTER_R      12
    #define LETTER_G      13
    #define LETTER_O      14
    #define MSG_ERR       -2
    
    void loop()
    {
       // try a bunch of different things...
       DisplayValue(123);
       DisplayValue(456);
       DisplayValue(12);
       DisplayValue(3);
       DisplayValue(100);
       DisplayValue(-2);
       DisplayValue(50);
    }
    
    void DisplayValue( int v )
    {
       unsigned char i, h, t, u; // hundreds, tens, units
    
       if( (v <= MSG_ERR) || (v > 999) ) // error code
       {
          h = LETTER_E;
          t = u = LETTER_R;
       }
       else
       {
          u = v%10;
          v = v/10;
          t = v%10;
          h = v/10;
       }
    
       // display the value for approx 1 sec (66x15msec)
       for( i=0; i<66; i++ )
       {
          // clear all displays then activate the desired digit
          PORTB |= DIGIT111;
          PORTD = numeral[h];
          PORTB &= ~DIGIT100;
          delay(5);
    
          PORTB |= DIGIT111;
          PORTD = numeral[t];
          PORTB &= ~DIGIT10;
          delay(5);
    
          PORTB |= DIGIT111;
          PORTD = numeral[u];
          PORTB &= ~DIGIT1;
          delay(5);   
       }
      
       // clear display
       PORTB |= DIGIT111;
    }
    

    Una vez que tengas el circuito funcionando, ¡pruébalo de verdad! Dé vuelta a su código y un esquema completo. También, comente qué alteraciones de código y hardware serían necesarias (si las hubiera) si se usaran pantallas de cátodo comunes en lugar de ánodo común.


    This page titled 11.2: Asignación is shared under a CC BY-NC-SA 4.0 license and was authored, remixed, and/or curated by James M. Fiore via source content that was edited to the style and standards of the LibreTexts platform; a detailed edit history is available upon request.