Uživatel:Koubazde

Z MAM wiki

(Rozdíly mezi verzemi)
Přejít na: navigace, hledání
(Semestralni prace - Ovladani ventilatoru teplovzdusneho rozvodu)
 
(Není zobrazeno 37 mezilehlých verzí.)
Řádka 1: Řádka 1:
Prosím zformátujte. Horčík
Prosím zformátujte. Horčík
-
 
+
==tyden 4.==
-
.EQU DDRB = $17 ; DDRB address
+
    .EQU DDRB = $17 ; DDRB address
-
.EQU PORTB = $18 ; PORTB address
+
    .EQU PORTB = $18 ; PORTB address
-
.EQU PINB = $16 ; P
+
    .EQU PINB = $16 ; P
-
 
+
   
-
.EQU LED_X = 0 ; LED_X is on PB0, pin 12 of ATtiny2313
+
    .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 LED_Y = 1 ; LED_Y is on PB1, pin 13 of ATtiny2313
-
 
+
   
-
; Pins connected to LED are outputs, DDRx=1 (set):
+
    ; Pins connected to LED are outputs, DDRx=1 (set):
-
 
+
    ; pro led
-
; pro led
+
    SBI DDRB, LED_X ; SBI - Set Bit in I/O Register
-
SBI DDRB, LED_X ; SBI - Set Bit in I/O Register
+
    SBI DDRB, LED_Y
-
SBI DDRB, LED_Y
+
   
-
 
+
    SHOW:
-
SHOW:
+
   
-
 
+
    ;pro klavesnici
-
;pro klavesnici
+
    SBI DDRB, 7  ; output pin 19
-
SBI DDRB, 7  ; output pin 19
+
    SBI PORTB, 2 ; enables pull-up rezistor on pin 14
-
SBI PORTB, 2 ; enables pull-up rezistor on pin 14
+
   
-
 
+
    GO:
-
GO:
+
    RCALL  COLOR1
-
RCALL  COLOR1
+
    RCALL WAIT
-
RCALL WAIT
+
    SBIS PINB, 2 ; skip if bit is set
-
SBIS PINB, 2 ; skip if bit is set
+
    RCALL COLOR2
-
RCALL COLOR2
+
    RCALL WAIT
-
RCALL WAIT
+
    RJMP GO
-
RJMP GO
+
   
-
+
    RJMP SHOW ; RJMP - Relative Jump  
-
RJMP SHOW ; RJMP - Relative Jump  
+
   
-
 
+
    ;;;
-
 
+
    ;;;
-
 
+
    ;;; P R O C E D U R E S
-
 
+
    ;;;
-
;;;
+
    ;;;
-
;;;
+
   
-
;;; 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
-
SMALLWAIT:
+
   
-
INC R1 ; INC - Increment
+
    WAIT:
-
BRNE SMALLWAIT ; BRNE - Branch if Not Equal (Z flag)  
+
    LDI R16, 1 ; LDI nastaveni casu
-
RET ; RET - Return from Subroutine
+
    WAIT1:
-
 
+
    INC R1
-
WAIT:
+
    BRNE WAIT1
-
LDI R16, 1 ; LDI nastaveni casu
+
    INC R2
-
WAIT1: INC R1
+
    BRNE WAIT1
-
BRNE WAIT1
+
    DEC R16
-
INC R2
+
    BRNE WAIT1
-
BRNE WAIT1
+
    RET
-
DEC R16
+
   
-
BRNE WAIT1
+
    COLOR1:
-
RET
+
-
+
-
COLOR1:
+
     SBI PORTB, LED_X
     SBI PORTB, LED_X
-
CBI PORTB, LED_Y ; CBI - Clear Bit in I/O Register
+
    CBI PORTB, LED_Y ; CBI - Clear Bit in I/O Register
-
RET
+
    RET
-
 
+
   
-
COLOR2:
+
    COLOR2:
     SBI PORTB, LED_Y
     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_X
-
CBI PORTB, LED_Y
+
    RET
-
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
-
........................................
 
-
tyden 5.
 
 +
==tyden 5.==
-
;
 
-
; 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
 
 +
    ;
 +
    ; 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 "m88def.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
 +
   
 +
    LDI R17, 0b00001111 ; pripravi hodnotu k presunu
 +
    OUT DDRD, R17 ; D0-3, piny 2-5 nastavi vystupy
 +
    OUT PORTC, R17 ; C0-3, piny 23-26 pull up rez
 +
   
 +
   
 +
    ; Init:
 +
    RCALL  FAN_OFF
 +
   
 +
    ;GO: SBIS PINC, 2
 +
    ; RCALL FAN3W  ; Simple PWM control of the FAN, if the key is pressed
 +
    ; RJMP GO
 +
   
 +
    LDI R16, 0x02 ; konstanta pro pwm
 +
   
 +
   
 +
   
 +
    PWM: ; nastaveni pwm
 +
    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
 +
    RJMP PWM
 +
   
 +
   
 +
    ;;;
 +
    ;;;
 +
    ;;; 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
 +
   
 +
   
 +
    ; obsluha preruseni
 +
   
 +
   
 +
    ; obsluha CTENI KLAVESNICE PRI preruseni
 +
   
 +
    KEYPRESS:
 +
    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
 +
    KEY1:
 +
    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
 +
   
 +
    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 KEYRET
 +
    LDI R16, 0 ;pressed key 0
 +
   
 +
    KEYRET:
 +
    RET
-
.EQU DDRB = $04
+
==tyden 6==
-
.EQU PORTB = $05
+
-
.EQU DDRC = $07
+
    ; example fan program for ATmega88 with Timer controlled PWM&Interrupt&Sleep
-
.EQU PORTC = $08
+
    ;
-
.EQU PINC = $06
+
    ; Rotation speed  is controlled by keyboard,
 +
    ; keys 0-9 represent the speed between 0 and 100 %
 +
    ;
 +
    ; Fan starts to rotate with the first valid key press
 +
    ;
 +
    ; To do: *** Catch only the key press, not key release
 +
    ;
 +
    ; To do: *** Set higher value of PWM (=higher fan rpm) for
 +
    ; a few first periods to start the fan reliably
 +
    ;
 +
    ;
 +
    ; P4 CPU fan Ucc pin is supposed to be connected
 +
    ; to +15 V, GND pin is supposed to be connected
 +
    ; to NMOS Drain,, Source on GND, Gate on
 +
    ; pin 11 (OC0B, PD5). Fan runs when pin 11 is high.
 +
   
 +
    .INCLUDE "m88def.inc"
 +
   
 +
    .EQU PWM_PULSES = 36 ; value for 27.8 kHz PWM/maximalni hodnota pro PWM counter
 +
    ;.EQU PWM_PULSES = 45 ; value for 22.2 kHz PWM
 +
   
 +
    .ORG 0x0000
 +
    rjmp Main ; Resetovaci vektor/skok na hl. program
 +
   
 +
    .ORG 0x0008
 +
    rjmp isr1 ; PCINT1 Handler/skok na obsluhu preruseni
 +
   
 +
    ; Main program start
 +
   
 +
    Main:
 +
    ; Stack pointer init:
 +
    ldi r16,high(RAMEND); Main program start
 +
    out SPH,r16 ; Set Stack Pointer to top of RAM
 +
    ldi r16,low(RAMEND)
 +
    out SPL,r16
 +
   
 +
    ; Hardware initialization
 +
   
 +
    ; Keyboard init:
 +
   
 +
    ; !!!!!zapojeni!!!!
 +
    ; col1 col3 row1 row3
 +
    ; col2 col4 row2 row4
 +
    ; !!!kabel!!!
 +
   
 +
    ; vstup z klávesnice = sloupce 1-3
 +
    cbi DDRC, 2 ; 25
 +
    cbi DDRC, 3 ; 26
 +
    cbi DDRC, 4 ; 27
 +
   
 +
    ; set internal Pull-Ups for keyboard
 +
    sbi PORTC, 2
 +
    sbi PORTC, 3
 +
    sbi PORTC, 4
 +
   
 +
    ; set driving outputs for keyboard (ROW1-ROW4)
 +
    sbi DDRD, 0 ; 2
 +
    sbi DDRD, 1 ; 3
 +
    sbi DDRD, 2 ; 4
 +
    sbi DDRD, 3 ; 5
 +
   
 +
    cbi PORTD, 0 ; log. 0 on all rows
 +
    cbi PORTD, 1
 +
    cbi PORTD, 2
 +
    cbi PORTD, 3
 +
   
 +
    ; Timer controlled PWM init:
 +
    ;
 +
    ; There are registers TCCR0A and TCCR0B for config, DDRD for output bit
 +
    ; enabling, OCR0A for counter lenght and OCR0A for pulse "high" lenght.
 +
    ; Register TIMSK0 controlls interrupts - not used, 0x00 by default
 +
   
 +
    PWM_INIT:
 +
    ldi R17, 0b00100011 ; Fast PWM Mode, out on OC0B, non Inverting
 +
    out TCCR0A, R17 ;
 +
    ldi R17, 0b00001001 ; WGM2:1 (Fast PWM), CS2..0:001 (internal clock, prescale=1)
 +
    out TCCR0B, R17
 +
    ldi R17, PWM_PULSES ; load number of clock pulses for 1 PWM period
 +
    out OCR0A, R17 
 +
   
 +
    sbi DDRD, 5 ; PWM output OC0B (PD5 pin cislo 11)
 +
   
 +
    ; Keyboard interrupt setup
 +
    ;
 +
    ; Activation of pin change interrupt - PROBLEM!!! PCICR and PCIMSK are
 +
    ; extended I/O registers (0x68 and 0x6C), and must be handled as
 +
    ; a memory location
 +
   
 +
    ldi r26, PCICR ; load address of PCICR in Y low
 +
    clr r27 ; load high byte with 0
 +
    ldi r16,0b00000010 ; activate PCINT1
 +
    st X, r16 ; store new PCINT1
 +
   
 +
    ldi r26, PCMSK1 ; load address of PCMSK1 in Y low
 +
    clr r27 ; load high byte with 0
 +
    ldi r16,0b00011100 ; allow pin change interrupt on portC bits 2,3,4
 +
    st X, r16 ; store new PCMSK1
 +
   
 +
    sei ; Enable interrupts
 +
   
 +
    ; Set sleep mode of the CPU
 +
    ; SMCR: 0,0,0,0,SM2,SM1,SM0,SE  SM2..0: Sleep Mode Select Bits, SE: Sleep enabled)
 +
   
 +
    ldi r16,0b00000001 ; Idle mode
 +
    out SMCR,r16 ; Sleep mode set
 +
   
 +
    ; 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
-
.EQU DDRD = $0A
+
==Tyden 7==
-
.EQU PORTD = $0B
+
-
.EQU PIND = $09
+
-
 
+
-
; .INCLUDE "m88def.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
+
-
 
+
-
LDI R17, 0b00001111 ; pripravi hodnotu k presunu
+
-
OUT DDRD, R17 ; D0-3, piny 2-5 nastavi vystupy
+
-
OUT PORTC, R17 ; C0-3, piny 23-26 pull up rez
+
-
 
+
-
 
+
-
; Init:
+
-
RCALL  FAN_OFF
+
-
 
+
-
;GO: SBIS PINC, 2
+
-
; RCALL FAN3W  ; Simple PWM control of the FAN, if the key is pressed
+
-
; RJMP GO
+
-
 
+
-
LDI R16, 0x02 ; konstanta pro pwm
+
-
 
+
-
 
+
-
 
+
-
 
+
-
 
+
-
 
+
-
PWM: ; nastaveni pwm
+
-
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
+
-
RJMP PWM
+
-
 
+
-
 
+
-
 
+
-
 
+
-
 
+
-
 
+
-
;;;
+
-
;;;
+
-
;;; 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
+
-
 
+
-
 
+
-
 
+
-
; obsluha preruseni
+
-
 
+
-
 
+
-
 
+
-
;...........UDELAT
+
-
 
+
-
 
+
-
; obsluha CTENI KLAVESNICE PRI preruseni
+
-
 
+
-
 
+
-
KEYPRESS:
+
-
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
+
-
KEY1:
+
-
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
+
-
;
+
-
;
+
-
; etc.
+
-
;
+
-
;
+
-
 
+
-
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 KEYRET
+
-
LDI R16, 0 ;pressed key 0
+
-
 
+
-
KEYRET:
+
-
RET
+
-
 
+
-
 
