PIC18F14K50: Display 7 Segmentos

Page 1

Por: Omar Gurrola

2/18/13

http://www.proprojects.wordpress.com

PIC18F14K50: Display 7 Segmentos El problema consiste en realizar un contador digital (0-9) que utilice dos interruptores y un digito 7 segmentos. Un interruptor incrementara la cuenta y el otro la reseteara.

Byte: Segment: 0 1 2 3 4 5 6 7 8 9 A B C D E F >F

b7 x 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0

b6 g 0 0 1 1 1 1 1 0 1 1 1 1 0 1 1 1 0

b5 f 1 0 0 0 1 1 1 0 1 1 1 1 1 0 1 1 0

b4 e 1 0 1 0 0 0 1 0 1 0 1 1 1 1 1 1 0

b3 d 1 0 1 1 0 1 1 0 1 0 0 1 1 1 1 0 0

b2 c 1 1 0 1 1 1 1 1 1 1 1 1 0 1 0 0 0

b1 b 1 1 1 1 1 0 0 1 1 1 1 0 0 1 0 0 0

b0 a 1 0 1 1 0 1 1 1 1 1 1 0 1 0 1 1 0

Cod-CC HEX 3F 06 5B 4F 66 6D 7D 07 7F 67 77 7C 39 5E 79 71 00

Cod-CA HEX F9 F9 A4 B0 99 92 82 F8 80 99 88 83 C6 A1 86 8D FF

Realizar este contador es muy sencillo, para codificar un byte a 7 segmentos utilizaremos un arreglo que se encuentre en ROM con los siguientes datos: static rom const u8 COD7SEG_CC[] = {0x3F,0x06,0x5B,0x4F,0x66,0x6D,0x7D,0x07,0x7F,0x67,0x77,0x7C,0x39,0x5E,0x79,0x71,0x00};

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


Por: Omar Gurrola * */

2/18/13

http://www.proprojects.wordpress.com

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/18/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 ******************************************************/ /** 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; // Start-up configuration OSCCONbits.IRCF = 0b110; OSCTUNEbits.SPLLEN = 1; // Ports OpenInRA4(); OpenInRA5(); OpenOutPC();

// Poscaler selected to 8 MHz // PLLx4 Enable System FQ = 32 MHz

// Counter // Reset // Display 7 Seg CA

while(TRUE){ WritePC(Cod7seg(Counter,COM_ANODE)); while(!ReadRA4() && !ReadRA5()); Waitmsx(50); if(ReadRA4()){ Counter++; if(Counter > 9){ Counter=0; } } else if(ReadRA5()){ Counter=0; } Waitmsx(250); }; } // end main()

// Decodificamos el byte a 7seg CA // Espera a presionar un boton. // Espera a que se estabilice el rebote. // Incrementa cuenta // Si cuenta supera los 9 // Resetea cuenta

// Resetea cuenta


Por: Omar Gurrola Diagrama esquemático:

2/18/13

Circuito armado:

Referencias 

Microchip, “PIC18F/LF1XK50 Data Sheet”, 2010, http://ww1.microchip.com/downloads/en/DeviceDoc/41350E.pdf

http://www.proprojects.wordpress.com


Turn static files into dynamic content formats.

Create a flipbook
Issuu converts static files into: digital portfolios, online yearbooks, online catalogs, digital photo albums and more. Sign up and create your flipbook.