Por: Omar Gurrola
2/19/13
http://www.proprojects.wordpress.com
PIC18F14K50: Digito 7 Segmentos Con Cambio Rapido Realizar un contador digital similar al ejercicio anterior, con la diferencia que este debe contar de 00 hasta 99 que utilice dos interruptores y dos digito 7 segmentos. Un interruptor incrementara la cuenta y el otro la reseteara. Como este uC no cuenta con suficientes pines de salida tendremos que utilizar una técnica de cambio rápido. Con esta técnica utilizamos 7 pines para los datos y 2 pines más para el control en lugar de requerir 14 pines. El procedimiento de cambio rápido es el siguiente: 1. Poner el dato del primer digito (DIG0). 2. Prender el digito correspondiente (DIG0). 3. Apagar el digito correspondiente (DIG0). 4. Poner el dato del segundo digito (DIG1). 5. Prender el digito correspondiente (DIG1). 6. Apagar el digito correspondiente (DIG1). 7. Y así sucesivamente. Se debe utilizar un transistor para prender y apagar el segmento correspondiente. main.c /* * * * * * * * * * * * * * * * * * * * * * */
Copyright (c) 2011-2013, http://www.proprojects.wordpress.com All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1.- Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2.- Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
/********************************************************************************** * Author: Omar Gurrola * Site: http://www.proprojects.wordpress.com * Processor: PIC18 * Compiler: C18 v3.45 * File Name: main.c * Description: Main program * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ * Rev. Date Comment * 1.0 02/19/13 Initial version *********************************************************************************/ /** INCLUDES *******************************************************/ #include <p18f14k50.h> #include "pic18f14k50_cbits.h" #include "pic18f14k50_io.h" #include "stdvars.h" #include "wait.h" #include "7seg.h" /** PROTOTYPES *****************************************************/ /** VARIABLES ******************************************************/
Por: Omar Gurrola
2/19/13
http://www.proprojects.wordpress.com
/** DECLARATIONS ***************************************************/ #pragma code // Forces the code below this line to be put into the code section (Memory Adress >= 0x'REMDIR'02A) /** Interrupt Service Routines (ISR)********************************/ #pragma interrupt HighPriorityISR void HighPriorityISR (void){ //Check which interrupt flag caused the interrupt. //Service the interrupt //Clear the interrupt flag //Etc. } //This return will be a "retfie fast", since this is in a #pragma interrupt section #pragma interruptlow LowPriorityISR void LowPriorityISR (void){ //Check which interrupt flag caused the interrupt. //Service the interrupt //Clear the interrupt flag //Etc. }
//This return will be a "retfie", since this is in a #pragma interruptlow section
void main(void){ // Variables y Constantes u8 Counter = 0; u8 U, D, t; bool ButtonPressed = false; // Start-up configuration OSCCONbits.IRCF = 0b110; OSCTUNEbits.SPLLEN = 1;
// Poscaler selected to 8 MHz // PLLx4 Enable System FQ = 32 MHz
// Ports OpenInRA4(); OpenInRA5(); OpenOutRB4(); OpenOutRB5(); OpenOutPC();
// // // // //
// Profile #define SEG1ON() #define SEG2ON()
WriteRB4(1); WriteRB5(0) WriteRB4(0); WriteRB5(1)
Counter Reset SEG1 SEG2 Display 7 Seg CA
while(TRUE){ U = Counter / 10; D = Counter - (U * 10); if(ButtonPressed){ t = 101; ButtonPressed = false; } else { t = 1; } for(t; t > 0; t--){ SEG1ON(); WritePC(Cod7seg(U,COM_ANODE)); Waitmsx(1); SEG2ON(); WritePC(Cod7seg(D,COM_ANODE)); Waitmsx(1); } if(ReadRA4()){ Counter++; if(Counter > 99){ Counter=0; } ButtonPressed = true; } else if(ReadRA5()){ Counter=0; ButtonPressed = true; } }; } // end main()
Por: Omar Gurrola Diagrama esquemático:
2/19/13
Circuito armado:
Referencias
Microchip, “PIC18F/LF1XK50 Data Sheet”, 2010, http://ww1.microchip.com/downloads/en/DeviceDoc/41350E.pdf
http://www.proprojects.wordpress.com