+
-
===================================
+
-
=== tyden 6
+
-
 
+
-
; example fan program for ATmega88 with Timer controlled PWM&Interrupt&Sleep
+
-
;
+
-
; Rotation speed  is controlled by keyboard,
+
-
; keys 0-9 represent the speed between 0 and 100 %
+
-
;
+
-
; Fan starts to rotate with the first valid key press
+
-
;
+
-
; To do: *** Catch only the key press, not key release
+
-
;
+
-
; To do: *** Set higher value of PWM (=higher fan rpm) for
+
-
; a few first periods to start the fan reliably
+
-
;
+
-
;
+
-
; P4 CPU fan Ucc pin is supposed to be connected
+
-
; to +15 V, GND pin is supposed to be connected
+
-
; to NMOS Drain,, Source on GND, Gate on
+
-
; pin 11 (OC0B, PD5). Fan runs when pin 11 is high.
+
-
 
+
-
 
+
-
.INCLUDE "m88def.inc"
+
-
 
+
-
.EQU PWM_PULSES = 36 ; value for 27.8 kHz PWM/maximalni hodnota pro PWM counter
+
-
;.EQU PWM_PULSES = 45 ; value for 22.2 kHz PWM
+
-
 
+
-
 
+
-
.ORG 0x0000
+
-
rjmp Main ; Resetovaci vektor/skok na hl. program
+
-
 
+
-
.ORG 0x0008
+
-
rjmp isr1 ; PCINT1 Handler/skok na obsluhu preruseni
+
-
 
+
-
 
+
-
; Main program start
+
-
 
+
-
Main:
+
-
 
+
-
; Stack pointer init:
+
-
ldi r16,high(RAMEND); Main program start
+
-
out SPH,r16 ; Set Stack Pointer to top of RAM
+
-
ldi r16,low(RAMEND)
+
-
out SPL,r16
+
-
 
+
-
 
+
-
; Hardware initialization
+
-
 
+
-
; Keyboard init:
+
-
 
+
-
; !!!!!zapojeni!!!!
+
-
; col1 col3 row1 row3
+
-
; col2 col4 row2 row4
+
-
; !!!kabel!!!
+
-
 
+
-
; vstup z klávesnice = sloupce 1-3
+
-
cbi DDRC, 2 ; 25
+
-
cbi DDRC, 3 ; 26
+
-
cbi DDRC, 4 ; 27
+
-
 
+
-
; set internal Pull-Ups for keyboard
+
-
sbi PORTC, 2
+
-
sbi PORTC, 3
+
-
sbi PORTC, 4
+
-
 
+
-
; set driving outputs for keyboard (ROW1-ROW4)
+
-
sbi DDRD, 0 ; 2
+
-
sbi DDRD, 1 ; 3
+
-
sbi DDRD, 2 ; 4
+
-
sbi DDRD, 3 ; 5
+
-
 
+
-
cbi PORTD, 0 ; log. 0 on all rows
+
-
cbi PORTD, 1
+
-
cbi PORTD, 2
+
-
cbi PORTD, 3
+
-
 
+
-
 
+
-
; Timer controlled PWM init:
+
-
;
+
-
; There are registers TCCR0A and TCCR0B for config, DDRD for output bit
+
-
; enabling, OCR0A for counter lenght and OCR0A for pulse "high" lenght.
+
-
; Register TIMSK0 controlls interrupts - not used, 0x00 by default
+
-
 
+
-
PWM_INIT:
+
-
ldi R17, 0b00100011 ; Fast PWM Mode, out on OC0B, non Inverting
+
-
out TCCR0A, R17 ;
+
-
ldi R17, 0b00001001 ; WGM2:1 (Fast PWM), CS2..0:001 (internal clock, prescale=1)
+
-
out TCCR0B, R17
+
-
ldi R17, PWM_PULSES ; load number of clock pulses for 1 PWM period
+
-
out OCR0A, R17 
+
-
 
+
-
sbi DDRD, 5 ; PWM output OC0B (PD5 pin cislo 11)
+
-
 
+
-
 
+
-
; Keyboard interrupt setup
+
-
;
+
-
; Activation of pin change interrupt - PROBLEM!!! PCICR and PCIMSK are
+
-
; extended I/O registers (0x68 and 0x6C), and must be handled as
+
-
; a memory location
+
-
 
+
-
ldi r26, PCICR ; load address of PCICR in Y low
+
-
clr r27 ; load high byte with 0
+
-
ldi r16,0b00000010 ; activate PCINT1
+
-
st X, r16 ; store new PCINT1
+
-
 
+
-
ldi r26, PCMSK1 ; load address of PCMSK1 in Y low
+
-
clr r27 ; load high byte with 0
+
-
ldi r16,0b00011100 ; allow pin change interrupt on portC bits 2,3,4
+
-
st X, r16 ; store new PCMSK1
+
-
 
+
-
sei ; Enable interrupts
+
-
 
+
-
 
+
-
; Set sleep mode of the CPU
+
-
; SMCR: 0,0,0,0,SM2,SM1,SM0,SE  SM2..0: Sleep Mode Select Bits, SE: Sleep enabled)
+
-
 
+
-
ldi r16,0b00000001 ; Idle mode
+
-
out SMCR,r16 ; Sleep mode set
+
-
 
+
-
 
+
-
; 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
+
-
 
+
-
=======================================================================
+
-
Tyden 7
+
Ovladani vetraku, osetreni stisku 2 tlacitek na klavesnici, rozbeh z 0
Ovladani vetraku, osetreni stisku 2 tlacitek na klavesnici, rozbeh z 0
-
-----------------------------------------------------------------------
+
    -----------------------------------------------------------------------
-
 
+
   
-
 
+
    ;===================================================
-
 
+
    ;======= by Jelinek Martin and Kouba Zdenek=========
-
 
+
    ;===================================================
-
 
+
    ;
-
;===================================================
+
    ; fan(ny) program for ATmega88 with Timer controlled PWM&Interrupt&Sleep
-
;======= by Jelinek Martin and Kouba Zdenek=========
+
    ;
-
;===================================================
+
    ; Rotation speed  is controlled by keyboard,  
-
;
+
    ; keys 0-9 represent the speed between 0 and 100 %
-
; fan(ny) program for ATmega88 with Timer controlled PWM&Interrupt&Sleep
+
    ;
-
;
+
    ; Fan starts to rotate with the first valid key press
-
; Rotation speed  is controlled by keyboard,  
+
    ;
-
; keys 0-9 represent the speed between 0 and 100 %
+
    ; To do: *** Catch only the key press, not key release
-
;
+
    ;
-
; Fan starts to rotate with the first valid key press
+
    ; To do: *** Set higher value of PWM (=higher fan rpm) for  
-
;
+
    ; a few first periods to start the fan reliably
-
; To do: *** Catch only the key press, not key release
+
    ;
-
;
+
    ;
-
; To do: *** Set higher value of PWM (=higher fan rpm) for  
+
    ; P4 CPU fan Ucc pin is supposed to be connected  
-
; a few first periods to start the fan reliably
+
    ; to +15 V, GND pin is supposed to be connected  
-
;
+
    ; to NMOS Drain,, Source on GND, Gate on  
-
;
+
    ; pin 11 (OC0B, PD5). Fan runs when pin 11 is high.
-
; P4 CPU fan Ucc pin is supposed to be connected  
+
   
-
; to +15 V, GND pin is supposed to be connected  
+
    .INCLUDE "m88def.inc"
-
; to NMOS Drain,, Source on GND, Gate on  
+
   
-
; pin 11 (OC0B, PD5). Fan runs when pin 11 is high.
+
    .EQU PWM_PULSES = 36 ; value for 27.8 kHz PWM/maximalni hodnota pro PWM counter/podle pouziteho vetraku
-
 
+
    ;.EQU PWM_PULSES = 45 ; value for 22.2 kHz PWM
-
 
+
   
-
.INCLUDE "m88def.inc"
+
    .ORG 0x0000  
-
 
+
    rjmp Main ; Resetovaci vektor/skok na hl. program
-
.EQU PWM_PULSES = 36 ; value for 27.8 kHz PWM/maximalni hodnota pro PWM counter/podle pouziteho vetraku
+
   
-
;.EQU PWM_PULSES = 45 ; value for 22.2 kHz PWM
+
    .ORG 0x0008  
-
 
+
    rjmp isr1 ; PCINT1 Handler/skok na obsluhu preruseni
-
 
+
   
-
.ORG 0x0000  
+
    ; Main program start
-
rjmp Main ; Resetovaci vektor/skok na hl. program
+
   
-
 
+
    Main:  
-
.ORG 0x0008  
+
   
-
rjmp isr1 ; PCINT1 Handler/skok na obsluhu preruseni
+
    ; Stack pointer init:
-
 
+
    ldi r16,high(RAMEND) ; Main program start
-
 
+
    out SPH,r16 ; Set Stack Pointer to top of RAM
-
; Main program start
+
    ldi r16,low(RAMEND)
-
 
+
    out SPL,r16
-
Main:  
+
   
-
 
+
    ; Hardware initialization
-
; Stack pointer init:
+
   
-
ldi r16,high(RAMEND) ; Main program start
+
    ldi r19, 0 ;reg R19 je pouzit v rutine pro rozbehovy puls
-
out SPH,r16 ; Set Stack Pointer to top of RAM
+
   
-
ldi r16,low(RAMEND)
+
    ; Keyboard init:
-
out SPL,r16
+
   
-
 
+
    ; !!!!!zapojeni!!!!
-
 
+
    ; col1 col3 row1 row3
-
; Hardware initialization
+
    ; col2 col4 row2 row4
-
 
+
    ; !!!kabel!!!
-
ldi r19, 0 ;reg R19 je pouzit v rutine pro rozbehovy puls
+
   
-
 
+
    ; vstup z klávesnice = sloupce 1-3
-
; Keyboard init:
+
    cbi DDRC, 2 ; 25
-
 
+
    cbi DDRC, 3 ; 26
-
; !!!!!zapojeni!!!!
+
    cbi DDRC, 4 ; 27
-
; col1 col3 row1 row3
+
   
-
; col2 col4 row2 row4
+
    ; set internal Pull-Ups for keyboard
-
; !!!kabel!!!
+
    sbi PORTC, 2
-
 
+
    sbi PORTC, 3
-
; vstup z klávesnice = sloupce 1-3
+
    sbi PORTC, 4
-
cbi DDRC, 2 ; 25
+
   
-
cbi DDRC, 3 ; 26
+
    ; set driving outputs for keyboard (ROW1-ROW4)
-
cbi DDRC, 4 ; 27
+
    sbi DDRD, 0 ; 2
-
 
+
    sbi DDRD, 1 ; 3
-
; set internal Pull-Ups for keyboard
+
    sbi DDRD, 2 ; 4
-
sbi PORTC, 2
+
    sbi DDRD, 3 ; 5
-
sbi PORTC, 3
+
   
-
sbi PORTC, 4
+
    cbi PORTD, 0 ; log. 0 on all rows
-
 
+
    cbi PORTD, 1
-
; set driving outputs for keyboard (ROW1-ROW4)
+
    cbi PORTD, 2
-
sbi DDRD, 0 ; 2
+
    cbi PORTD, 3
-
sbi DDRD, 1 ; 3
+
   
-
sbi DDRD, 2 ; 4
+
    ; Timer controlled PWM init:
-
sbi DDRD, 3 ; 5
+
    ;
-
 
+
    ; There are registers TCCR0A and TCCR0B for config, DDRD for output bit
-
cbi PORTD, 0 ; log. 0 on all rows
+
    ; enabling, OCR0A for counter lenght and OCR0A for pulse "high" lenght.
-
cbi PORTD, 1
+
    ; Register TIMSK0 controlls interrupts - not used, 0x00 by default  
-
cbi PORTD, 2
+
   
-
cbi PORTD, 3
+
    PWM_INIT:
-
 
+
    ldi R17, 0b00100011 ; Fast PWM Mode, out on OC0B, non Inverting
-
 
+
    out TCCR0A, R17 ;  
-
; Timer controlled PWM init:
+
    ldi R17, 0b00001001 ; WGM2:1 (Fast PWM), CS2..0:001 (internal clock, prescale=1)
-
;
+
    out TCCR0B, R17
-
; There are registers TCCR0A and TCCR0B for config, DDRD for output bit
+
    ldi R17, PWM_PULSES ; load number of clock pulses for 1 PWM period
