TEXT 10
Bomb timer with avr By Hightechrobo on 20th February 2025 07:19:15 AM
  1. #include <mega32.h>
  2. #include <delay.h>
  3. #include <stdbool.h>
  4.  
  5. #define ddigit_B   DDRB
  6. #define digit_B   PORTB
  7.  
  8. #define ddigit_C   DDRC
  9. #define digit_C   PORTC
  10. const unsigned char digit[10] = {0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};
  11.  
  12.  
  13. void main(void)
  14. {
  15.     char a = 0;
  16.     int ta = 0;
  17.     int ti = 0;
  18.     int timernum = 0;
  19.     int timer = 0;
  20.     bool start = 0 ;
  21.  
  22.    ddigit_B = 0xff;
  23.    ddigit_C = 0xff;
  24.   DDRA = 0xFF ;
  25.  
  26.   DDRD = 0x04;
  27.   PORTD = 0x03;
  28.  
  29. while (1)
  30.       {
  31.  
  32.          if(ta > 50){
  33.          PORTA = a;
  34.          a >>= 1;
  35.          if(a==0)
  36.             a = 0b10000000;
  37.          }
  38.  
  39.  
  40.          if( (PIND & 1) == 0 && start == 0 && ti > 500){
  41.             timernum ++ ;
  42.             ti = 0;
  43.          }
  44.  
  45.          if((PIND & 2) == 0 && start != 1 && ti > 500){
  46.             start = 1;
  47.             ti = 0;
  48.          }
  49.          else if((PIND & 2) == 0 && start && timernum == 0){
  50.             start  = 0;
  51.             PORTD = 0b00000011;
  52.          }
  53.  
  54.          if(start && timernum && timer > 50) {
  55.             timernum --;
  56.             timer = 0;
  57.  
  58.          }
  59.  
  60.          if(timernum == 0 && start){
  61.             PORTD = 0x07;
  62.          }
  63.  
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70.       digit_B = digit[timernum/10];
  71.       digit_C = digit[timernum%10];
  72.  
  73.  
  74.  
  75.  
  76.  
  77.  
  78.          delay_ms(1);
  79.          ta ++ ;
  80.          ti ++;
  81.          timer ++;
  82.       }
  83. }

Hightechrobo bin is for source code and general debugging text.

Login or Register to edit, delete and keep track of your pastes and more.

Raw Paste

Login or Register to edit or fork this paste. It's free.