KRITSADA

2 digit 7 Segment Count Down

Dec 13th, 2019
973
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.68 KB | None | 0 0
  1. #include "mcc_generated_files/mcc.h"
  2. #include <xc.h>
  3. #include <stdint.h>
  4. //                    0     1   2     3   4     5    6    7    8    9   A    B    C                  
  5. unsigned char led[]={0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8,0x80,0x90,0x88,0x83,0xC6,0xA1,0x86,0xFF};
  6. unsigned char g=0,x=0,y=0,i,cnt=60;
  7. void disp(unsigned char num)  {
  8.     PORTC=led[num];
  9.     if (num==0 || num==1||num==7){RA2=1;}
  10.     else {RA2=0;}
  11.     return;
  12. }
  13. void main(void) {
  14.     OSCCON = 0x7A; // SCS INTOSC; SPLLEN disabled; IRCF 16MHz_HF;
  15.     OSCTUNE = 0x00;     // TUN 0;
  16.     BORCON = 0x00; // SBOREN disabled; BORFS disabled;
  17.     ANSELA=0x00;
  18.     PORTA=0x00;
  19.     TRISA = 0x01; // Port A is Digital Output RA0 input
  20.     TRISC = 0; // Port C is Digital Output
  21.     PORTC =0;
  22.     RA1=0;
  23.     while(g==0){
  24.         y=cnt/10;
  25.         x=cnt%10;
  26.         for (i=0;i<50;i++){
  27.             RA4=0;
  28.             disp(x);
  29.             __delay_ms(10);
  30.             RA4=1;
  31.             RA5=0;
  32.             disp(y);
  33.             __delay_ms(10);
  34.             RA5=1;
  35.             if (RA0==0){g=1;break;}
  36.         }
  37.     }
  38.     while(cnt>0){
  39.         y=cnt/10;
  40.         x=cnt%10;
  41.         for (i=0;i<20;i++){
  42.             RA4=0;
  43.             disp(x);
  44.             __delay_ms(10);
  45.             RA4=1;
  46.             RA5=0;
  47.             disp(y);
  48.             __delay_ms(10);
  49.             RA5=1;
  50.         }
  51.         cnt--;
  52.     }
  53.     RA1=1;
  54.     while(1){
  55.         for (i=0;i<50;i++){
  56.             RA4=0;
  57.             disp(0);
  58.             __delay_ms(10);
  59.             RA4=1;
  60.             RA5=0;
  61.             disp(0);
  62.             __delay_ms(10);
  63.             RA5=1;
  64.             if (RA0==0){break;}
  65.         }
  66.     }
  67.     return;
  68. }
Advertisement
Add Comment
Please, Sign In to add comment