Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int state;
- void main()
- {
- // set the analog pins to be digital
- ansel = 0;
- anselh = 0 ;
- trisc = 0x00; // set port C to be output port;
- trisa.b3 = 1; // set the 3rd bit of port A to be an input bit for on/off
- trisa.b4 = 1; // set the 4th bit of port A to be an input bit for day/night mode
- trisa.b5 = 1; // set the 5th bit of port A to be an input bit for blink mode
- porta.b3 = 1; // the traffic light is on
- porta.b4 = 1; // the day mode is on
- porta.b5 = 1; // the blink mode is on
- eeprom_write(0x60, 0x20);
- state = eeprom_read(0x60);
- while(1)
- {
- if(porta.b3 == 0)
- {
- portc = 0x00; // set port C to logic 0
- }
- else if(porta.b4 == 1) // day mode
- {
- if(porta.b5 == 1) // blink mode
- {
- portc = 0x20;
- eeprom_write(0x60, 0x20);
- delay_ms(18);
- portc = 0x00;
- delay_ms(1);
- portc = 0x20;
- delay_ms(1);
- portc = 0x40;
- eeprom_write(0x60, 0x40);
- delay_ms(5);
- portc = 0x80;
- eeprom_write(0x60, 0x80);
- delay_ms(18);
- portc = 0x00;
- delay_ms(1);
- portc = 0x80;
- delay_ms(1);
- }
- else
- {
- portc = 0x20;
- eeprom_write(0x60, 0x20);
- delay_ms(20);
- portc = 0x40;
- eeprom_write(0x60, 0x40);
- delay_ms(5);
- portc = 0x80;
- eeprom_write(0x60, 0x80);
- delay_ms(20);
- }
- }
- else if(porta.b4 == 0) // night mode
- {
- if(porta.b5 == 1) // blink mode
- {
- portc = 0x20;
- eeprom_write(0x60, 0x20);
- delay_ms(10);
- portc = 0x00;
- delay_ms(1);
- portc = 0x20;
- delay_ms(1);
- portc = 0x40;
- eeprom_write(0x60, 0x40);
- delay_ms(3);
- portc = 0x80;
- eeprom_write(0x60, 0x80);
- delay_ms(10);
- portc = 0x00;
- delay_ms(1);
- portc = 0x80;
- delay_ms(1);
- }
- else
- {
- portc = 0x20;
- eeprom_write(0x60, 0x20);
- delay_ms(12);
- portc = 0x40;
- eeprom_write(0x60, 0x40);
- delay_ms(3);
- portc = 0x80;
- eeprom_write(0x60, 0x80);
- delay_ms(12);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement