Advertisement
Guest User

Untitled

a guest
Dec 7th, 2019
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.47 KB | None | 0 0
  1. //const int len = 16;
  2. //char ch;
  3. //int i absolute 0x111;
  4. //char *text;
  5. void main() {
  6.   // first all analog pins are set to digital
  7.      ANSEL = 0;
  8.      ANSELH = 0;
  9.      TRISC=0x00; // set port C as output port
  10.      PORTC=0x00; // set all pins of port C the value of logical 0 , C7-C5 for our semaphore
  11.      //TRISA=0x00; // set port A as output port
  12.      PORTA=0x00; // set all pins of port A the value of logical 0
  13.      TRISA.B3=1; //set switches to input pins
  14.      //TRISA.B4=1;
  15.      PORTA.B4=1; //semaphore is initially ON
  16.      PORTA.B3=1; //semaphore is initially in day mode
  17.      while(1){ // repeat
  18.        if (PORTA.B4 ==0){  //semaphore is off
  19.           PORTC.B5=0;
  20.           PORTC.B6=0;
  21.           PORTC.B7=0;
  22.           }
  23.        else {       //semaphore is on
  24.           while(PORTA.B3 ==1 && PORTA.B4 == 1) {  // while in day mode and sem. is on
  25.              PORTC.B7=1;
  26.              Delay_ms(20);
  27.              PORTC.B7=0;
  28.              PORTC.B6=1;
  29.              Delay_ms(5);
  30.              PORTC.B6=0;
  31.              PORTC.B5=1;
  32.              Delay_ms(20);
  33.              PORTC.B5=0;
  34.              }
  35.           while(PORTA.B3 ==0 && PORTA.B4 == 1) {  // while in night mode and sem. is on
  36.              PORTC.B7=1;
  37.              Delay_ms(12);
  38.              PORTC.B7=0;
  39.              PORTC.B6=1;
  40.              Delay_ms(3);
  41.              PORTC.B6=0;
  42.              PORTC.B5=1;
  43.              Delay_ms(12);
  44.              PORTC.B5=0;
  45.              }
  46.  
  47.        
  48.        }
  49.  
  50.        }
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement