Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define F_CPU 1000000L
- #include <avr/io.h>
- #include <util/delay.h>
- #define SW (1<<PB0)
- #define PWM1 (1<<PB1)
- #define PWM2 (1<<PB2)
- #define PWM3 (1<<PB3)
- #define A (1<<PB4)
- #define B (1<<PB5)
- /* STAN NISKI */
- #define PWM1L (0<<PB1)
- #define PWM2L (0<<PB2)
- #define PWM3L (0<<PB3)
- /* http://eduinf.waw.pl/inf/prg/009_kurs_avr_old/0026.php */
- int ilosc; /* ZMIENNA LICZNIKA */
- int main(void) {
- /* PINY */
- DDRB = PWM1 | PWM1L | A | B; // Wyjscie pin 1,
- PORTB = SW; // Wyjścia podciągniete 1 pod VCC = SW
- PINB = SW; // Wejscie pin 0.
- /* TIMERY */
- TCCR0A = (1 << COM0B1) | (1 << COM0B0) | (1 << WGM01) | (1 << WGM00);
- TCCR0B = (1 << CS00);
- /* rejestr zegara ustawiony na częstotliwośc taktowania */
- OCR0B = (255); /* Maksymalna jasność diody D1 */
- while(1)
- {
- if (!(PINB & SW)) /*Jesli pin 0 wcisniety*/
- {
- int ilosc;++ /* DODAJ +1 DO LICZNIKA */
- _delay_ms(80); /* DRGANIE STYKÓW */
- while (!(PINB & SW)) {
- _delay_ms(80); /* DRGANIE STYKÓW */
- }
- }
- switch (ilosc) {
- case 5:
- /*Jesiilosc jest maks (5) zeruj ją. */
- int ilosc = 0;
- break;
- case 1:
- /* instrukcje, jeśli ilosc = 1 */
- /* MIGANIE DIODAMI */
- while (ilosc == 1) {
- /* STANY ZERO NA 4,5 PINIE MUX PRZEŁĄCZA NA Y/X0 */
- PORTB = (PWM1);
- _delay_ms(1000);
- PORTB = (PWM1L);
- }
- break;
- case 2:
- /* instrukcje, jeśli ilosc = 2 */
- /* ZAPALENIE DIODY ORAZ STAN WYSOKI NA WEJSCIU A MUX (PB4) */
- PORTB = (A); /* MUX WYJSCIE Y1*/
- while (ilosc == 2) {
- PORTB = (PWM1);
- }
- break;
- case 3:
- PORTB = (B); /* MUX WYJSCIE Y2 */
- while (ilosc == 3) {
- PORTB = (PWM1);
- _delay_ms(1000);
- PORTB = (PWM1L);
- _delay_ms(1000);
- PORTB = (PWM1);
- _delay_ms(1000);
- PORTB = (PWM1L);
- _delay_ms(5000);
- PORTB = (PWM1);
- _delay_ms(1000);
- PORTB = (PWM1L);
- _delay_ms(1000);
- PORTB = (PWM1);
- _delay_ms(1000);
- PORTB = (PWM1L);
- }
- break;
- case 4:
- /* instrukcje, jeśli ilosc = 4 */
- /* zmiana kolorów diod */
- PORTB = (A); /* MUX */
- while (ilosc == 4) {
- PORTB = (PWM1);
- _delay_ms(1000);
- PORTB = (PWM1L);
- PORTB = (PWM2);
- _delay_ms(1000);
- PORTB = (PWM2L);
- PORTB = (PWM3);
- _delay_ms(1000);
- PORTB = (PWM3L);
- }
- default :
- _delay_ms(10);
- break;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement