Ejercicio timer Assembler atmega164p

download Ejercicio timer Assembler atmega164p

of 3

Transcript of Ejercicio timer Assembler atmega164p

  • 8/13/2019 Ejercicio timer Assembler atmega164p

    1/3

    /**

    * ECIO_4.asm* GENERAR UN PWM DE 5KHZ CADA MEDIO SEGUNDO, Y ENCENDERLA O APAGARLA CON UN PULSADOR* Created: 11/18/2013 5:17:16 PM

    * Author: Juan Villacrs*/

    .include "m164pdef.inc"

    .def tempo=R16

    .def conta=R17

    .def conta1=R18

    .org 0x00rjmpinicio

    .org 0x02rjmpencender_apagar

    .org 0x01A

    rjmpdesborde

    inicio:

    ldi tempo,0b00001000out ddrb,tempo; INTOldi tempo,0b00000000out ddrd,tempocom tempoout portd,tempo ; pull up

    ;aseguro pull up

    in tempo,MCUCRandi tempo,0b11101111

    out MCUCR,tempo

    ;inicio stack pointer

    ldi tempo,high(ramend)out sph,tempoldi tempo,low(ramend)out spl,tempo

    ;configuro interrupciones externas

    ldi tempo,0b00000010sts EICRA,tempoldi tempo,0b00000001

    out EIMSK,tempoout EIFR,tempo

    SEI

    ; Timer 0, 5KHz

    ldi tempo,0b00000010 ; Activar con INT0 0b01000010out TCCR0A,tempo

    ldi tempo,0b00000010out TCCR0B,tempoldi tempo,99

  • 8/13/2019 Ejercicio timer Assembler atmega164p

    2/3

    out OCR0A,tempoldi tempo,0b00000000

    sts TIMSK0,tempo

    ; Timer 1, 0.5 seg

    ldi tempo,0b00000000 ; normal, CTCsts TCCR1A,tempo

    ldi tempo,0b00001100sts TCCR1B,tempoclr temposts TCCR1C,tempoldi tempo,high(15624)

    sts OCR1AH,tempoldi tempo,low(15624)sts OCR1AL,tempo

    ldi tempo,0b00000000sts TIMSK1,tempo

    ldi conta,0ldi conta1,0

    main:rjmpmain

    desborde:push r16in r16,SREGpush r16cpi conta,1breq apa_t0enc_t0:

    ldi tempo,0b01000010out TCCR0A,tempo

    inc contarjmp conti

    apa_t0:ldi tempo,0b00000010out TCCR0A,tempoclr conta

    conti:pop r16out SREG,tempopop r16

    RETI

    encender_apagar:

    push r16in r16,SREGpush r16cpi conta1,1

    breq apa_t1

    enc_t1:

  • 8/13/2019 Ejercicio timer Assembler atmega164p

    3/3

    ldi tempo,0b00000010

    sts TIMSK1,tempoldi tempo,0b01000010out TCCR0A,tempo

    inc conta1rjmp conti1

    apa_t1:ldi tempo,0b00000000sts TIMSK1,tempoldi tempo,0b00000010out TCCR0A,tempo

    clr conta1

    conti1:

    pop r16out SREG,tempopop r16

    RETI

    SIMULACiN

    PC6/TOSC1/PCINT22 25

    PC5/TDI/PCINT21 24

    PC4/TDO/PCINT20 23

    PC3/TMS/PCINT19 22

    PC2/TCK/PCINT18 21

    PC1/SDA/PCINT17 20

    PC0/SCL/PCINT16 19

    AVCC27

    AREF29

    PC7/TOSC2/PCINT23 26

    PA6/ADC6/PCINT6 31

    PA5/ADC5/PCINT5 32

    PA4/ADC4/PCINT4 33

    PA3/ADC3/PCINT3 34

    PA2/ADC2/PCINT2 35

    PA1/ADC1/PCINT1 36

    PA0/ADC0/PCINT0 37

    PA7/ADC7/PCINT7 30

    PB6/MISO/PCINT142

    PB5/MOSI/PCINT131

    PB4/SS/OC0B/PCINT1244

    PB3/AIN1/OC0A/PCINT1143

    PB2/AIN0/INT2/PCINT1042

    PB1/T1/CLKO/PCINT941

    PB0/XCK0/T0/PCINT840

    PB7/SCK/PCINT153

    PD6/ICP/OC2B/PCINT3015

    PD5/OC1A/PCINT2914

    PD4/OC1B/XCK1/PCINT2813

    PD3/INT1/TXD1/PCINT2712

    PD2/INT0/RXD1/PCINT2611

    PD1/TXD0/PCINT2510

    PD0/RXD0/PCINT249

    PD7/OC2A/PCINT3116

    RESET4

    XTAL1 8

    XTAL2 7

    U1

    ATMEGA164P

    A

    B

    C

    D