-
; enabling, OCR0A for counter lenght and OCR0A for pulse "high" lenght.
+
    out OCR0A, R17   
-
; Register TIMSK0 controlls interrupts - not used, 0x00 by default  
+
   
-
 
+
    sbi DDRD, 5 ; PWM output OC0B (PD5 pin cislo 11)
-
PWM_INIT:
+
   
-
ldi R17, 0b00100011 ; Fast PWM Mode, out on OC0B, non Inverting
+
    ; Keyboard interrupt setup
-
out TCCR0A, R17 ;  
+
    ;
-
ldi R17, 0b00001001 ; WGM2:1 (Fast PWM), CS2..0:001 (internal clock, prescale=1)
+
    ; Activation of pin change interrupt - PROBLEM!!! PCICR and PCIMSK are  
-
out TCCR0B, R17
+
    ; extended I/O registers (0x68 and 0x6C), and must be handled as  
-
ldi R17, PWM_PULSES ; load number of clock pulses for 1 PWM period
+
    ; a memory location
-
out OCR0A, R17   
+
   
-
 
+
    ldi r26, PCICR ; load address of PCICR in Y low
-
sbi DDRD, 5 ; PWM output OC0B (PD5 pin cislo 11)
+
    clr r27 ; load high byte with 0
-
 
+
    ldi r16,0b00000010 ; activate PCINT1
-
 
+
    st X, r16 ; store new PCINT1
-
; Keyboard interrupt setup
+
   
-
;
+
    ldi r26, PCMSK1 ; load address of PCMSK1 in Y low
-
; Activation of pin change interrupt - PROBLEM!!! PCICR and PCIMSK are  
+
    clr r27 ; load high byte with 0
-
; extended I/O registers (0x68 and 0x6C), and must be handled as  
+
    ldi r16,0b00011100 ; allow pin change interrupt on portC bits 2,3,4
-
; a memory location
+
    st X, r16 ; store new PCMSK1
-
 
+
   
-
ldi r26, PCICR ; load address of PCICR in Y low
+
    sei ; Enable interrupts
-
clr r27 ; load high byte with 0
+
   
-
ldi r16,0b00000010 ; activate PCINT1
+
    ; Set sleep mode of the CPU
-
st X, r16 ; store new PCINT1
+
    ; SMCR: 0,0,0,0,SM2,SM1,SM0,SE  SM2..0: Sleep Mode Select Bits, SE: Sleep enabled)
-
 
+
   
-
ldi r26, PCMSK1 ; load address of PCMSK1 in Y low
+
    ldi r16,0b00000001 ; Idle mode  
-
clr r27 ; load high byte with 0
+
    out SMCR,r16 ; Sleep mode set
-
ldi r16,0b00011100 ; allow pin change interrupt on portC bits 2,3,4
+
   
-
st X, r16 ; store new PCMSK1
+
    ; Sleep loop, wake up by the Interrupt, return with RETI back to sleep loop
-
 
+
   
-
sei ; Enable interrupts
+
    loop:
-
 
+
    sleep ; now AVR sleeps
-
 
+
    nop ; return from Interrupt to this instruction
-
; Set sleep mode of the CPU
+
    rjmp loop ; and sleep again
-
; SMCR: 0,0,0,0,SM2,SM1,SM0,SE  SM2..0: Sleep Mode Select Bits, SE: Sleep enabled)
+
   
-
 
+
    ; PCINT0 Service Routine:
-
ldi r16,0b00000001 ; Idle mode  
+
    ;
-
out SMCR,r16 ; Sleep mode set
+
    ; To do: *** rpm reading, regulation, etc.
-
 
+
   
-
 
+
    isr1:
-
; Sleep loop, wake up by the Interrupt, return with RETI back to sleep loop
+
    mov R19, R17
-
 
+
    rcall KEYPRESS
-
loop:
+
    cpse R19, R16 ;pokud nejsou rovny, zmena cisla - muze jit o prechod 0 - non0
-
sleep ; now AVR sleeps
+
    rcall TEST_START
-
nop ; return from Interrupt to this instruction
+
   
-
rjmp loop ; and sleep again
+
    mov R17, R16
-
 
+
    lsl R17
-
 
+
    lsl R17 ;multiply key number by 4 for 10 steps in 40 clock pulses of PWM
-
; PCINT0 Service Routine:
+
    out OCR0B, R17 ;output pulse "high" lenght to PWM compare unit  
-
;
+
   
-
; To do: *** rpm reading, regulation, etc.
+
    reti ;return from Interrupt
-
 
+
   
-
 
+
    ;===============================
-
isr1:
+
    TEST_START:
-
mov R19, R17
+
    ldi R18, 0x0
-
rcall KEYPRESS
+
    cpse R18, R19 ; was the old length 0?
-
cpse R19, R16 ;pokud nejsou rovny, zmena cisla - muze jit o prechod 0 - non0
+
    rcall STARTING_PULSE ; if yes, run the starting pulse
-
rcall TEST_START
+
    ret
-
 
+
   
-
mov R17, R16
+
    STARTING_PULSE:
-
lsl R17
+
    sbi PORTD, 5
-
lsl R17 ;multiply key number by 4 for 10 steps in 40 clock pulses of PWM
+
    rcall WAIT
-
out OCR0B, R17 ;output pulse "high" lenght to PWM compare unit  
+
    cbi PORTD, 5
-
 
+
    ret
-
reti ;return from Interrupt
+
   
-
 
+
    WAIT:
-
;===============================
+
    LDI R18, 4 ; LDI - Load Immediate
-
TEST_START:
+
    WAIT1: INC R1
-
ldi R18, 0x0
+
    BRNE WAIT1
-
cpse R18, R19 ; was the old length 0?
+
    INC R2
-
rcall STARTING_PULSE ; if yes, run the starting pulse
+
    BRNE WAIT1
-
ret
+
    DEC R18
-
 
+
    BRNE WAIT1
-
STARTING_PULSE:
+
    RET
-
sbi PORTD, 5
+
    ;===============================
-
rcall WAIT
+
   
-
cbi PORTD, 5
+
    ; Keyboard decoding:
-
ret
+
   
-
 
+
    KEYPRESS:
-
WAIT:
+
   
-
LDI R18, 4 ; LDI - Load Immediate
+
    ; inicializace
-
WAIT1: INC R1
+
   
-
BRNE WAIT1
+
    cbi DDRD, 0 ; nastaveni vstupu na PORTD
-
INC R2
+
    cbi DDRD, 1
-
BRNE WAIT1
+
    cbi DDRD, 2
-
DEC R18
+
    cbi DDRD, 3
-
BRNE WAIT1
+
   
-
RET
+
    sbi PORTD, 0 ; nastaveni pull-up rezistoru na PORTD
-
;===============================
+
    sbi PORTD, 1
-
 
+
    sbi PORTD, 2
-
 
+
    sbi PORTD, 3
-
; Keyboard decoding:
+
   
-
 
+
    KEY0:
-
KEYPRESS:
+
    sbi DDRD, 3 ;nastaveni vystupu
-
 
+
    cbi PORTD, 3 ;log. 0 na radek  *, 0, #, D
-
; inicializace
+
   
-
 
+
    sbic PINC, 3
-
cbi DDRD, 0 ; nastaveni vstupu na PORTD
+
    rjmp KEY1
-
cbi DDRD, 1
+
    ldi R16, 0 ;pressed key 0
-
cbi DDRD, 2
+
    rjmp KEYRET
-
cbi DDRD, 3
+
   
-
 
+
    KEY1:
-
sbi PORTD, 0 ; nastaveni pull-up rezistoru na PORTD
+
    cbi DDRD, 3 ;obnoveni vstupu
-
sbi PORTD, 1
+
    sbi PORTD, 3 ;obnovení pull-up rezistoru
-
sbi PORTD, 2
+
   
-
sbi PORTD, 3
+
    sbi DDRD, 0 ;nastaveni vystupu
-
 
+
    cbi PORTD, 0 ;log. 0 na radek  *, 0, #, D
-
 
+
   
-
KEY0:
+
    sbic PINC, 2
-
sbi DDRD, 3 ;nastaveni vystupu
+
    rjmp KEY2
-
cbi PORTD, 3 ;log. 0 na radek  *, 0, #, D
+
    ldi R16, 1 ;pressed key 1
-
 
+
    rjmp KEYRET
-
sbic PINC, 3
+
    KEY2:
-
rjmp KEY1
+
    sbic PINC, 3
-
ldi R16, 0 ;pressed key 0
+
    rjmp KEY3
-
rjmp KEYRET
+
    ldi R16, 2
-
 
+
    rjmp KEYRET
-
 
+
    KEY3:
-
KEY1:
+
    sbic PINC, 4
-
cbi DDRD, 3 ;obnoveni vstupu
+
    rjmp KEY4
-
sbi PORTD, 3 ;obnovení pull-up rezistoru
+
    ldi R16, 3
-
 
+
    rjmp KEYRET
-
sbi DDRD, 0 ;nastaveni vystupu
+
   
-
cbi PORTD, 0 ;log. 0 na radek  *, 0, #, D
+
    KEY4:
-
 
+
    cbi DDRD, 0 ;obnoveni vstupu
-
 
+
    sbi PORTD, 0 ;obnovení pull-up rezistoru
-
sbic PINC, 2
+
   
-
rjmp KEY2
+
    sbi DDRD, 1 ;nastaveni vystupu
-
ldi R16, 1 ;pressed key 1
+
    cbi PORTD, 1 ;log. 0 na radek  *, 0, #, D
-
rjmp KEYRET
+
   
-
KEY2:
+
    sbic PINC, 2
-
sbic PINC, 3
+
    rjmp KEY5
-
rjmp KEY3
+
    ldi R16, 4 ;pressed key 4
-
ldi R16, 2
+
    rjmp KEYRET
-
rjmp KEYRET
+
    KEY5:
-
KEY3:
+
    sbic PINC, 3
-
sbic PINC, 4
+
    rjmp KEY6
-
rjmp KEY4
+
    ldi R16, 5
-
ldi R16, 3
+
    rjmp KEYRET
-
rjmp KEYRET
+
    KEY6:
-
 
+
    sbic PINC, 4
-
KEY4:
+
    rjmp KEY7
-
cbi DDRD, 0 ;obnoveni vstupu
+
    ldi R16, 6
-
sbi PORTD, 0 ;obnovení pull-up rezistoru
+
    rjmp KEYRET
-
 
+
   
-
sbi DDRD, 1 ;nastaveni vystupu
+
    KEY7:
-
cbi PORTD, 1 ;log. 0 na radek  *, 0, #, D
+
    cbi DDRD, 1 ;obnoveni vstupu
-
 
+
    sbi PORTD, 1 ;obnovení pull-up rezistoru
-
+
   
-
sbic PINC, 2
+
    sbi DDRD, 2 ;nastaveni vystupu
-
rjmp KEY5
+
    cbi PORTD, 2 ;log. 0 na radek  *, 0, #, D
-
ldi R16, 4 ;pressed key 4
+
   
-
rjmp KEYRET
+
    sbic PINC, 2
-
KEY5:
+
    rjmp KEY8
-
sbic PINC, 3
+
    ldi R16, 7 ;pressed key 7
-
rjmp KEY6
+
    rjmp KEYRET
-
ldi R16, 5
+
    KEY8:
-
rjmp KEYRET
+
    sbic PINC, 3
-
KEY6:
+
    rjmp KEY9
-
sbic PINC, 4
+
    ldi R16, 8
-
rjmp KEY7
+
    rjmp KEYRET
-
ldi R16, 6
+
    KEY9:
-
rjmp KEYRET
+
    sbic PINC, 4
-
 
+
    rjmp KEYRET
-
KEY7:
+
    ldi R16, 9
-
cbi DDRD, 1 ;obnoveni vstupu
+
   
-
sbi PORTD, 1 ;obnovení pull-up rezistoru
+
    KEYRET:
-
 
+
   
-
sbi DDRD, 2 ;nastaveni vystupu
+
    sbi DDRD, 0 ; nastaveni vystupu na PORTD
-
cbi PORTD, 2 ;log. 0 na radek  *, 0, #, D
+
    sbi DDRD, 1
-
 
+
    sbi DDRD, 2
-
+
    sbi DDRD, 3
-
sbic PINC, 2
+
   
-
rjmp KEY8
+
    cbi PORTD, 0 ; log. 0 on all rows for next key press catch
-
ldi R16, 7 ;pressed key 7
+
    cbi PORTD, 1
-
rjmp KEYRET
+
    cbi PORTD, 2
-
KEY8:
+
    cbi PORTD, 3
-
sbic PINC, 3
+
    ret
-
rjmp KEY9
+
-
ldi R16, 8
+
-
rjmp KEYRET
+
-
KEY9:
+
-
sbic PINC, 4
+
-
rjmp KEYRET
+
-
ldi R16, 9
+
-
 
+
-
 
+
-
KEYRET:
+
-
 
+
-
sbi DDRD, 0 ; nastaveni vystupu na PORTD
+
-
sbi DDRD, 1
+
-
sbi DDRD, 2
+
-
sbi DDRD, 3
+
-
 
+
-
cbi PORTD, 0 ; log. 0 on all rows for next key press catch
+
-
cbi PORTD, 1
+
-
cbi PORTD, 2
+
-
cbi PORTD, 3
+
-
ret
+
-
-------------------------------------------------------------------------------------
+
-
 
+
-
tyden 9.
+
-
 
+
-
;%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
-
;%%%%%%%%%%%%%JELINEK Martin, KOUBA Zdenek%%%%%%%%%%%%
+
-
;%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
-
;
+
-
 
+
-
 
+
-
 
+
-
.INCLUDE "m88def.inc" ; info pro prekladac
+
-
 
+
-
 
+
-
.ORG 0x0000 rjmp START ; Resetovaci vektor/skok na hl. program
+
-
 
+
-
 
+
-
;Main program start
+
-
START:
+
-
 
+
-
;%%%%NASTAVENI%%%%
+
-
 
+
-
;nastaveni IN/OUT ; PORTC ADC in!!!
+
-
SBI DDRC, 0 ; clk
 
-
SBI DDRC, 1 ; serial clk
 
-
SBI DDRC, 2 ; paralel clk
 
-
CBI DDRC, 4 ; change number input
 
-
LOOP:
+
==Domaci ukol 1==
-
VERYSMALLWAIT:
 
-
LDI R20, 0xFC
 
-
MOV R1, R20
 
-
SMALLWAIT:
 
-
INC R1
 
-
BRNE SMALLWAIT
 
 +
    ;%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 +
    ;%%%%%1. home work - JELINEK Martin, KOUBA Zdenek%%%%%
 +
    ;%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 +
    ;
 +
    ;po startu dojde k inicializaci HW
 +
    ;==nastaveni vstupu a vystupu
 +
    ;==vystupy vynulovany
 +
    ;==nastaveni PWM a AD prevodniku
 +
    ;==nastaveni a nasledne pouziti SLEEP MODu
 +
   
 +
    .INCLUDE "m88def.inc" ; info pro prekladac
 +
   
 +
    .EQU OSV_INT = 1 ; prirazeni pinu pro osvetleni interieru
 +
    .EQU DOOR_IN = 2 ; prirazeni pinu pro dverni kontakt
 +
   
 +
    .EQU OSV_PALUB = 5 ; prirazeni pinu pro osvetleni interieru (PD5)
 +
    .EQU AD_IN = 4 ; prirazeni pinu pro potenciometr
 +
   
 +
    .EQU STMIVANI = 100 ; pocet stmivacich kroku interniho osvetleni (0-255)
 +
    .EQU PWM_PULSES = 50 ; pocet pulzu osvetleni palubni desky za 1 periodu PWM
 +
   
 +
    .ORG 0x0000 rjmp START ; Resetovaci vektor/skok na hl. program
 +
   
 +
    .ORG 0x0008 rjmp PALUBKA ; vektor preruseni/skok na obsluhu nastaveni palubniho osvetleni
 +
   
 +
    ;Main program start
 +
    START:
 +
   
 +
    ;%%%%NASTAVENI%%%%
 +
   
 +
    ;nastaveni IN/OUT ; zvolit port podle pouziteho procesoru!!!!!!!!!!!!!!!!
 +
   
 +
    SBI DDRB, OSV_INT ; nastaveni vystupniho pinu pro osvetleni interieru
 +
    CBI DDRB, DOOR_IN ; nastaveni vstupniho pinu pro dverni kontakt
 +
   
 +
    SBI DDRD, OSV_PALUB ; nastaveni vystupniho pinu pro osvetleni interieru
 +
    CBI DDRB, AD_IN ; nastaveni vstupniho pinu pro potenciometr
 +
   
 +
    ; nastaveni SLEEP modu
 +
    ; SMCR: 0,0,0,0,SM2,SM1,SM0,SE  SM2..0: Sleep Mode Select Bits, SE: Sleep enabled)
 +
   
 +
    ldi r16,0b00000001 ; Idle mode
 +
    out SMCR,r16 ; Sleep mode set
 +
   
 +
    ;nastaveni A/D converteru
 +
    ldi R16,0b10001111 ; ADC enable (8.bit), enable interrupt (4.bit), prescaler 128
 +
    out ADCSRA,R16
 +
    ; vystup:
 +
    ; 2. a 1. bit ADCL (ADC9, ADC8)
 +
    ; 8. - 1. bit ADCH (ADC7 - ADC0)
 +
   
 +
    ;nastaveni hardwarove PWM
 +
   
 +
    PWM_PALUB_INIT: ; timer 0
 +
    ldi R17, 0x00 ; disable all interrupts
 +
    out TIMSK0, R17
 +
    ldi R17, 0b00100011 ; Fast PWM Mode, out on OC0B, non Inverting
 +
    out TCCR0A, R17 ;
 +
    ldi R17, 0b00001001 ; WGM2:1 (Fast PWM), CS2..0:001 (internal clock, prescale=1)
 +
    out TCCR0B, R17
 +
    ldi R17, PWM_PULSES ; load number of clock pulses for 1 PWM period
 +
    out OCR0A, R17 
 +
   
 +
    sbi DDRD, OSV_PALUB ; PWM output - pin pro osvetleni palubni desky
 +
   
 +
    ;-----------------------------------------------------------------------------
 +
    ;-----------------------------------------------------------------------------
 +
    ;==========ovladani osvetleni palubni desky potenciometrem
 +
    ;(popis funkce)
 +
    ;
 +
    ;AD prevod nastaven pravidelne
 +
    ;dokonceni AD prevodu vyvolava preruseni
 +
    ;v preruseni je cislo z AD prevodniku predano do PWM
 +
   
 +
    ;%%%%OBSLUHA_PRERUSENI%%%%
 +
   
 +
    PALUBKA:
 +
    MOV R20, ADCH
 +
    out OCR0B, R20 ; output pulse "high" lenght to PWM compare unit
 +
    reti ; return from Interrupt
 +
   
 +
    ;==========ovladani vnitrniho osvetleni dvernim kontaktem
 +
    ;(popis funkce)
 +
    ;
 +
    ;kontakt pripojen na pin (DOOR_IN)
 +
    ;zmena na pinu probudi mikrokontroler ze sleep modu
 +
    ;rozhodne se, zda se jedna o sepnuti 1), ci rozepnuti kontaktu 2)
 +
    ;1) nastaveni vystupu do log. 1
 +
    ;1) sleep mode
 +
    ;2) cekaci smycka 5 sec
 +
    ;2) softwarova klesajici PWM
 +
    ;2) sleep mode
 +
    ;-----------------------------------------------------------------------------
 +
    ;-----------------------------------------------------------------------------
 +
   
 +
    ;%%%%PROCEDURY%%%%
 +
   
 +
   
 +
    ; Sleep loop, wake up by the Interrupt, return with RETI back to sleep loop
 +
   
 +
    LOOP:
 +
    sleep ; prechod do sleep modu
 +
    nop ; return from Interrupt to this instruction
 +
    SBIC PINB, DOOR_IN ; je kontakt sepnut? NE-pokracuje ZHASINEJ1
 +
    rjmp TURN_ON ; skok na sepnuti svetla
 +
   
 +
   
 +
    ZHASINEJ1:
 +
    ldi R16, 0x0
 +
    cpse R16, R17 ; je R17 nula? NE-pokracuje CEKEJ5SEC
 +
    rjmp CEKEJ5SEC ; skok na CEKEJ5SEC
 +
    rjmp LOOP ; skok na LOOP, R17 bylo=0, je zhasnuto
 +
   
 +
    CEKEJ5SEC: ; cekaci smycka pred zapocetim stmivani
 +
    LDI R3, 20 ; doba je nastavovana cislem ukladanym do registru R3
 +
    WAIT1:
 +
    INC R1
 +
    BRNE WAIT1
 +
    INC R2
 +
    BRNE WAIT1
 +
    DEC R3
 +
    BRNE WAIT1
 +
   
 +
    LDI R17, STMIVANI ; ulozi pocet stmivacich kroku(=x) do R17=x´
 +
    LDI R19, STMIVANI ; R19=y
 +
   
 +
    ZHASINEJ2:
 +
    MOV R18, R17 ; R18=x´´
 +
    DEC R17
 +
    SUB R19, R17
 +
   
 +
    PWM_PIN_ON:
 +
    SBI PORTB, OSV_INT ; zapne interni svetlo
 +
   
 +
    WAIT2: INC R1 ; po zapnuti ceka
 +
    BRNE WAIT2
 +
    DEC R18
 +
    BRNE WAIT2
 +
   
 +
    PWM_PIN_OFF:
 +
    CBI PORTB, OSV_INT ; vypne interni svetlo
 +
   
 +
    WAIT3:
 +
    INC R1 ; po vypnuti ceka
 +
    BRNE WAIT3
 +
    DEC R19
 +
    BRNE WAIT3
 +
   
 +
    cpse R16, R17 ; je R17 nula? NE-pokracuje ZHASINEJ2:
 +
    rjmp ZHASINEJ2: ; skok na ZHASINEJ2:
 +
    rjmp LOOP ; skok na LOOP, R17 bylo=0, je zhasnuto definitivne
 +
   
 +
    TURN_ON:
 +
    SBI PORTB, OSV_INT ; zapne interni svetlo
 +
    rjmp LOOP ; skok na LOOP
 +
   
 +
   
 +
    TURN_OFF:
 +
    CBI PORTB, OSV_INT ; vypne interni svetlo
 +
    rjmp LOOP ; skok na LOOP
 +
   
 +
==tyden 9.==
-
SBIS PINC,4
+
    ;%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-
RJMP HODJEDNA
+
    ;%%%%%%%%%%%%%JELINEK Martin, KOUBA Zdenek%%%%%%%%%%%%
-
RJMP HODDVA
+
    ;%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 +
    ;
 +
   
 +
    .INCLUDE "m88def.inc" ; info pro prekladac
 +
   
 +
    .ORG 0x0000 rjmp START ; Resetovaci vektor/skok na hl. program
 +
   
 +
    ;Main program start
 +
    START:
 +
   
 +
    ;%%%%NASTAVENI%%%%
 +
   
 +
    ;nastaveni IN/OUT ; PORTC ADC in!!!
 +
   
 +
    SBI DDRC, 0 ; clk
 +
    SBI DDRC, 1 ; serial clk
 +
    SBI DDRC, 2 ; paralel clk
 +
    CBI DDRC, 4 ; change number input
 +
   
 +
    LOOP:
 +
   
 +
    VERYSMALLWAIT:
 +
    LDI R20, 0xFC
 +
    MOV R1, R20
 +
    SMALLWAIT:
 +
    INC R1
 +
    BRNE SMALLWAIT
 +
   
 +
    SBIS PINC,4
 +
    RJMP HODJEDNA
 +
    RJMP HODDVA
 +
   
 +
    HODJEDNA:
 +
    LDI R16,  0b11111010
 +
    RCALL REGISTR
 +
    RJMP LOOP
 +
   
 +
    HODDVA:
 +
    LDI R16,  0b01111001
 +
    RCALL REGISTR
 +
    RJMP LOOP
 +
   
 +
    ; RCALL REGISTR
 +
    ; by MARTIN JELINEK
 +
    ; v registru R16 ocekava cislo
 +
    ; ovlada PORTC
 +
    ; pro posuvny registr 74595
 +
    ; PIN9 - serial data input - PORTC 0
 +
    ; PIN10 - master reset (active LOW) - trvale pripojit na Vcc
 +
    ; PIN11 - shift registr clock input - PORTC 1
 +
    ; PIN12 - storage registr clock input - PORTC 2
 +
    ; PIN13 - output enable (active LOW) - trvale pripojit na GND
 +
   
 +
    REGISTR:
 +
    LDI R17, 128 ; pro osmibitove slovo (pro 7-bitove ulozit64)
 +
   
 +
    POSUN_DALSI:
 +
    CBI PORTC, 0 ; vynuluje vystup
 +
    SBRC R16, 0 ; otestuje 0 bit v R17
 +
    SBI PORTC, 0 ; vystup do 1
 +
    SBI PORTC, 1 ; hodiny na shift registr - vzestup hr.
 +
    ROR R16 ; rotace vpravo R16
 +
    CBI PORTC, 1 ; hodiny na shift registr - sestup hr.
 +
    SBRC R17, 0 ; neni posledni
 +
    RJMP POSUN_KONEC
 +
    ROR R17 ; rotace vpravo R17
 +
    RJMP POSUN_DALSI
 +
   
 +
    POSUN_KONEC:
 +
    SBI PORTC, 2 ; hodiny na storage registr - vzestup hr.
 +
    NOP
 +
    NOP
 +
    CBI PORTC, 2 ; hodiny na storage registr - sestup hr.
 +
    RET
-
HODJEDNA:
+
==tyden 11==
-
LDI R16,  0b11111010
+
-
RCALL REGISTR
+
-
RJMP LOOP
+
-
HODDVA:
 
-
LDI R16,  0b01111001
 
-
RCALL REGISTR
 
-
RJMP LOOP
 
 +
    .INCLUDE "C:\\Program Files\\Atmel\\AVR Tools\\AvrAssembler2\\Appnotes\\m88def.inc"     ;    info pro prekladac
 +
   
 +
   
 +
    .global shift_reg_led  ; deklarace funkce
 +
    shift_reg_led:        ; návìští, které musí být stejné, jako jméno funkce
 +
   
 +
    LDI R17, 128 ; pro osmibitove slovo (pro 7-bitove ulozit64)
 +
    POSUN_DALSI:
 +
    CBI PORTC, 0 ; vynuluje vystup
 +
    SBRC R16, 0 ; otestuje 0 bit v R17
 +
    SBI PORTC, 0 ; vystup do 1
 +
    SBI PORTC, 1 ; hodiny na shift registr - vzestup hr.
 +
    ROR R16 ; rotace vpravo R16
 +
    CBI PORTC, 1 ; hodiny na shift registr - sestup hr.
 +
    SBRC R17, 0 ; neni posledni
 +
    RJMP POSUN_KONEC
 +
    ROR R17 ; rotace vpravo R17
 +
    RJMP POSUN_DALSI
 +
   
 +
    POSUN_KONEC:
 +
    SBI PORTC, 2 ; hodiny na storage registr - vzestup hr.
 +
    NOP
 +
    NOP
 +
    CBI PORTC, 2 ; hodiny na storage registr - sestup hr.
 +
       
 +
    ret
 +
==Domací úkol 2==
 +
[[Soubor:HW2-Kouba.png|thumb]]
-
; RCALL REGISTR
+
<h3>Zadání</h3>
-
; by MARTIN JELINEK
+
<p>Studenti 1-10 mají RAM umístěnou v rozsahu adres 4000h až 5FFFh, EPROM 8000h až FFFFh, studenti 11-20 mají RAM umístěnou v rozsahu adres C000h až DFFFh, EPROM 4000h až BFFFh. Adresy I/O jsou uvedeny v tabulce na konci stránky. Pozor na kolizi paměti a I/O, pokud k ní dochází, je pro danou adresu třeba zakázat paměť, tj. místo buňky paměti je na dané adrese I/O obvod.</p>
-
; v registru R16 ocekava cislo
+
<p>Student 9: Konec volného prostoru nezabraného RAM a EPROM, každá periferie zabírá rozsah (zrcadlí se v rozsahu) 256 adres, INPUT na stejné adrese jako OUT1 (tj. zabráno celkem 512 adres)</p>
-
; ovlada PORTC
+
-
; pro posuvny registr 74595
+
-
; PIN9 - serial data input - PORTC 0
+
-
; PIN10 - master reset (active LOW) - trvale pripojit na Vcc
+
-
; PIN11 - shift registr clock input - PORTC 1
+
-
; PIN12 - storage registr clock input - PORTC 2
+
-
; PIN13 - output enable (active LOW) - trvale pripojit na GND
+
-
REGISTR:
+
<h3>Řešení</h3>
-
LDI R17, 128 ; pro osmibitove slovo (pro 7-bitove ulozit64)
+
<p>Pro realizaci logických součinů lze využít např. obvod CD74HCT21 (2 čtyřvstupová hradla AND) pro součit adresových signálů A5 - A11 a SN74LVC1G11 (trojvstupové hradlo AND) pro součin výstupů Y1, Y3 a Y7 členu U7.
 +
Pro invertování výstupního signálu Y2 členu U7 lze využít např. obvod HCT2G04.
 +
</p>
 +
<table>
 +
<tr>
 +
<td>EPROM</td>
 +
<td>0x8000</td>
 +
<td>0xFFFF</td>
 +
</tr>
 +
<tr>
 +
<td>OUT1 / INPUT  </td>
 +
<td>0x7F00</td>
 +
<td>0x7FFF</td>
 +
</tr>
 +
<tr>
 +
<td>OUT2</td>
 +
<td>0x7E00</td>
 +
<td>0x7EFF</td>
 +
</tr>
 +
<tr>
 +
<td>RAM</td>
 +
<td>0x4000</td>
 +
<td>0x5FFF</td>
 +
</tr>
 +
</table>
-
POSUN_DALSI:
+
==Semestralni prace - Ovladani ventilatoru teplovzdusneho rozvodu==
-
CBI PORTC, 0 ; vynuluje vystup
+
-
SBRC R16, 0 ; otestuje 0 bit v R17
+
-
SBI PORTC, 0 ; vystup do 1
+
-
SBI PORTC, 1 ; hodiny na shift registr - vzestup hr.
+
-
ROR R16 ; rotace vpravo R16
+
-
CBI PORTC, 1 ; hodiny na shift registr - sestup hr.
+
-
SBRC R17, 0 ; neni posledni
+
-
RJMP POSUN_KONEC
+
-
ROR R17 ; rotace vpravo R17
+
-
RJMP POSUN_DALSI
+
-
POSUN_KONEC:
+
Viz [[Jelínek Martin, Zdeněk Kouba: Ovládání ventilátoru teplovzdušného rozvodu]]
-
SBI PORTC, 2 ; hodiny na storage registr - vzestup hr.
+
-
NOP
+
-
NOP
+
-
CBI PORTC, 2 ; hodiny na storage registr - sestup hr.
+
-
RET
+
    ;%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 +
    ;%%%%%SEM. PRACE - JELINEK Martin, KOUBA Zdenek%%%%%
 +
    ;%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 +
    ;
 +
    ;po startu dojde k inicializaci HW
 +
    ;==nastaveni vstupu a vystupu
 +
    ;==vystupy vynulovany
 +
   
 +
   
 +
    ;==nastaveni COUNTERU1 a AD prevodniku
 +
    ;==nastaveni a nasledne pouziti SLEEP MODu
 +
   
 +
   
 +
    .INCLUDE "m88def.inc" ; info pro prekladac
 +
   
 +
    ;VSTUPY:
 +
    .EQU LOW_START = 1 ; prirazeni pinu pro tlacitko 1 (PB1 pin cislo 15)
 +
    .EQU HIGH_STOP = 2 ; prirazeni pinu pro tlacitko 2 (PB2 pin cislo 16)
 +
    .EQU ZERO_CR = 3 ; prirazeni pinu pro detekci nuly (PB3 pin cislo 17)
 +
    .EQU AD_IN = 0 ; prirazeni pinu pro termistor (PC0 pin cislo 23)
 +
   
 +
    ;VYSTUPY:
 +
    .EQU OUT = 5     ; prirazeni pinu pro optotriak (PD5 pin cislo 11)
 +
    .EQU LED_IND = 6 ; prirazeni pinu pro kontrolní LED (PD6 pin cislo 12)
 +
   
 +
    ;NASTAVENI TEPLOTY
 +
    .EQU TEMP_LOW = 128 ; nastavení komparacni hodnoty (0-255)
 +
    .EQU TEMP_HIGH = 192 ; nastavení komparacni hodnoty (0-255)
 +
   
 +
    ; HYSTEREZE
 +
    .EQU HYST = 10
 +
   
 +
    ;REGISTR PRO UCHOVANI A POROVNAVANI NASTAVENE TEPLOTY
 +
    .EQU TEMP_TRASH = R17
 +
   
 +
   
 +
   
 +
    .ORG 0x0000 rjmp START ; Resetovaci vektor/skok na hl. program
 +
   
 +
    .ORG 0x0005 rjmp TLACITKO ; vektor preruseni/skok na obsluhu tlacitek
 +
   
 +
    .ORG 0x000D rjmp COUNTER1 ; Timer/Counter1 overflow - vektor preruseni/skok na obsluhu preteceni counteru1
 +
   
 +
   
 +
   
 +
    ;Main program start
 +
    START:
 +
   
 +
   
 +
    ;nastaveni IN/OUT ; PORTC ADC in!!!
 +
    CBI DDRB, LOW_START ; nastaveni vstupniho pinu tlacitko 1 (PB1 pin cislo 15)
 +
    CBI DDRB, HIGH_STOP ; nastaveni vstupniho pinu pro pro tlacitko 2 (PB2 pin cislo 16)
 +
    SBI PORTB, LOW_START ; pull-up pro tlacitko 1
 +
    SBI PORTB, HIGH_STOP ; pull-up pro tlacitko 2
 +
    CBI DDRC, AD_IN ; nastaveni vstupniho pinu pro termistor (PC0 pin cislo 23)
 +
   
 +
    SBI DDRD, OUT ; nastaveni vystupniho pinu pro optotriak (PD5 pin cislo 11)
 +
    SBI DDRD, LED_IND ; nastaveni vystupniho pinu pro kontrolní LED (PD6 pin cislo 12)
 +
    SBI DDRB, ZERO_CR ; nastaveni docasne-vystupniho pinu pro detekci nuly (PB3 pin cislo 17)-aby nedelal preruseni
 +
   
 +
   
 +
   
 +
    ;nastaveni SLEEP modu
 +
    ;SMCR: 0,0,0,0,SM2,SM1,SM0,SE  SM2..0: Sleep Mode Select Bits, SE: Sleep enabled)
 +
   
 +
    ldi r16,0b00000001 ; Idle mode
 +
    out SMCR,r16 ; Sleep mode set
 +
   
 +
   
 +
    ;nastaveni A/D converteru
 +
    ldi R16,0b10000111 ; ADC enable (7.bit), permit (enable interrupt (3.bit)), prescaler 128
 +
    out ADCSRA,R16
 +
   
 +
    ldi R16,0b11100000 ; Internal 1.1V voltage reference with external capacitor at AREF pin (7.,6.bit), ADLAR (5.bit), input PORTC 0 (low 4 bit)
 +
    out ADMUX,R16
 +
   
 +
    ; vystup:  pro ADLAR=1
 +
    ; 7. a 6. bit ADCL (ADC1 - ADC0)
 +
        ; 7. - 0. bit ADCH (ADC9 - ADC2)
 +
   
 +
   
 +
    ;nastaveni counteru1
 +
    ; 16bit, prescaler 256 - preruseni kazdych 17,8 sec
 +
   
 +
    ;TCCR1A: COM1A1 COM1A0 COM1B1 COM1B0 0 0 WGM11 WGM10
 +
      ; 0 0      0      0      0 0 0    0 ... normal mode
 +
    ldi R16, 0x00
 +
    out TCCR1A, R16
 +
   
 +
    ;TCCR1B: ICNC1 ICES1 0 WGM13 WGM12 CS12 CS11 CS10
 +
    ; 0    0    0 0    0    1    0    0 ... Clock select - clk_IO/256
 +
    ldi R16, 0b00000100
 +
    out TCCR1B, R16
 +
   
 +
        ;TIMSK1: 0 0 ICIE1 0 0 OCIE1B OCIE1A TOIE1
 +
        ; 0 0 1    0 0 0      0      1 ... interrupt on overflow
 +
    ldi R16, 0b00100001
 +
    out TIMSK1, R16
 +
   
 +
   
 +
    ;inicializace registru temperature-treshhold
 +
    ldi TEMP_TRASH, TEMP_LOW
 +
   
 +
    ;-----------------------------------------------------------------------------
 +
    ;-----------------------------------------------------------------------------
 +
   
 +
    ;%%%%PROCEDURY%%%%
 +
   
 +
   
 +
    ;Sleep loop, wake up by the Interrupt, return with RETI back to sleep loop
 +
   
 +
    LOOP:
 +
    SLEEP ; prechod do sleep modu
 +
    nop ; return from Interrupt to this instruction
 +
    RJMP LOOP ; skok na LOOP
 +
   
 +
   
 +
   
 +
    ;-----------------------------------------------------------------------------
 +
    ;-----------------------------------------------------------------------------
 +
   
 +
    ;%%%%OBSLUHA_PRERUSENI%%%%
 +
   
 +
    TLACITKO:
 +
    ; do registru se ulozi hodnota low nebo high podle stisku tlacitka
 +
   
 +
    sbic PINB, LOW_START
 +
    ldi TEMP_TRASH, TEMP_LOW
 +
   
 +
    sbic PINB, HIGH_START
 +
    ldi TEMP_TRASH, TEMP_HIGH
 +
   
 +
    reti ; return from Interrupt
 +
   
 +
   
 +
   
 +
    COUNTER1:
 +
    ;zakaze se preruseni od tlacitek
 +
    ldi R16, 0x00
 +
    out PCICR, R16
 +
   
 +
        ; porovna se hodnota z AD prevodniku (ADCH)
 +
    cp TEMP_TRASH, ADCH
 +
    brge TEMP_LESS_TRASH ; je mene - odchod, vypnuti vystupu
 +
    brlt TEMP_MORE_TRaSH ; je vice - detekce nuly, pak zapnuti vystupu
 +
   
 +
    TEMP_LESS_TRASH:
 +
        sbis    PIND, OUT
 +
        rjmp    EXIT    ; pokud jiz vystup byl vypnuty, rovnou odchod
 +
        ldi    R18, HYST
 +
        add    TEMP_TRASH, R18
 +
    cbi PORTD, OUT
 +
    CBI PORTD, LED_IND ; LED_OFF
 +
    rjmp EXIT
 +
   
 +
    TEMP_MORE_TRASH:
 +
        sbic    PIND, OUT
 +
        rjmp    EXIT    ; pokud jiz vystup byl zapnuty, rovnou na odchod
 +
        subi    TEMP_TRASH, HYST
 +
    CBI DDRB, ZERO_CR ; nastaví pin (PB3 cislo 17) jako vstup
 +
    SBI PORTD, LED_IND ; LED_ON
 +
   
 +
    ZERO:
 +
    SBIS DDRB, ZERO_CR ; detekce kladne pulvlny
 +
    rjmp ZERO
 +
   
 +
    NO_ZERO:
 +
    SBIC DDRB, ZERO_CR ; detekce nuly
 +
    rjmp NO_ZERO
 +
    SBI PORTD, OUT
 +
    SBI DDRB, ZERO_CR ; nastaví jako vystup - nedela preruseni
 +
    rjmp EXIT
 +
   
 +
    EXIT: ; odchod: povoleni preruseni
 +
    ldi R16, 0x01
 +
    out PCICR, R16
 +
    reti ; return from Interrupt

