Uživatel:Krctomas

Z MAM wiki

(Rozdíly mezi verzemi)
Přejít na: navigace, hledání
Řádka 1: Řádka 1:
-
==Cvičení 4==
+
==Cvičení 4==
-
'''Při stisku tlačítka 1 svítí červená LED, jinak zelená'''
+
'''ATtiny 2313'''  - Při stisku tlačítka 1 svítí červená LED, jinak zelená
<pre>
<pre>
Řádka 100: Řádka 100:
</pre>
</pre>
-
==Klávesnice==
+
==Cvičení 5==  
-
'''Připojení klávesnice na porty'''
+
'''ATmega88''' - Při stisku tlačítka 1 se větrák roztočí s hodnotou PWM danou R16
-
 
+
-
Konektor:
+
-
{| class="wikitable" border="1"
+
-
|-  
+
-
! COL1
+
-
! COL3
+
-
! ROW1
+
-
! ROW3
+
-
|-
+
-
! COL2
+
-
! COL4
+
-
! ROW2
+
-
! ROW4
+
-
|}
+
-
 
+
-
Odpovídající porty na ATiny2313:
+
-
{| class="wikitable" border="1"
+
-
|-
+
-
! 14
+
-
! 16
+
-
! 6
+
-
! 8
+
-
|-
+
-
! 15
+
-
! 17
+
-
! 7
+
-
! 9
+
-
|}
+
-
 
+
-
<pre>
+
-
SBI DDRD, 2    ; nastaveni ctyr vstupu
+
-
SBI DDRD, 3
+
-
SBI DDRD, 4
+
-
SBI DDRD, 5
+
-
 
+
-
SBI PORTB, 2    ; nastaveni pull-up rezistoru
+
-
SBI PORTB, 3
+
-
SBI PORTB, 4
+
-
SBI PORTB, 5
+
-
 
+
-
KLAVESNICE:
+
-
JEDNA:
+
-
CBI PORTD,2  ; prvni radek 0, ostatni 1
+
-
SBI PORTD,3
+
-
SBI PORTD,4
+
-
SBI PORTD,5
+
-
SBIC PINB,2
+
-
RJMP DVE
+
-
LDI R17,1
+
-
RET
+
-
DVE:
+
-
SBIC PINB,3
+
-
RJMP TRI
+
-
LDI R17,2
+
-
RET
+
-
TRI:
+
-
SBIC PINB,4
+
-
RJMP ACKO
+
-
LDI R17,3
+
-
RET
+
-
ACKO:
+
-
SBIC PINB,5
+
-
RJMP CTYRI
+
-
LDI R17,11
+
-
RET
+
-
CTYRI:
+
-
SBI PORTD,2  ; druhy radek 0, ostatni 1
+
-
CBI PORTD,3
+
-
SBI PORTD,4
+
-
SBI PORTD,5
+
-
SBIC PINB,2
+
-
RJMP PET
+
-
LDI R17,4
+
-
RET
+
-
PET:
+
-
SBIC PINB,3
+
-
RJMP SEST
+
-
LDI R17,5
+
-
RET
+
-
SEST:
+
-
SBIC PINB,4
+
-
RJMP BECKO
+
-
LDI R17,6
+
-
RET
+
-
BECKO:
+
-
SBIC PINB,5
+
-
RJMP SEDM
+
-
LDI R17,12
+
-
RET
+
-
SEDM:
+
-
SBI PORTD,2  ; treti radek 0, ostatni 1
+
-
SBI PORTD,3
+
-
CBI PORTD,4
+
-
SBI PORTD,5
+
-
SBIC PINB,2
+
-
RJMP OSM
+
-
LDI R17,7
+
-
RET
+
-
OSM:
+
-
SBIC PINB,3
+
-
RJMP DEVET
+
-
LDI R17,8
+
-
RET
+
-
DEVET:
+
-
SBIC PINB,4
+
-
RJMP CECKO
+
-
LDI R17,9
+
-
RET
+
-
CECKO:
+
-
SBIC PINB,5
+
-
RJMP HVEZDICKA
+
-
LDI R17,13
+
-
RET
+
-
HVEZDICKA:
+
-
SBI PORTD,2  ; ctvrty radek 0, ostatni 1
+
-
SBI PORTD,3
+
-
SBI PORTD,4
+
-
CBI PORTD,5
+
-
SBIC PINB,2
+
-
RJMP NULA
+
-
LDI R17,15
+
-
RET
+
-
NULA:
+
-
SBIC PINB,3
+
-
RJMP KRIZEK
+
-
LDI R17,0
+
-
RET
+
-
KRIZEK:
+
-
SBIC PINB,4
+
-
RJMP DECKO
+
-
LDI R17,16
+
-
RET
+
-
DECKO:
+
-
SBIC PINB,5
+
-
RJMP JEDNA
+
-
LDI R17,14
+
-
RET
+
-
</pre>
+
-
 
