//
// pict14c.c // // Implementation of the PICT14.ASM program in Easy Pic 'N // lookup demo using a 7 segment display. // It adds monitoring of the PortA switches to change the // 7 segment display. // There are probably a billion ways to do this one, but storing the // table in ROM by using a constant is very efficient in .asm code. // You might want to try doing this with a case statement and then // with the lookup table (below). Big difference in amount of hex // code that is generated! // // Using '84 on a board (simple solderless breadboard with // 16F84 on it) and Peter Anderson's include file with // port/bit definitions (defs_f84.h available at www.phanderson.com) // Settings: // 4Mhz resonator (not important) // All Port A inputs use external pullups (resistor SIP used) // Port B outputs tied to a 7 segment display (Radio Shack has 'em) // Port A inputs tied to ground through four switches // (pullups still are on them - makes it all work!) // Flip switch and the correct number should appear on the 7 segment // Note that you can only flip switches up to binary 1010 (10 decimal) #case #include <16f84.h> #include// defines registers and bits #fuses xt,nowdt,put,noprotect int const table[10]= {0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f}; void main(void) { TRISA=0x1f; // make porta all inputs TRISB=0x00; // make portb all outputs PORTB=0; // clear portB while(1) { PORTB=table[PORTA]; // set PORTB with a table value based on // switch value in PORTA } }