Aktuální verze z 13. 5. 2013, 15:17

Prosím zformátujte. Horčík

Obsah

[editovat] tyden 4.

   .EQU DDRB = $17		; DDRB address
   .EQU PORTB = $18	; PORTB address
   .EQU PINB = $16		; P
   
   .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):
   ; pro led
   SBI	DDRB, LED_X	; SBI - Set Bit in I/O Register
   SBI	DDRB, LED_Y
   
   SHOW:	
   
   ;pro klavesnici
   SBI DDRB, 7  ; output pin 19
   SBI PORTB, 2 ; enables pull-up rezistor on pin 14
   
   GO:
   RCALL   COLOR1
   RCALL	WAIT
   SBIS	PINB, 2	; skip if bit is set
   RCALL	COLOR2
   RCALL	WAIT
   RJMP	GO
   	
   RJMP SHOW		; RJMP - Relative Jump 
   
   ;;;
   ;;;
   ;;; 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, 1			; LDI nastaveni casu
   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


[editovat] tyden 5.

   ; 
   ; 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 "m88def.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
   
   LDI		R17, 0b00001111	; pripravi hodnotu k presunu
   OUT 	DDRD, R17 		; D0-3, piny 2-5 nastavi vystupy
   OUT 	PORTC, R17		; C0-3, piny 23-26 pull up rez
   
   
   ; Init:
   RCALL   FAN_OFF
   
   ;GO:	SBIS	PINC, 2
   ;	RCALL	FAN3W   ; Simple PWM control of the FAN, if the key is pressed
   ;	RJMP	GO
   
   LDI		R16, 0x02 	; konstanta pro pwm
   
   
   
   PWM:	; nastaveni pwm
   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
   RJMP	PWM
   
   
   ;;;
   ;;;
   ;;; 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
   
   
   ; obsluha preruseni
   
   
   ; obsluha CTENI KLAVESNICE PRI preruseni
   
   KEYPRESS:
   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	
   KEY1:
   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
   
   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	KEYRET
   LDI	R16, 0		;pressed key 0
   
   KEYRET:
   RET

[editovat] tyden 6

   ; example fan program for ATmega88 with Timer controlled PWM&Interrupt&Sleep
   ;
   ; Rotation speed  is controlled by keyboard, 
   ; keys 0-9 represent the speed between 0 and 100 %
   ;
   ; Fan starts to rotate with the first valid key press
   ;
   ; To do: *** Catch only the key press, not key release
   ;
   ; To do: *** Set higher value of PWM (=higher fan rpm) for 
   ; a few first periods to start the fan reliably
   ;
   ;
   ; P4 CPU fan Ucc pin is supposed to be connected 
   ; to +15 V, GND pin is supposed to be connected 
   ; to NMOS Drain,, Source on GND, Gate on 
   ; pin 11 (OC0B, PD5). Fan runs when pin 11 is high.
   
   .INCLUDE "m88def.inc"
   
   .EQU PWM_PULSES = 36	; value for 27.8 kHz PWM/maximalni hodnota pro PWM counter
   ;.EQU PWM_PULSES = 45	; value for 22.2 kHz PWM
   
   .ORG 0x0000 
   rjmp Main ; Resetovaci vektor/skok na hl. program
   
   .ORG 0x0008 
   rjmp isr1 ; PCINT1 Handler/skok na obsluhu preruseni
   
   ; Main program start
   
   Main: 
   ; Stack pointer init:
   ldi r16,high(RAMEND); Main program start
   out SPH,r16 ; Set Stack Pointer to top of RAM
   ldi r16,low(RAMEND)
   out SPL,r16
   
   ; Hardware initialization
   
   ; Keyboard init:
   
   ; !!!!!zapojeni!!!!
   ; col1	col3	row1	row3
   ; col2	col4	row2	row4
   ;		!!!kabel!!!
   
   ; vstup z klávesnice = sloupce 1-3
   cbi DDRC, 2	; 25
   cbi DDRC, 3	; 26
   cbi DDRC, 4	; 27
   
   ; set internal Pull-Ups for keyboard
   sbi PORTC, 2
   sbi PORTC, 3
   sbi PORTC, 4
   
   ; set driving outputs for keyboard (ROW1-ROW4)
   sbi DDRD, 0 ; 2
   sbi DDRD, 1 ; 3
   sbi DDRD, 2 ; 4
   sbi DDRD, 3 ; 5
   
   cbi PORTD, 0	; log. 0 on all rows
   cbi PORTD, 1
   cbi PORTD, 2
   cbi PORTD, 3
   
   ; Timer controlled PWM init:
   ;
   ; There are registers TCCR0A and TCCR0B for config, DDRD for output bit
   ; enabling, OCR0A for counter lenght and OCR0A for pulse "high" lenght.
   ; Register TIMSK0 controlls interrupts - not used, 0x00 by default 
   
   PWM_INIT:
   ldi R17, 0b00100011	; Fast PWM Mode, out on OC0B, non Inverting
   out TCCR0A, R17			; 
   ldi R17, 0b00001001	; WGM2:1 (Fast PWM), CS2..0:001 (internal clock, prescale=1)
   out TCCR0B, R17
   ldi R17, PWM_PULSES	; load number of clock pulses for 1 PWM period
   out OCR0A, R17   
   
   sbi DDRD, 5	; PWM output OC0B (PD5 pin cislo 11)
   
   ; Keyboard interrupt setup
   ;
   ; Activation of pin change interrupt - PROBLEM!!! PCICR and PCIMSK are 
   ; extended I/O registers (0x68 and 0x6C), and must be handled as 
   ; a memory location
   
   ldi r26, PCICR ; load address of PCICR in Y low
   clr r27 ; load high byte with 0
   ldi r16,0b00000010 ; activate PCINT1
   st X, r16 ; store new PCINT1
   
   ldi r26, PCMSK1 ; load address of PCMSK1 in Y low
   clr r27 ; load high byte with 0
   ldi r16,0b00011100 ; allow pin change interrupt on portC bits 2,3,4
   st X, r16 ; store new PCMSK1
   
   sei ; Enable interrupts
   
   ; Set sleep mode of the CPU
   ; SMCR: 0,0,0,0,SM2,SM1,SM0,SE   SM2..0: Sleep Mode Select Bits, SE: Sleep enabled)
   
   ldi r16,0b00000001 ; Idle mode 
   out SMCR,r16 ; Sleep mode set
   
   ; 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

[editovat] Tyden 7

