/* * * * * * */
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 Villacrés
.include .include .def .def .def .def .def .def .org .org .org .org .org .org
"m164pdef.inc" tempo=R16 conta=R17 conta1=R18
0x00 rjmp inicio rjmp inicio 0x02 rjmp encender_apagar encender_apagar 0x01A rjmp desborde rjmp desborde
inicio: ldi ldi out out ; INTO ldi ldi out out com com out out
tempo,0b00001000 ddrb,tempo tempo,0b00000000 ddrd,tempo tempo portd,tempo
; pull up
;aseguro pull up in in tempo,MCUCR andi andi tempo,0b11101111 out out MCUCR,tempo ;inicio stack pointer ldi tempo,high(ramend) ldi out out sph,tempo ldi ldi tempo,low(ramend) out out spl,tempo ;configuro interrupciones externas ldi ldi sts sts ldi ldi out out out out
tempo,0b00000010 EICRA,tempo tempo,0b00000001 EIMSK,tempo EIFR,tempo
SEI ; Timer 0, 5KHz ldi ldi out out ldi ldi out out ldi ldi
tempo,0b00000010 TCCR0A,tempo tempo,0b00000010 TCCR0B,tempo tempo,99
; Activar con INT0 0b01000010
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
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
ldi ldi
conta,0 conta1,0
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:
; normal, CTC
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
SIMULACiÓN
A B C D
U1 40 41 42 43 44 1 2
PB0/XCK0/T0/PCINT8
PA0/ADC0/PCINT0
PB1/T1/CLKO/PCINT9
PA1/ADC1/PCINT1
PB2/AIN0/INT2/PCINT10
PA2/ADC2/PCINT2
PB3/AIN1/OC0A/PCINT11
PA3/ADC3/PCINT3
PB4/SS/OC0B/PCINT12
PA4/ADC4/PCINT4
PB5/MOSI/PCINT13
PA5/ADC5/PCINT5
PB6/MISO/PCINT14
PA6/ADC6/PCINT6
PB7/SCK/PCINT15
PA7/ADC7/PCINT7
PD0/RXD0/PCINT24
PC0/SCL/PCINT16
PD1/TXD0/PCINT25
PC1/SDA/PCINT17
PD2/INT0/RXD1/PCINT26
PC2/TCK/PCINT18
PD3/INT1/TXD1/PCINT27
PC3/TMS/PCINT19
PD4/OC1B/XCK1/PCINT28
PC4/TDO/PCINT20
PD5/OC1A/PCINT29
3 9 10 11 12 13 14 15 16 29 27 4
PC5/TDI/PCINT21
PD6/ICP/OC2B/PCINT30
PC6/TOSC1/PCINT22
PD7/OC2A/PCINT31
PC7/TOSC2/PCINT23
AREF
XTAL1
AVCC
XTAL2
RESET ATMEGA164P
37 36 35 34 33 32 31 30 19 20 21 22 23 24 25 26 8 7