Uživatel:Trisktom
Z MAM wiki
(Rozdíly mezi verzemi)
(Založena nová stránka: ; ; example LED-show program for ATtiny 2313 ; ; 2-color LED with 300 Ohm resistor in series is supposed to be ; connected between pins 12 (PB0, LED_X) and 13 (PB1, LED_…) |
|||
Řádka 1: | Řádka 1: | ||
+ | <pre> | ||
+ | |||
+ | |||
+ | |||
Řádka 92: | Řádka 96: | ||
CBI PORTB,LED_X | CBI PORTB,LED_X | ||
RET | RET | ||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
+ | ; Sleep loop, wake up by the Interrupt, return with RETI back to sleep loop | ||
+ | |||
+ | loop: | ||
+ | sleep ; now AVR sleeps | ||
+ | nop ; return from Interrupt to this instruction | ||
+ | rjmp loop ; and sleep again | ||
+ | |||
+ | |||
+ | ; PCINT0 Service Routine: | ||
+ | ; | ||
+ | ; To do: *** rpm reading, regulation, etc. | ||
+ | |||
+ | |||
+ | isr1: | ||
+ | rcall KEYPRESS | ||
+ | |||
+ | mov R17, R16 | ||
+ | lsl R17 | ||
+ | lsl R17 ; multiply key number by 4 for 10 steps in 40 clock pulses of PWM | ||
+ | out OCR0B, R17 ; output pulse "high" lenght to PWM compare unit | ||
+ | |||
+ | reti ; return from Interrupt | ||
+ | |||
+ | |||
+ | ; Keyboard decoding: | ||
+ | |||
+ | KEYPRESS: | ||
+ | KEY0: | ||
+ | sbi PORTD, 0 | ||
+ | sbi PORTD, 1 | ||
+ | sbi PORTD, 2 | ||
+ | cbi PORTD, 3 ;log. 0 to the row with *, 0, #, D | ||
+ | sbic PINC, 3 | ||
+ | rjmp KEY1 | ||
+ | ldi R16, 0 ;pressed key 0 | ||
+ | rjmp KEYRET | ||
+ | KEY1: | ||
+ | cbi PORTD, 0 ;log. 0 to the row with 1, 2, 3, A | ||
+ | sbi PORTD, 1 ;log. 1 on another three | ||
+ | sbi PORTD, 2 | ||
+ | sbi PORTD, 3 | ||
+ | sbic PINC, 2 | ||
+ | rjmp KEY2 | ||
+ | ldi R16, 1 ;pressed key 1 | ||
+ | rjmp KEYRET | ||
+ | KEY2: | ||
+ | sbic PINC, 3 | ||
+ | rjmp KEY3 | ||
+ | ldi R16, 2 | ||
+ | rjmp KEYRET | ||
+ | KEY3: | ||
+ | sbic PINC, 4 | ||
+ | rjmp KEY4 | ||
+ | ldi R16, 3 | ||
+ | rjmp KEYRET | ||
+ | |||
+ | KEY4: | ||
+ | sbi PORTD, 0 | ||
+ | cbi PORTD, 1 ;log. 0 to the row with 4, 5, 6, B | ||
+ | sbi PORTD, 2 | ||
+ | sbi PORTD, 3 | ||
+ | sbic PINC, 2 | ||
+ | rjmp KEY5 | ||
+ | ldi R16, 4 ;pressed key 4 | ||
+ | rjmp KEYRET | ||
+ | KEY5: | ||
+ | sbic PINC, 3 | ||
+ | rjmp KEY6 | ||
+ | ldi R16, 5 | ||
+ | rjmp KEYRET | ||
+ | KEY6: | ||
+ | sbic PINC, 4 | ||
+ | rjmp KEY7 | ||
+ | ldi R16, 6 | ||
+ | rjmp KEYRET | ||
+ | |||
+ | KEY7: | ||
+ | sbi PORTD, 0 | ||
+ | sbi PORTD, 1 | ||
+ | cbi PORTD, 2 ;log. 0 to the row with 7, 8, 9, C | ||
+ | sbi PORTD, 3 | ||
+ | sbic PINC, 2 | ||
+ | rjmp KEY8 | ||
+ | ldi R16, 7 ;pressed key 7 | ||
+ | rjmp KEYRET | ||
+ | KEY8: | ||
+ | sbic PINC, 3 | ||
+ | rjmp KEY9 | ||
+ | ldi R16, 8 | ||
+ | rjmp KEYRET | ||
+ | KEY9: | ||
+ | sbic PINC, 4 | ||
+ | rjmp KEYRET | ||
+ | ldi R16, 9 | ||
+ | |||
+ | KEYRET: | ||
+ | cbi PORTD, 0 ; log. 0 on all rows for next key press catch | ||
+ | cbi PORTD, 1 | ||
+ | cbi PORTD, 2 | ||
+ | cbi PORTD, 3 | ||
+ | ret | ||
+ | |||
+ | |||
+ | |||
+ | </pre> |
Verze z 21. 3. 2013, 10:47
; ; example LED-show program for ATtiny 2313 ; ; 2-color LED with 300 Ohm resistor in series is supposed to be ; connected between pins 12 (PB0, LED_X) and 13 (PB1, LED_Y). ; ; Color1 shines when LED_X is high and LED_Y is low ; Color2 shines when LED_Y is high and LED_X is low ; LED is off when LED_Y and LED_X are both low or both high .EQU DDRB = $17 ; DDRB address .EQU PORTB = $18 ; PORTB address .EQU DDRD = $17 ; DDRB address .EQU PORTD = $18 ; PORTB address .EQU PINB =$16 .EQU LED_X = 0 ; LED_X is on PB0, pin 12 of ATtiny2313 .EQU LED_Y = 1 ; LED_Y is on PB1, pin 13 of ATtiny2313 ; Pins connected to LED are outputs, DDRx=1 (set): SBI DDRB, LED_X ; SBI - Set Bit in I/O Register SBI DDRB, LED_Y SBI DDRD, 0 SBI PORTB, 2 GO: RCALL COLOR1 RCALL WAIT SBIS PINB, 2 RCALL COLOR2 RCALL WAIT RJMP GO ;;; ;;; ;;; P R O C E D U R E S ;;; ;;; SMALLWAIT: INC R1 ; INC - Increment BRNE SMALLWAIT ; BRNE - Branch if Not Equal (Z flag) RET ; RET - Return from Subroutine WAIT: LDI R16, 4 ; LDI - Load Immediate WAIT1: INC R1 BRNE WAIT1 INC R2 BRNE WAIT1 DEC R16 BRNE WAIT1 RET COLOR1: SBI PORTB, LED_X CBI PORTB, LED_Y ; CBI - Clear Bit in I/O Register RET COLOR2: SBI PORTB, LED_Y CBI PORTB, LED_X RET COL3W: LDI R16, 2 COL3X: RCALL COLOR1 RCALL SMALLWAIT RCALL COLOR2 RCALL SMALLWAIT INC R2 BRNE COL3X DEC R16 BRNE COL3X DARK: CBI PORTB, LED_X CBI PORTB, LED_Y RET led:SBIS PINB,LED_X SBI PORTB,LED_X CBI PORTB,LED_X RET ; Sleep loop, wake up by the Interrupt, return with RETI back to sleep loop loop: sleep ; now AVR sleeps nop ; return from Interrupt to this instruction rjmp loop ; and sleep again ; PCINT0 Service Routine: ; ; To do: *** rpm reading, regulation, etc. isr1: rcall KEYPRESS mov R17, R16 lsl R17 lsl R17 ; multiply key number by 4 for 10 steps in 40 clock pulses of PWM out OCR0B, R17 ; output pulse "high" lenght to PWM compare unit reti ; return from Interrupt ; Keyboard decoding: KEYPRESS: KEY0: sbi PORTD, 0 sbi PORTD, 1 sbi PORTD, 2 cbi PORTD, 3 ;log. 0 to the row with *, 0, #, D sbic PINC, 3 rjmp KEY1 ldi R16, 0 ;pressed key 0 rjmp KEYRET KEY1: cbi PORTD, 0 ;log. 0 to the row with 1, 2, 3, A sbi PORTD, 1 ;log. 1 on another three sbi PORTD, 2 sbi PORTD, 3 sbic PINC, 2 rjmp KEY2 ldi R16, 1 ;pressed key 1 rjmp KEYRET KEY2: sbic PINC, 3 rjmp KEY3 ldi R16, 2 rjmp KEYRET KEY3: sbic PINC, 4 rjmp KEY4 ldi R16, 3 rjmp KEYRET KEY4: sbi PORTD, 0 cbi PORTD, 1 ;log. 0 to the row with 4, 5, 6, B sbi PORTD, 2 sbi PORTD, 3 sbic PINC, 2 rjmp KEY5 ldi R16, 4 ;pressed key 4 rjmp KEYRET KEY5: sbic PINC, 3 rjmp KEY6 ldi R16, 5 rjmp KEYRET KEY6: sbic PINC, 4 rjmp KEY7 ldi R16, 6 rjmp KEYRET KEY7: sbi PORTD, 0 sbi PORTD, 1 cbi PORTD, 2 ;log. 0 to the row with 7, 8, 9, C sbi PORTD, 3 sbic PINC, 2 rjmp KEY8 ldi R16, 7 ;pressed key 7 rjmp KEYRET KEY8: sbic PINC, 3 rjmp KEY9 ldi R16, 8 rjmp KEYRET KEY9: sbic PINC, 4 rjmp KEYRET ldi R16, 9 KEYRET: cbi PORTD, 0 ; log. 0 on all rows for next key press catch cbi PORTD, 1 cbi PORTD, 2 cbi PORTD, 3 ret