Ovladani vetraku, osetreni stisku 2 tlacitek na klavesnici, rozbeh z 0

   -----------------------------------------------------------------------
   
   ;===================================================
   ;======= by Jelinek Martin and Kouba Zdenek=========
   ;===================================================
   ;
   ; fan(ny) program for ATmega88 with Timer controlled PWM&Interrupt&Sleep
   ;
   ; Rotation speed  is controlled by keyboard, 
   ; keys 0-9 represent the speed between 0 and 100 %
   ;
   ; Fan starts to rotate with the first valid key press
   ;
   ; To do: *** Catch only the key press, not key release
   ;
   ; To do: *** Set higher value of PWM (=higher fan rpm) for 
   ; a few first periods to start the fan reliably
   ;
   ;
   ; P4 CPU fan Ucc pin is supposed to be connected 
   ; to +15 V, GND pin is supposed to be connected 
   ; to NMOS Drain,, Source on GND, Gate on 
   ; pin 11 (OC0B, PD5). Fan runs when pin 11 is high.
   
   .INCLUDE "m88def.inc"
   
   .EQU PWM_PULSES = 36		; value for 27.8 kHz PWM/maximalni hodnota pro PWM counter/podle pouziteho vetraku
   ;.EQU PWM_PULSES = 45		; value for 22.2 kHz PWM
   
   .ORG 0x0000 
   rjmp Main 		; Resetovaci vektor/skok na hl. program
   
   .ORG 0x0008 
   rjmp isr1 		; PCINT1 Handler/skok na obsluhu preruseni
   
   ; Main program start
   
   Main: 
   
   ; Stack pointer init:
   ldi r16,high(RAMEND)	; Main program start
   out SPH,r16 		; Set Stack Pointer to top of RAM
   ldi r16,low(RAMEND)
   out SPL,r16
   
   ; Hardware initialization
   
   ldi r19, 0		;reg R19 je pouzit v rutine pro rozbehovy puls
   
   ; Keyboard init:
   
   ; !!!!!zapojeni!!!!
   ; col1	col3	row1	row3
   ; col2	col4	row2	row4
   ;		!!!kabel!!!
   
   ; vstup z klávesnice = sloupce 1-3
   cbi DDRC, 2		; 25
   cbi DDRC, 3		; 26
   cbi DDRC, 4		; 27
   
   ; set internal Pull-Ups for keyboard
   sbi PORTC, 2
   sbi PORTC, 3
   sbi PORTC, 4
   
   ; set driving outputs for keyboard (ROW1-ROW4)
   sbi DDRD, 0		; 2
   sbi DDRD, 1 		; 3
   sbi DDRD, 2 		; 4
   sbi DDRD, 3 		; 5
   
   cbi PORTD, 0		; log. 0 on all rows
   cbi PORTD, 1
   cbi PORTD, 2
   cbi PORTD, 3
   
   ; Timer controlled PWM init:
   ;
   ; There are registers TCCR0A and TCCR0B for config, DDRD for output bit
   ; enabling, OCR0A for counter lenght and OCR0A for pulse "high" lenght.
   ; Register TIMSK0 controlls interrupts - not used, 0x00 by default 
   
   PWM_INIT:
   ldi R17, 0b00100011	; Fast PWM Mode, out on OC0B, non Inverting
   out TCCR0A, R17			; 
   ldi R17, 0b00001001	; WGM2:1 (Fast PWM), CS2..0:001 (internal clock, prescale=1)
   out TCCR0B, R17
   ldi R17, PWM_PULSES	; load number of clock pulses for 1 PWM period
   out OCR0A, R17   
   
   sbi DDRD, 5		; PWM output OC0B (PD5 pin cislo 11)
   
   ; Keyboard interrupt setup
   ;
   ; Activation of pin change interrupt - PROBLEM!!! PCICR and PCIMSK are 
   ; extended I/O registers (0x68 and 0x6C), and must be handled as 
   ; a memory location
   
   ldi r26, PCICR 		; load address of PCICR in Y low
   clr r27 		; load high byte with 0
   ldi r16,0b00000010 	; activate PCINT1
   st X, r16 		; store new PCINT1
   
   ldi r26, PCMSK1 	; load address of PCMSK1 in Y low
   clr r27 		; load high byte with 0
   ldi r16,0b00011100 	; allow pin change interrupt on portC bits 2,3,4
   st X, r16 		; store new PCMSK1
   
   sei 			; Enable interrupts
   
   ; Set sleep mode of the CPU
   ; SMCR: 0,0,0,0,SM2,SM1,SM0,SE   SM2..0: Sleep Mode Select Bits, SE: Sleep enabled)
   
   ldi r16,0b00000001 	; Idle mode 
   out SMCR,r16 		; Sleep mode set
   
   ; 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:
   mov R19, R17
   rcall KEYPRESS
   cpse R19, R16		;pokud nejsou rovny, zmena cisla - muze jit o prechod 0 - non0
   rcall TEST_START	
   
   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
   
   ;===============================
   TEST_START:
   ldi R18, 0x0
   cpse R18, R19 		; was the old length 0?
   rcall STARTING_PULSE 	; if yes, run the starting pulse
   ret
   
   STARTING_PULSE:
   sbi PORTD, 5
   rcall WAIT
   cbi PORTD, 5
   ret
   
   WAIT:
   LDI R18, 4 		; LDI - Load Immediate
   WAIT1: 	INC R1
   BRNE WAIT1
   INC R2
   BRNE WAIT1
   DEC R18
   BRNE WAIT1
   RET
   ;===============================
   
   ; Keyboard decoding:
   
   KEYPRESS:
   
   ; inicializace
   
   cbi 	DDRD, 0		; nastaveni vstupu na PORTD
   cbi 	DDRD, 1
   cbi 	DDRD, 2
   cbi 	DDRD, 3
   
   sbi 	PORTD, 0	; nastaveni pull-up rezistoru na PORTD
   sbi 	PORTD, 1
   sbi 	PORTD, 2
   sbi 	PORTD, 3
   
   KEY0:
   sbi 	DDRD, 3		;nastaveni vystupu
   cbi 	PORTD, 3	;log. 0 na radek  *, 0, #, D	
   
   sbic	PINC, 3
   rjmp	KEY1
   ldi	R16, 0		;pressed key 0
   rjmp	KEYRET
   
   KEY1:
   cbi 	DDRD, 3		;obnoveni vstupu
   sbi 	PORTD, 3	;obnovení pull-up rezistoru	
   
   sbi 	DDRD, 0		;nastaveni vystupu
   cbi 	PORTD, 0	;log. 0 na radek  *, 0, #, D	
   
   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:
   cbi 	DDRD, 0		;obnoveni vstupu
   sbi 	PORTD, 0	;obnovení pull-up rezistoru	
   
   sbi 	DDRD, 1		;nastaveni vystupu
   cbi 	PORTD, 1	;log. 0 na radek  *, 0, #, D	
   
   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:
   cbi 	DDRD, 1		;obnoveni vstupu
   sbi 	PORTD, 1	;obnovení pull-up rezistoru	
   
   sbi 	DDRD, 2		;nastaveni vystupu
   cbi 	PORTD, 2	;log. 0 na radek  *, 0, #, D	
   
   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:
   
   sbi 	DDRD, 0		; nastaveni vystupu na PORTD
   sbi 	DDRD, 1
   sbi 	DDRD, 2
   sbi 	DDRD, 3
   
   cbi PORTD, 0		; log. 0 on all rows for next key press catch
   cbi PORTD, 1
   cbi PORTD, 2
   cbi PORTD, 3
   ret


[editovat] Domaci ukol 1

   ;%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
   ;%%%%%1. home work - JELINEK Martin, KOUBA Zdenek%%%%%
   ;%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
   ;
   ;po startu dojde k inicializaci HW
   ;==nastaveni vstupu a vystupu
   ;==vystupy vynulovany
   ;==nastaveni PWM a AD prevodniku
   ;==nastaveni a nasledne pouziti SLEEP MODu
   
   .INCLUDE "m88def.inc"		; info pro prekladac
   
   .EQU OSV_INT = 1		; prirazeni pinu pro osvetleni interieru
   .EQU DOOR_IN = 2		; prirazeni pinu pro dverni kontakt
   
   .EQU OSV_PALUB = 5		; prirazeni pinu pro osvetleni interieru (PD5)
   .EQU AD_IN = 4			; prirazeni pinu pro potenciometr
   
   .EQU STMIVANI = 100		; pocet stmivacich kroku interniho osvetleni (0-255)
   .EQU PWM_PULSES = 50	; pocet pulzu osvetleni palubni desky za 1 periodu PWM
   
   .ORG 0x0000 rjmp START		; Resetovaci vektor/skok na hl. program 
   
   .ORG 0x0008 rjmp PALUBKA	; vektor preruseni/skok na obsluhu nastaveni palubniho osvetleni
   
   ;Main program start 
   START: 
   
   ;%%%%NASTAVENI%%%%
   
   ;nastaveni IN/OUT		; zvolit port podle pouziteho procesoru!!!!!!!!!!!!!!!!
   
   SBI	DDRB, OSV_INT	; nastaveni vystupniho pinu pro osvetleni interieru
   CBI	DDRB, DOOR_IN	; nastaveni vstupniho pinu pro dverni kontakt
   
   SBI	DDRD, OSV_PALUB	; nastaveni vystupniho pinu pro osvetleni interieru
   CBI	DDRB, AD_IN	; nastaveni vstupniho pinu pro potenciometr
   
   ; nastaveni SLEEP modu
   ; SMCR: 0,0,0,0,SM2,SM1,SM0,SE   SM2..0: Sleep Mode Select Bits, SE: Sleep enabled)
   
   ldi r16,0b00000001 	; Idle mode 
   out SMCR,r16 		; Sleep mode set
   
   ;nastaveni A/D converteru
   ldi R16,0b10001111 ; ADC enable (8.bit), enable interrupt (4.bit), prescaler 128
   out ADCSRA,R16
   ; vystup: 
   ;		2. a 1. bit ADCL (ADC9, ADC8)
   ;		8. - 1. bit ADCH (ADC7 - ADC0)
   
   ;nastaveni hardwarove PWM
   
   PWM_PALUB_INIT: ; timer 0
   ldi R17, 0x00 ; disable all interrupts
   out TIMSK0, R17
   ldi R17, 0b00100011	; Fast PWM Mode, out on OC0B, non Inverting
   out TCCR0A, R17			; 
   ldi R17, 0b00001001	; WGM2:1 (Fast PWM), CS2..0:001 (internal clock, prescale=1)
   out TCCR0B, R17
   ldi R17, PWM_PULSES	; load number of clock pulses for 1 PWM period
   out OCR0A, R17   
   
   sbi DDRD, OSV_PALUB	; PWM output - pin pro osvetleni palubni desky
   
   ;-----------------------------------------------------------------------------
   ;-----------------------------------------------------------------------------
   ;==========ovladani osvetleni palubni desky potenciometrem
   ;(popis funkce)
   ;
   ;AD prevod nastaven pravidelne
   ;dokonceni AD prevodu vyvolava preruseni
   ;v preruseni je cislo z AD prevodniku predano do PWM
   
   ;%%%%OBSLUHA_PRERUSENI%%%%
   
   PALUBKA: 
   MOV	R20, ADCH
   out	OCR0B, R20	; output pulse "high" lenght to PWM compare unit
   reti	 ; return from Interrupt
   
   ;==========ovladani vnitrniho osvetleni dvernim kontaktem
   ;(popis funkce)
   ;
   ;kontakt pripojen na pin (DOOR_IN)
   ;zmena na pinu probudi mikrokontroler ze sleep modu
   ;rozhodne se, zda se jedna o sepnuti 1), ci rozepnuti kontaktu 2)
   ;1) nastaveni vystupu do log. 1
   ;1) sleep mode
   ;2) cekaci smycka 5 sec
   ;2) softwarova klesajici PWM
   ;2) sleep mode
   ;-----------------------------------------------------------------------------
   ;-----------------------------------------------------------------------------
   
   ;%%%%PROCEDURY%%%%
   
   
   ; Sleep loop, wake up by the Interrupt, return with RETI back to sleep loop
   
   LOOP:
   sleep 			; prechod do sleep modu
   nop 			; return from Interrupt to this instruction
   SBIC PINB, DOOR_IN	; je kontakt sepnut? NE-pokracuje ZHASINEJ1
   rjmp TURN_ON		; skok na sepnuti svetla
   
   
   ZHASINEJ1:
   ldi R16, 0x0
   cpse R16, R17 		; je R17 nula? NE-pokracuje CEKEJ5SEC
   rjmp CEKEJ5SEC		; skok na CEKEJ5SEC
   rjmp LOOP		; skok na LOOP, R17 bylo=0, je zhasnuto
   
   CEKEJ5SEC:			; cekaci smycka pred zapocetim stmivani
   LDI R3, 20 		; doba je nastavovana cislem ukladanym do registru R3
   WAIT1: 
   INC R1
   BRNE WAIT1
   INC R2
   BRNE WAIT1
   DEC R3
   BRNE WAIT1
   
   LDI R17, STMIVANI	; ulozi pocet stmivacich kroku(=x) do R17=x´
   LDI R19, STMIVANI	; R19=y
   
   ZHASINEJ2:
   MOV R18, R17		; R18=x´´
   DEC R17
   SUB R19, R17
   
   PWM_PIN_ON:
   SBI PORTB, OSV_INT	; zapne interni svetlo
   
   WAIT2: 	INC R1			; po zapnuti ceka
   BRNE WAIT2
   DEC R18
   BRNE WAIT2
   
   PWM_PIN_OFF:
   CBI PORTB, OSV_INT	; vypne interni svetlo
   
   WAIT3: 
   INC R1			; po vypnuti ceka
   BRNE WAIT3
   DEC R19
   BRNE WAIT3
   
   cpse R16, R17 		; je R17 nula? NE-pokracuje ZHASINEJ2:
   rjmp ZHASINEJ2:		; skok na ZHASINEJ2:
   rjmp LOOP		; skok na LOOP, R17 bylo=0, je zhasnuto definitivne
   
   TURN_ON:
   SBI PORTB, OSV_INT	; zapne interni svetlo
   rjmp LOOP		; skok na LOOP
   
   
   TURN_OFF:
   CBI PORTB, OSV_INT	; vypne interni svetlo
   rjmp LOOP		; skok na LOOP
   


[editovat] tyden 9.

   ;%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
   ;%%%%%%%%%%%%%JELINEK Martin, KOUBA Zdenek%%%%%%%%%%%%
   ;%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
   ;
   
   .INCLUDE "m88def.inc"		; info pro prekladac
   
   .ORG 0x0000	rjmp START	; Resetovaci vektor/skok na hl. program 
   
   ;Main program start 
   START: 
   
   ;%%%%NASTAVENI%%%%
   
   ;nastaveni IN/OUT		; PORTC ADC in!!!
   
   SBI	DDRC, 0	; clk
   SBI	DDRC, 1	; serial clk
   SBI	DDRC, 2	; paralel clk
   CBI	DDRC, 4	; change number input
   
   LOOP:
   
   VERYSMALLWAIT:
   LDI R20, 0xFC
   MOV R1, R20
   SMALLWAIT:
   INC	R1
   BRNE	SMALLWAIT
   
   SBIS	PINC,4
   RJMP	HODJEDNA
   RJMP	HODDVA
   
   HODJEDNA:
   LDI R16,  0b11111010 
   RCALL REGISTR 
   RJMP	LOOP
   
   HODDVA:
   LDI R16,  0b01111001
   RCALL REGISTR
   RJMP	LOOP
   
   ;	RCALL REGISTR
   ; by MARTIN JELINEK
   ; v registru R16 ocekava cislo
   ; ovlada PORTC
   ; pro posuvny registr 74595
   ; PIN9 - serial data input - PORTC 0
   ; PIN10 - master reset (active LOW) - trvale pripojit na Vcc
   ; PIN11 - shift registr clock input - PORTC 1
   ; PIN12 - storage registr clock input - PORTC 2
   ; PIN13 - output enable (active LOW) - trvale pripojit na GND
   
   REGISTR:
   LDI R17, 128 		; pro osmibitove slovo (pro 7-bitove ulozit64)
   
   POSUN_DALSI:
   CBI PORTC, 0		; vynuluje vystup
   SBRC R16, 0			; otestuje 0 bit v R17
   SBI PORTC, 0		; vystup do 1
   SBI PORTC, 1		; hodiny na shift registr - vzestup hr.
   ROR R16				; rotace vpravo R16
   CBI PORTC, 1		; hodiny na shift registr - sestup hr.
   SBRC R17, 0			; neni posledni
   RJMP POSUN_KONEC
   ROR R17				; rotace vpravo R17
   RJMP POSUN_DALSI
   
   POSUN_KONEC:
   SBI PORTC, 2		; hodiny na storage registr - vzestup hr.
   NOP
   NOP
   CBI PORTC, 2		; hodiny na storage registr - sestup hr.
   RET

[editovat] tyden 11

   .INCLUDE "C:\\Program Files\\Atmel\\AVR Tools\\AvrAssembler2\\Appnotes\\m88def.inc"		    ;     info pro prekladac
   
   
   .global shift_reg_led  ; deklarace funkce
   shift_reg_led:         ; návìští, které musí být stejné, jako jméno funkce
   
   	LDI R17, 128 		; pro osmibitove slovo (pro 7-bitove ulozit64)
   POSUN_DALSI:
   	CBI PORTC, 0		; vynuluje vystup
   	SBRC R16, 0			; otestuje 0 bit v R17
   	SBI PORTC, 0		; vystup do 1
   	SBI PORTC, 1		; hodiny na shift registr - vzestup hr.
   	ROR R16				; rotace vpravo R16
   	CBI PORTC, 1		; hodiny na shift registr - sestup hr.
   	SBRC R17, 0			; neni posledni
   	RJMP POSUN_KONEC
   	ROR R17				; rotace vpravo R17
   	RJMP POSUN_DALSI
   
   POSUN_KONEC:
   	SBI PORTC, 2		; hodiny na storage registr - vzestup hr.
   	NOP
   	NOP
   	CBI PORTC, 2		; hodiny na storage registr - sestup hr.
       
   	ret

[editovat] Domací úkol 2

Zadání

Studenti 1-10 mají RAM umístěnou v rozsahu adres 4000h až 5FFFh, EPROM 8000h až FFFFh, studenti 11-20 mají RAM umístěnou v rozsahu adres C000h až DFFFh, EPROM 4000h až BFFFh. Adresy I/O jsou uvedeny v tabulce na konci stránky. Pozor na kolizi paměti a I/O, pokud k ní dochází, je pro danou adresu třeba zakázat paměť, tj. místo buňky paměti je na dané adrese I/O obvod.

Student 9: Konec volného prostoru nezabraného RAM a EPROM, každá periferie zabírá rozsah (zrcadlí se v rozsahu) 256 adres, INPUT na stejné adrese jako OUT1 (tj. zabráno celkem 512 adres)

Řešení

Pro realizaci logických součinů lze využít např. obvod CD74HCT21 (2 čtyřvstupová hradla AND) pro součit adresových signálů A5 - A11 a SN74LVC1G11 (trojvstupové hradlo AND) pro součin výstupů Y1, Y3 a Y7 členu U7. Pro invertování výstupního signálu Y2 členu U7 lze využít např. obvod HCT2G04.

EPROM 0x8000 0xFFFF
OUT1 / INPUT 0x7F00 0x7FFF
OUT2 0x7E00 0x7EFF
RAM 0x4000 0x5FFF

[editovat] Semestralni prace - Ovladani ventilatoru teplovzdusneho rozvodu

Viz Jelínek Martin, Zdeněk Kouba: Ovládání ventilátoru teplovzdušného rozvodu

   ;%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
   ;%%%%%SEM. PRACE - JELINEK Martin, KOUBA Zdenek%%%%%
   ;%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
   ;
   ;po startu dojde k inicializaci HW
   ;==nastaveni vstupu a vystupu
   ;==vystupy vynulovany
   
   
   ;==nastaveni COUNTERU1 a AD prevodniku
   ;==nastaveni a nasledne pouziti SLEEP MODu
   
   
   .INCLUDE "m88def.inc"		; info pro prekladac
   
   ;VSTUPY:
   .EQU LOW_START = 1		; prirazeni pinu pro tlacitko 1 (PB1 pin cislo 15)
   .EQU HIGH_STOP = 2		; prirazeni pinu pro tlacitko 2 (PB2 pin cislo 16)
   .EQU ZERO_CR = 3		; prirazeni pinu pro detekci nuly (PB3 pin cislo 17)
   .EQU AD_IN = 0			; prirazeni pinu pro termistor (PC0 pin cislo 23)
   
   ;VYSTUPY:
   .EQU OUT = 5		    ; prirazeni pinu pro optotriak (PD5 pin cislo 11)
   .EQU LED_IND = 6		; prirazeni pinu pro kontrolní LED (PD6 pin cislo 12)
   
   ;NASTAVENI TEPLOTY
   .EQU TEMP_LOW = 128		; nastavení komparacni hodnoty (0-255)
   .EQU TEMP_HIGH = 192	; nastavení komparacni hodnoty (0-255) 
   
   ; HYSTEREZE
   .EQU HYST = 10
   
   ;REGISTR PRO UCHOVANI A POROVNAVANI NASTAVENE TEPLOTY
   .EQU TEMP_TRASH = R17
   
   
   
   .ORG 0x0000	rjmp START	; Resetovaci vektor/skok na hl. program 
   
   .ORG 0x0005	rjmp TLACITKO	; vektor preruseni/skok na obsluhu tlacitek
   
   .ORG 0x000D	rjmp COUNTER1	; Timer/Counter1 overflow - vektor preruseni/skok na obsluhu preteceni counteru1
   
   
   
   ;Main program start 
   START: 
   
   
   ;nastaveni IN/OUT			; PORTC ADC in!!!
   	CBI	DDRB, LOW_START		; nastaveni vstupniho pinu tlacitko 1 (PB1 pin cislo 15)
   	CBI	DDRB, HIGH_STOP		; nastaveni vstupniho pinu pro pro tlacitko 2 (PB2 pin cislo 16)
   	SBI	PORTB, LOW_START	; pull-up pro tlacitko 1
   	SBI	PORTB, HIGH_STOP	; pull-up pro tlacitko 2
   	CBI	DDRC, AD_IN			; nastaveni vstupniho pinu pro termistor (PC0 pin cislo 23)
   
   	SBI	DDRD, OUT			; nastaveni vystupniho pinu pro optotriak (PD5 pin cislo 11)
   	SBI	DDRD, LED_IND		; nastaveni vystupniho pinu pro kontrolní LED (PD6 pin cislo 12)
   	SBI	DDRB, ZERO_CR		; nastaveni docasne-vystupniho pinu pro detekci nuly (PB3 pin cislo 17)-aby nedelal preruseni
   
   
   
   ;nastaveni SLEEP modu
   ;SMCR: 0,0,0,0,SM2,SM1,SM0,SE   SM2..0: Sleep Mode Select Bits, SE: Sleep enabled)
   
   	ldi	r16,0b00000001 	; Idle mode 
   	out	SMCR,r16 		; Sleep mode set
   
   
   ;nastaveni A/D converteru
   	ldi	R16,0b10000111	; ADC enable (7.bit), permit (enable interrupt (3.bit)), prescaler 128
   	out	ADCSRA,R16
   
   	ldi	R16,0b11100000	; Internal 1.1V voltage reference with external capacitor at AREF pin (7.,6.bit), ADLAR (5.bit), input PORTC 0 (low 4 bit)
   	out	ADMUX,R16
   
   	; vystup:  pro ADLAR=1
   	;		7. a 6. bit ADCL (ADC1 - ADC0)
       	;		7. - 0. bit ADCH (ADC9 - ADC2) 
   
   
   ;nastaveni counteru1		
   	; 16bit, prescaler 256 - preruseni kazdych 17,8 sec
   
   	;TCCR1A: COM1A1 COM1A0 COM1B1 COM1B0 0 0 WGM11 WGM10
      	;	 0	0      0      0      0 0 0     0 ... normal mode
   	ldi	R16, 0x00
   	out	TCCR1A, R16
   
   	;TCCR1B: ICNC1 ICES1 0 WGM13 WGM12 CS12 CS11 CS10
   	;	 0     0     0 0     0     1    0    0 ... Clock select - clk_IO/256
   	ldi	R16, 0b00000100
   	out	TCCR1B, R16
   
       ;TIMSK1: 0 0 ICIE1 0 0 OCIE1B OCIE1A TOIE1
       ;	 0 0 1     0 0 0      0      1 ... interrupt on overflow
   	ldi	R16, 0b00100001
   	out	TIMSK1, R16
   
   
   ;inicializace registru temperature-treshhold
   	ldi	TEMP_TRASH, TEMP_LOW
   
   ;-----------------------------------------------------------------------------
   ;-----------------------------------------------------------------------------
   
   ;%%%%PROCEDURY%%%%
   
   
   ;Sleep loop, wake up by the Interrupt, return with RETI back to sleep loop
   
   LOOP:
   	SLEEP 			; prechod do sleep modu
   	nop 			; return from Interrupt to this instruction
   	RJMP	LOOP		; skok na LOOP
   
   
   	
   ;-----------------------------------------------------------------------------
   ;-----------------------------------------------------------------------------
   
   ;%%%%OBSLUHA_PRERUSENI%%%%
   
   TLACITKO:
   	; do registru se ulozi hodnota low nebo high podle stisku tlacitka
   
   	sbic	PINB, LOW_START
   	ldi	TEMP_TRASH, TEMP_LOW
   
   	sbic	PINB, HIGH_START
   	ldi	TEMP_TRASH, TEMP_HIGH
   
   	reti			; return from Interrupt
   
   
   
   COUNTER1:
   	;zakaze se preruseni od tlacitek
   	ldi	R16, 0x00
   	out	PCICR, R16
   
       ; porovna se hodnota z AD prevodniku (ADCH)
   	cp	TEMP_TRASH, ADCH	
   	brge	TEMP_LESS_TRASH	; je mene - odchod, vypnuti vystupu
   	brlt	TEMP_MORE_TRaSH	; je vice - detekce nuly, pak zapnuti vystupu
   
   TEMP_LESS_TRASH:
       sbis    PIND, OUT
       rjmp    EXIT    ; pokud jiz vystup byl vypnuty, rovnou odchod
       ldi    R18, HYST
       add    TEMP_TRASH, R18
   	cbi	PORTD, OUT
   	CBI	PORTD, LED_IND	; LED_OFF
   	rjmp	EXIT
   
   TEMP_MORE_TRASH:
       sbic    PIND, OUT
       rjmp    EXIT    ; pokud jiz vystup byl zapnuty, rovnou na odchod
       subi    TEMP_TRASH, HYST
   	CBI	DDRB, ZERO_CR	; nastaví pin (PB3 cislo 17) jako vstup
   	SBI	PORTD, LED_IND	; LED_ON
   
   ZERO:
   	SBIS	DDRB, ZERO_CR	; detekce kladne pulvlny
   	rjmp	ZERO
   
   NO_ZERO:
   	SBIC	DDRB, ZERO_CR	; detekce nuly
   	rjmp	NO_ZERO
   	SBI	PORTD, OUT
   	SBI	DDRB, ZERO_CR	; nastaví jako vystup - nedela preruseni 
   	rjmp	EXIT
   
   EXIT:	; odchod: povoleni preruseni
   	ldi	R16, 0x01
   	out	PCICR, R16
   	reti			; return from Interrupt
Osobní nástroje