Advertisement
Guest User

Untitled

a guest
Dec 3rd, 2016
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.76 KB | None | 0 0
  1. int state;
  2. void main()
  3. {
  4.     // set the analog pins to be digital
  5.      ansel = 0;
  6.      anselh = 0 ;
  7.  
  8.      trisc = 0x00;     // set port C to be output port;
  9.      trisa.b3 = 1;     // set the 3rd bit of port A to be an input bit for on/off
  10.      trisa.b4 = 1;     // set the 4th bit of port A to be an input bit for day/night mode
  11.      trisa.b5 = 1;     // set the 5th bit of port A to be an input bit for blink mode
  12.  
  13.      porta.b3 = 1;     // the traffic light is on
  14.      porta.b4 = 1;     // the day mode is on
  15.      porta.b5 = 1;     // the blink mode is on
  16.  
  17.      eeprom_write(0x60, 0x20);
  18.      state = eeprom_read(0x60);
  19.  
  20.      while(1)
  21.      {
  22.         if(porta.b3 == 0)
  23.         {
  24.            portc = 0x00;     // set port C to logic 0
  25.         }
  26.         else if(porta.b4 == 1)  // day mode
  27.         {
  28.            if(porta.b5 == 1)    // blink mode
  29.            {
  30.               portc = 0x20;
  31.               eeprom_write(0x60, 0x20);
  32.               delay_ms(18);
  33.               portc = 0x00;
  34.               delay_ms(1);
  35.               portc = 0x20;
  36.               delay_ms(1);
  37.              
  38.               portc = 0x40;
  39.               eeprom_write(0x60, 0x40);
  40.               delay_ms(5);
  41.  
  42.               portc = 0x80;
  43.               eeprom_write(0x60, 0x80);
  44.               delay_ms(18);
  45.               portc = 0x00;
  46.               delay_ms(1);
  47.               portc = 0x80;
  48.               delay_ms(1);
  49.            }
  50.            else
  51.            {
  52.               portc = 0x20;
  53.               eeprom_write(0x60, 0x20);
  54.               delay_ms(20);
  55.  
  56.               portc = 0x40;
  57.               eeprom_write(0x60, 0x40);
  58.               delay_ms(5);
  59.  
  60.               portc = 0x80;
  61.               eeprom_write(0x60, 0x80);
  62.               delay_ms(20);
  63.            }
  64.         }
  65.         else if(porta.b4 == 0)      // night mode
  66.         {
  67.            if(porta.b5 == 1)    // blink mode
  68.            {
  69.               portc = 0x20;
  70.               eeprom_write(0x60, 0x20);
  71.               delay_ms(10);
  72.               portc = 0x00;
  73.               delay_ms(1);
  74.               portc = 0x20;
  75.               delay_ms(1);
  76.  
  77.               portc = 0x40;
  78.               eeprom_write(0x60, 0x40);
  79.               delay_ms(3);
  80.  
  81.               portc = 0x80;
  82.               eeprom_write(0x60, 0x80);
  83.               delay_ms(10);
  84.               portc = 0x00;
  85.               delay_ms(1);
  86.               portc = 0x80;
  87.               delay_ms(1);
  88.            }
  89.            else
  90.            {
  91.               portc = 0x20;
  92.               eeprom_write(0x60, 0x20);
  93.               delay_ms(12);
  94.  
  95.               portc = 0x40;
  96.               eeprom_write(0x60, 0x40);
  97.               delay_ms(3);
  98.  
  99.               portc = 0x80;
  100.               eeprom_write(0x60, 0x80);
  101.               delay_ms(12);
  102.            }
  103.         }
  104.      }
  105. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement