Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <tiny2313.h>
- #include <delay.h>
- // Declare your global variables here
- void main(void) {
- // Declare your local variables here
- // Crystal Oscillator division factor: 1
- #pragma optsize-
- CLKPR = (1 << CLKPCE);
- CLKPR = (0 << CLKPCE) | (0 << CLKPS3) | (0 << CLKPS2) | (0 << CLKPS1) | (0 << CLKPS0);
- #ifdef _OPTIMIZE_SIZE_
- #pragma optsize+
- #endif
- // Input/Output Ports initialization
- // Port B initialization
- // Function: Bit7=Out Bit6=Out Bit5=Out Bit4=Out Bit3=Out Bit2=Out Bit1=Out Bit0=Out
- DDRB = (1 << DDB7) | (1 << DDB6) | (1 << DDB5) | (1 << DDB4) | (1 << DDB3) | (1 << DDB2) | (1 << DDB1) |
- (1 << DDB0);
- // State: Bit7=0 Bit6=0 Bit5=0 Bit4=0 Bit3=0 Bit2=0 Bit1=0 Bit0=0
- PORTB = (0 << PORTB7) | (0 << PORTB6) | (0 << PORTB5) | (0 << PORTB4) | (0 << PORTB3) | (0 << PORTB2) |
- (0 << PORTB1) | (0 << PORTB0);
- // Port D initialization
- // Function: Bit6=In Bit5=In Bit4=In Bit3=In Bit2=In Bit1=In Bit0=In
- DDRD = (0 << DDD6) | (0 << DDD5) | (0 << DDD4) | (0 << DDD3) | (0 << DDD2) | (0 << DDD1) | (0 << DDD0);
- // State: Bit6=P Bit5=P Bit4=P Bit3=P Bit2=P Bit1=P Bit0=P
- PORTD = (1 << PORTD6) | (1 << PORTD5) | (1 << PORTD4) | (1 << PORTD3) | (1 << PORTD2) | (1 << PORTD1) |
- (1 << PORTD0);
- // PORTB.0 red
- // PORTB.1 yellow
- // PORTB.3 green
- //
- // PORTB.2 red
- // PORTB.4 green
- PORTB.0 = 0;
- PORTB.1 = 0;
- PORTB.2 = 0;
- PORTB.3 = 0;
- PORTB.4 = 0;
- while (true) {
- while (PIND.0 == 0) {
- PORTB.1 = 1;
- PORTB.5 = 1;
- delay_ms(300);
- PORTB.1 = 0;
- PORTB.5 = 0;
- delay_ms(300);
- }
- PORTB.0 = 1;
- PORTB.4 = 1;
- delay_ms(2000);
- PORTB.1 = 1;
- PORTB.4 = 0;
- PORTB.2 = 1;
- delay_ms(1000);
- PORTB.0 = 0;
- PORTB.1 = 0;
- PORTB.3 = 1;
- delay_ms(3000);
- PORTB.3 = 0;
- delay_ms(300);
- PORTB.3 = 1;
- delay_ms(300);
- PORTB.3 = 0;
- delay_ms(300);
- PORTB.3 = 1;
- delay_ms(300);
- PORTB.3 = 0;
- PORTB.1 = 1;
- delay_ms(1000);
- PORTB.1 = 0;
- PORTB.2 = 0;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement