daily pastebin goal
27%
SHARE
TWEET

Untitled

a guest Oct 12th, 2018 58 Never
Upgrade to PRO!
ENDING IN00days00hours00mins00secs
 
  1. #pragma SMALL
  2. #include<reg52.h>
  3. int segment[10] = {0x3F, 0x06, 0x5B, 0x4F, 0x66, 0x6D, 0x7D, 0x07, 0x7F, 0x6F};
  4. int runningNum = 0;
  5. bit isRight = 1;
  6. int count=0;
  7. sbit Switch_pin = P3^0;
  8.  
  9. bit old = 0;
  10. bit new = 0;
  11.  
  12. void delay(int ms) {
  13.     int i, j;
  14.     for(i=0;i<10;i++) {
  15.         for(j=0;j<ms;j++) {
  16.         }
  17.     }
  18. }
  19.  
  20. void runningSEG(bit isRight){
  21.     if (runningNum == 100) {
  22.         runningNum = 0;
  23.     }
  24.     if (isRight)
  25.     {
  26.         P0 = segment[runningNum / 10];
  27.     } else {
  28.         P0 = segment[runningNum % 10];
  29.  
  30.     }
  31. }
  32.  
  33.  
  34.  
  35. void main(void) {
  36.     P0 = 0x00;
  37.     P2 = 0x02;
  38.     while(1) {
  39.         //Push Btn = Switch_pin = 0
  40.     /* Use Push Btn as Toggle Switch */
  41.         new = !Switch_pin;
  42.         if(new != old && new) {
  43.       //If push btn, increase number by 1
  44.             runningNum++;
  45.         }
  46.         old = new;
  47.    
  48.     /* Display number on two 7-Segment */
  49.         runningSEG(isRight);
  50.         if(isRight) {
  51.             P2 = 0x01;
  52.         } else {
  53.             P2 = 0x02;
  54.         }
  55.         isRight = !isRight;
  56.         delay(100);
  57.     }
  58. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top