Advertisement
xerpi

PIC 7-SEG DISP

Oct 1st, 2014
295
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.62 KB | None | 0 0
  1. #include <xc.h>
  2. #include "config.h"
  3.  
  4. static const unsigned char nums[] = {
  5.     0b00111111,
  6.     0b00110000,
  7.     0b01101101,
  8.     0b01111001,
  9.     0b01110010,
  10.     0b01011011,
  11.     0b01011111,
  12.     0b00110001,
  13.     0b01111111,
  14.     0b01110011,
  15.     0b00000000,
  16. };
  17.  
  18. void main()
  19. {
  20.          ADCON1 |= 0x0F;                         // Configure all ports with analog function as digital
  21.         CMCON  |= 7;                            // Disable comparators
  22.  
  23.     TRISA=0xFF;
  24.     TRISB=0;
  25.     int old = PORTA;
  26.     int i = 0;
  27.  
  28.     for(;;){
  29.         int n = PORTA;
  30.  
  31.         if ((n == 1) && !(old == 1)) {
  32.             i++;
  33.             if (i > 10) i = 0;
  34.             PORTB=nums[i];
  35.         }
  36.         old = n;
  37.     }
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement