Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int state=0;
- void main() {
- ANSEL=0;
- ANSELH=0;
- TRISA.B3=1;//NIGHT DAY
- TRISA.B4=1;//ON OFF
- TRISC=0;
- PORTC=0;
- EEPROM_WRITE(0x00,0);
- while(1){
- if(PORTA.B4){ // on
- state=EEPROM_READ(0x00);
- if(PORTA.B3){ //DAY
- switch(state){
- case 0: //red
- PORTC=0b10000000;
- delay_ms(5);
- break;
- case 1: //yellow
- PORTC=0b01000000;
- delay_ms(3);
- break;
- case 2: //green
- PORTC=0b00100000;
- delay_ms(5);
- break;
- }
- }else{ //night
- switch(state){
- case 0: //red
- PORTC=0b10000000;
- delay_ms(3);
- break;
- case 1: //yellow
- PORTC=0b01000000;
- delay_ms(1);
- break;
- case 2: //green
- PORTC=0b00100000;
- delay_ms(3);
- break;
- }
- }
- state++;
- if(state>2) state=0;
- EEPROM_WRITE(0x00,state);
- }else {
- PORTC=0;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment