You are on page 1of 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 .def .def .def .org .org .org

"m164pdef.inc" tempo=R16 conta=R17 conta1=R18

0x00 rjmp inicio 0x02 rjmp encender_apagar 0x01A rjmp desborde

inicio: ldi out ; INTO ldi out com out tempo,0b00001000 ddrb,tempo tempo,0b00000000 ddrd,tempo tempo portd,tempo

; pull up

;aseguro pull up in andi out tempo,MCUCR tempo,0b11101111 MCUCR,tempo

;inicio stack pointer ldi out ldi out tempo,high(ramend) sph,tempo tempo,low(ramend) spl,tempo

;configuro interrupciones externas ldi sts ldi out out SEI ; Timer 0, 5KHz ldi out ldi out ldi tempo,0b00000010 TCCR0A,tempo tempo,0b00000010 TCCR0B,tempo tempo,99 ; Activar con INT0 0b01000010 tempo,0b00000010 EICRA,tempo tempo,0b00000001 EIMSK,tempo EIFR,tempo

out ldi sts

OCR0A,tempo tempo,0b00000000 TIMSK0,tempo

; Timer 1, 0.5 seg ldi sts ldi sts clr sts ldi sts ldi sts ldi sts ldi ldi tempo,0b00000000 TCCR1A,tempo tempo,0b00001100 TCCR1B,tempo tempo TCCR1C,tempo tempo,high(15624) OCR1AH,tempo tempo,low(15624) OCR1AL,tempo tempo,0b00000000 TIMSK1,tempo conta,0 conta1,0 ; normal, CTC

main: rjmp main desborde: push r16 in r16,SREG push r16 cpi conta,1 breq apa_t0 enc_t0: ldi out inc rjmp tempo,0b01000010 TCCR0A,tempo conta conti

apa_t0: ldi tempo,0b00000010 out TCCR0A,tempo clr conta

conti: pop r16 out SREG,tempo pop r16 RETI

encender_apagar: push in push cpi breq r16 r16,SREG r16 conta1,1 apa_t1

enc_t1:

ldi sts ldi out inc rjmp

tempo,0b00000010 TIMSK1,tempo tempo,0b01000010 TCCR0A,tempo conta1 conti1

apa_t1: ldi tempo,0b00000000 sts TIMSK1,tempo ldi tempo,0b00000010 out TCCR0A,tempo clr conta1 conti1: pop r16 out SREG,tempo pop r16 RETI

SIMULACiN

A B C D

U1
40 41 42 43 44 1 2 3 9 10 11 12 13 14 15 16 29 27 4 PB0/XCK0/T0/PCINT8 PB1/T1/CLKO/PCINT9 PB2/AIN0/INT2/PCINT10 PB3/AIN1/OC0A/PCINT11 PB4/SS/OC0B/PCINT12 PB5/MOSI/PCINT13 PB6/MISO/PCINT14 PB7/SCK/PCINT15 PD0/RXD0/PCINT24 PD1/TXD0/PCINT25 PD2/INT0/RXD1/PCINT26 PD3/INT1/TXD1/PCINT27 PD4/OC1B/XCK1/PCINT28 PD5/OC1A/PCINT29 PD6/ICP/OC2B/PCINT30 PD7/OC2A/PCINT31 AREF AVCC RESET ATMEGA164P PA0/ADC0/PCINT0 PA1/ADC1/PCINT1 PA2/ADC2/PCINT2 PA3/ADC3/PCINT3 PA4/ADC4/PCINT4 PA5/ADC5/PCINT5 PA6/ADC6/PCINT6 PA7/ADC7/PCINT7 PC0/SCL/PCINT16 PC1/SDA/PCINT17 PC2/TCK/PCINT18 PC3/TMS/PCINT19 PC4/TDO/PCINT20 PC5/TDI/PCINT21 PC6/TOSC1/PCINT22 PC7/TOSC2/PCINT23 XTAL1 XTAL2 37 36 35 34 33 32 31 30 19 20 21 22 23 24 25 26 8 7

You might also like