+
-
==Cvičení 5==
+
<pre>
<pre>
;  
;  

Verze z 20. 3. 2013, 17:08

Cvičení 4

ATtiny 2313 - Při stisku tlačítka 1 svítí červená LED, jinak zelená


; 
; 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 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

	.EQU DDRD = $11
	.EQU PORTD = $12
	.EQU PIND = $10

; 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, 4
	SBI PORTB, 2
GO:
	RCALL COLOR1
	RCALL WAIT
	SBIS PINB, 2
	RJMP GOP
	RCALL WAIT
	RJMP GO

GOP:
	RCALL COLOR2
	SBIC PINB, 2
	RJMP GO
	RJMP GOP

;;;
;;;
;;; P R O C E D U R E S
;;;
;;;
	
SMALLWAIT:
        LDI R16, 100
SMALLWAIT1:
	INC R1		; INC - Increment
	BRNE SMALLWAIT1	; BRNE - Branch if Not Equal (Z flag) 				
	DEC R16
	BRNE WAIT1
	RET             ; RET - Return from Subroutine

WAIT:
	LDI R16, 4	; LDI - Load Immediate
WAIT1:	INC R1          ; Bezi az do R1=255, dalsi krok - preteceni, R1=0
	BRNE WAIT1	; Pokud v R1 neni 0, skoc na 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
	RET

DARK:
        CBI PORTB, LED_X
	CBI PORTB, LED_Y
	RET

Cvičení 5

ATmega88 - Při stisku tlačítka 1 se větrák roztočí s hodnotou PWM danou R16

; 
; example fan program for ATmega88
;
; P4 CPU fan Ucc pin is supposed to be connected 
; to +12 V, GND pin is supposed to be connected 
; to FET Drain, Source on GND, Gate on 
; pin 16 (PB2, FAN). Fan runs when FAN output is log. H.
;
; FAN is switched ON with switch between PC2 and PD2


	.EQU DDRB = $04
	.EQU PORTB = $05

	.EQU DDRC = $07
	.EQU PORTC = $08
	.EQU PINC = $06

	.EQU DDRD = $0A
	.EQU PORTD = $0B
	.EQU PIND = $09

;	.INCLUDE "m168def.inc"  ; replaces previous lines of the program

	.EQU FAN = 2


; Pin driving FAN is set as output:

	SBI	DDRB, FAN

; Basic keyboard init:

; One switch of matrix keyboard is connected between PINC 2 a PIND 2
; Zero values of DDRC, 2 and PORTB, 2 are implicit

	SBI DDRD, 2
	SBI PORTC, 2


; Init:
	RCALL   FAN_OFF

GO:	SBIS	PINC, 2
	RCALL	PWM   ; Simple PWM control of the FAN, if the key is pressed
	RJMP	GO


;;;
;;;
;;; P R O C E D U R E S
;;;
;;;
	
VERYSMALLWAIT:
	LDI R20, 0xFC
	MOV R1, R20
SMALLWAIT:
	INC	R1
	BRNE	SMALLWAIT
	RET

WAIT:
	LDI	R21, 4
WAIT1:
	INC	R1
	BRNE	WAIT1
	INC	R2
	BRNE	WAIT1
	DEC	R21
	BRNE	WAIT1
	RET
	
FAN_ON:
	SBI	PORTB, FAN
	RET

FAN_OFF:
	CBI	PORTB, FAN
	RET

FAN3W:
	LDI	R16, 0x20
FAN3X:
 	RCALL	FAN_ON
	RCALL	VERYSMALLWAIT  ; pulse ratio controlled by number of waits
	RCALL	VERYSMALLWAIT  ; 4:1 in this case
	RCALL	VERYSMALLWAIT
	RCALL	VERYSMALLWAIT
	RCALL	FAN_OFF
	RCALL	VERYSMALLWAIT 


	INC	R2
	BRNE	FAN3X
	DEC	R16
	BRNE	FAN3X
	RET

PWM:
	LDI	R16, 8
	MOV 	R17, R16
	INC		R17
	LDI		R18, 0xF8
	OR		R18, R16
PWM_ON:
	DEC		R17
	BREQ	PWM_OFF
	SBI		PORTB, FAN
	RCALL 	VERYSMALLWAIT
	RJMP	PWM_ON
PWM_OFF:
	INC		R18
	BREQ	PWM_RET
	CBI		PORTB, FAN
	RCALL 	VERYSMALLWAIT
	RJMP	PWM_OFF
PWM_RET:
	RET

Osobní nástroje