TDimovska

[MPS] Lab5 eng

Jan 14th, 2020
172
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.64 KB | None | 0 0
  1. int state=0;
  2. void main() {
  3.      ANSEL=0;
  4.      ANSELH=0;
  5.      
  6.      TRISA.B3=1;//NIGHT DAY
  7.      TRISA.B4=1;//ON OFF
  8.      TRISC=0;
  9.      PORTC=0;
  10.      EEPROM_WRITE(0x00,0);
  11.      
  12.      while(1){
  13.            if(PORTA.B4){   // on
  14.                state=EEPROM_READ(0x00);
  15.                if(PORTA.B3){  //DAY
  16.                     switch(state){
  17.                         case 0:   //red
  18.                              PORTC=0b10000000;
  19.                              delay_ms(5);
  20.                              break;
  21.                         case 1:    //yellow
  22.                              PORTC=0b01000000;
  23.                              delay_ms(3);
  24.                              break;
  25.                         case 2:     //green
  26.                              PORTC=0b00100000;
  27.                              delay_ms(5);
  28.                              break;
  29.                    }
  30.                }else{   //night
  31.                     switch(state){
  32.                         case 0:   //red
  33.                              PORTC=0b10000000;
  34.                              delay_ms(3);
  35.                              break;
  36.                         case 1:    //yellow
  37.                              PORTC=0b01000000;
  38.                              delay_ms(1);
  39.                              break;
  40.                         case 2:     //green
  41.                              PORTC=0b00100000;
  42.                              delay_ms(3);
  43.                              break;
  44.                    }
  45.                }
  46.                state++;
  47.                if(state>2) state=0;
  48.                EEPROM_WRITE(0x00,state);
  49.            }else {
  50.                PORTC=0;
  51.            }
  52.      }
  53. }
Advertisement
Add Comment
Please, Sign In to add comment