Académique Documents
Professionnel Documents
Culture Documents
CIRCUITO IMPLEMENTADO
LCD1
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
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
D0
D1
D2
D3
D4
D5
D6
D7
RS
RW
E
7
8
9
10
11
12
13
14
1
2
3
U1
40
41
42
43
44
1
2
3
4
5
6
VSS
VDD
VEE
LM016L
37
36
35
34
33
32
31
30
19
20
21
22
23
24
25
26
R1
R2
10k
10k
8
7
U2
6
5
ATMEGA164P
7
3
SCL
SDA
X1
X1
CRYSTAL
SOUT
VBAT X2
DS1307
Hora As Byte
Minuto As Byte
Segundo As Byte
Weekday As Byte
Dia As Byte
Meses As Byte
Annos As Byte
'
'inicializo mi lcd
Jonathan Tirado
Dir_esc
0
_sec
_min
_hour
Setdate:
_day = Makebcd(dia)
_month = Makebcd(meses)
_year = Makebcd(annos)
I2cstart
I2cwbyte Dir_esc
I2cwbyte 4
Jonathan Tirado
tempo=r16
aux=r17
cont=r18
flag=r19
conta=r20
flag_t=r21
.equ SLA_w=0b11010000
.equ SLA_r=0b11010001
.DSEG
Digito_h_w: .BYTE 3
de configuracion escritura
Digito_m_w: .BYTE 3
bits de configuracion escritura
Digito_s_w: .BYTE 3
los bits de configuracion escritura
Digito_h_r: .BYTE 3
configuracion lectura
Digito_m_r: .BYTE 3
bits de configuracion lectura
Digito_s_r: .BYTE 3
bits de configuracion lectura
Hora_w: .BYTE 1
Minuto_w: .BYTE 1
Segundo_w: .BYTE 1
Hora_r: .BYTE 1
Minuto_r: .BYTE 1
Segundo_r: .BYTE 1
Digito_d_w: .BYTE 3
configuracion escritura
Digito_ds_w: .BYTE 3
con los bits de configuracion escritura
Digito_me_w: .BYTE 3
bits de configuracion escritura
Digito_a_w: .BYTE 3
de configuracion escritura
Digito_d_r: .BYTE 3
de configuracion lectura
Digito_ds_r: .BYTE 3
y con los bits de configuracion lectura
Digito_me_r: .BYTE 3
bits de configuracion lectura
Jonathan Tirado
.CSEG
.ORG 0x00
jmp Inicio
.ORG 0x02
jmp Menu_I
.ORG 0x04
jmp Up_I
.ORG 0x06
jmp Down_I
.ORG 0x1A
jmp Casi_1
;interrupcion para espera de 0.9 [s]
.ORG 0x20
jmp Tiempo_Espera
;Interrupcion cuando ha pasado el tiempo de
espera
Inicio:
ldi tempo,0b11110000
;A como salida de Datos
out ddra,tempo
ldi tempo,0b00000011
;B como salida de control
out ddrb,tempo
clr tempo
out ddrd,tempo
ldi tempo,0b00000001
;SDA sin configurar y SCL
como salida
out ddrc,tempo
ldi tempo,0b00001000
out porta,tempo
ldi tempo,0b11111100
out portb,tempo
ser tempo
out portd,tempo
ldi tempo,0b11111110
out portc,tempo
in tempo,mcucr
interno
andi tempo,0b11101111
out mcucr,tempo
ldi tempo,HIGH(RAMEND)
Jonathan Tirado
;inicializando el Stack
sts ocr1ah,tempo
ldi tempo,LOW(28124)
sts ocr1al,tempo
ldi tempo,0b00000010
;inicializando el Timer0
;Configurando el Timer1
;aun no corre y modo CTC
;para que tenga un retardo de
;habilitando la interrupcion
sts timsk1,tempo
inicio
ldi tempo,0b00111111
sts eicra,tempo
ldi tempo,0b00000111
out eimsk,tempo
SEI
call I_LCD_4
ldi tempo,0b10000000
out porta,tempo
sbi portb,0
call Espera
cbi portb,0
ldi tempo,0b00000000
out porta,tempo
sbi portb,0
call Espera
cbi portb,0
ldi zh,HIGH(T_vacio<<1)
ldi zl,LOW(T_vacio<<1)
ldi cont,16
call Escribir
;apuntando al mensaje de
;numero de elementos del mensaje
clr conta
clr flag_t
/*Inicializacion del DS1307*/
ldi tempo,0x02
integrado
Jonathan Tirado
ldi xl,LOW(Hora_w)
ldi yh,HIGH(Digito_h_w)
ldi yl,LOW(Digito_h_w)
call BIN_BCD
lds tempo,Digito_h_w+1
andi tempo,0b11110011
sts Digito_h_w+1,tempo
Codificar
ldi xh,HIGH(Digito_h_w+1)
ldi xl,LOW(Digito_h_w+1)
call Codificar_I
;modo 24H
M_send
al integrado
call Write_I2C
ldi tempo,0x01
integrado
sts A_reloj,tempo
ldi tempo,6
sts Minuto_w,tempo
escritos
BIN-BCD
ldi xh,HIGH(Minuto_w)
ldi xl,LOW(Minuto_w)
ldi yh,HIGH(Digito_m_w)
ldi yl,LOW(Digito_m_w)
call BIN_BCD
lds tempo,Digito_m_w+1
andi tempo,0b11110111
sts Digito_m_w+1,tempo
ldi xh,HIGH(Digito_m_w+1)
para Codificar
M_send
ldi xl,LOW(Digito_m_w+1)
call Codificar_I
call Write_I2C
;argumentos de entrada
;para preparar el dato a enviar
;subrutina de envio de informacion
al integrado
integrado
escritos
Jonathan Tirado
ldi tempo,0x00
sts A_reloj,tempo
ldi tempo,9
sts Segundo_w,tempo
ldi xl,LOW(Segundo_w)
ldi yh,HIGH(Digito_s_w)
ldi yl,LOW(Digito_s_w)
call BIN_BCD
lds tempo,Digito_s_w+1
ori tempo,0b00000000
sts Digito_s_w+1,tempo
para Codificar
ldi xh,HIGH(Digito_s_w+1)
ldi xl,LOW(Digito_s_w+1)
call Codificar_I
M_send
al integrado
call Write_I2C
/*Inicializando la Fecha*/
ldi tempo,0x03
el integrado
sts A_reloj,tempo
ldi tempo,1
sts Dias_w,tempo
ser escrito
sts M_send,tempo
call Write_I2C
al integrado
integrado
BCD
ldi tempo,0x04
sts A_reloj,tempo
ldi tempo,16
sts Dia_w,tempo
ldi xh,HIGH(Dia_w)
ldi xl,LOW(Dia_w)
ldi yh,HIGH(Digito_d_w)
ldi yl,LOW(Digito_d_w)
call BIN_BCD
lds tempo,Digito_d_w+1
andi tempo,0b11110011
decenas no mas de 31
sts Digito_d_w+1,tempo
para Codificar
ldi xh,HIGH(Digito_d_w+1)
ldi xl,LOW(Digito_d_w+1)
call Codificar_I
;argumentos de entrada
;para preparar el dato a enviar
M_send
al integrado
Jonathan Tirado
call Write_I2C
sts A_reloj,tempo
ldi tempo,6
sts Mes_w,tempo
ldi xh,HIGH(Mes_w)
BCD
ldi xl,LOW(Mes_w)
ldi yh,HIGH(Digito_me_w)
ldi yl,LOW(Digito_me_w)
call BIN_BCD
lds tempo,Digito_me_w+1
andi tempo,0b11110001
decenas no mas de 12
sts Digito_me_w+1,tempo
ldi xh,HIGH(Digito_me_w+1)
para Codificar
M_send
ldi xl,LOW(Digito_me_w+1)
call Codificar_I
call Write_I2C
;argumentos de entrada
;para preparar el dato a enviar
;subrutina de envio de informacion
al integrado
integrado
BCD
ldi tempo,0x06
sts A_reloj,tempo
ldi tempo,13
sts Ano_w,tempo
ldi xh,HIGH(Ano_w)
ldi xl,LOW(Ano_w)
ldi yh,HIGH(Digito_a_w)
ldi yl,LOW(Digito_a_w)
call BIN_BCD
ldi xh,HIGH(Digito_a_w+1)
para Codificar
M_send
ldi xl,LOW(Digito_a_w+1)
call Codificar_I
call Write_I2C
;argumentos de entrada
;para preparar el dato a enviar
;subrutina de envio de informacion
al integrado
Prog_Principal:
;Programa Principal
clr flag_t
ldi tempo,0x02
sts A_reloj,tempo
call Read_I2C
ldi xh,HIGH(Hora_r)
decodificar
Jonathan Tirado
ldi xh,HIGH(Hora_r)
ldi xl,LOW(Hora_r)
ldi yh,HIGH(Digito_h_r)
ldi yl,LOW(Digito_h_r)
call BIN_BCD
cbi portb,1
presentar en el LCD
ldi xl,LOW(Digito_h_r+1)
ldi cont,2
call Escribir_Numero
inicio
cbi portb,1
ldi tempo,0b10000000
out porta,tempo
sbi portb,0
call Espera
cbi portb,0
ldi tempo,0b01010000
out porta,tempo
sbi portb,0
call Espera
cbi portb,0
ldi zh,HIGH(T_separa<<1)
ldi zl,LOW(T_separa<<1)
ldi cont,1
call Escribir
cbi portb,1
ldi tempo,0b10000000
out porta,tempo
sbi portb,0
call Espera
cbi portb,0
ldi tempo,0b10000000
out porta,tempo
sbi portb,0
Jonathan Tirado
;apuntando al mensaje de
;numero de elementos del mensaje
ldi zl,LOW(T_separa<<1)
ldi cont,1
call Escribir
ldi tempo,0x01
sts A_reloj,tempo
call Read_I2C
ldi xh,HIGH(Minuto_r)
decodificar
BIN-BCD
;apuntando al mensaje de
;numero de elementos del mensaje
ldi xl,LOW(Minuto_r)
call Decodificar_I
ldi xh,HIGH(Minuto_r)
ldi xl,LOW(Minuto_r)
ldi yh,HIGH(Digito_m_r)
ldi yl,LOW(Digito_m_r)
call BIN_BCD
cbi portb,1
ldi tempo,0b10000000
out porta,tempo
sbi portb,0
call Espera
cbi portb,0
ldi tempo,0b01100000
out porta,tempo
sbi portb,0
call Espera
cbi portb,0
ldi xh,HIGH(Digito_m_r+1)
presentar en el LCD
ldi xl,LOW(Digito_m_r+1)
ldi cont,2
call Escribir_Numero
ldi tempo,0x00
sts A_reloj,tempo
call Read_I2C
decodificar
ldi xh,HIGH(Segundo_r)
ldi xl,LOW(Segundo_r)
call Decodificar_I
ldi xh,HIGH(Segundo_r)
para BIN-BCD
Jonathan Tirado
ldi xl,LOW(Segundo_r)
ldi yh,HIGH(Digito_s_r)
;argumentos de entrada
;digitos de los segundos
ldi tempo,0b10010000
out porta,tempo
sbi portb,0
call Espera
cbi portb,0
presentar en el LCD
ldi xh,HIGH(Digito_s_r+1)
ldi xl,LOW(Digito_s_r+1)
ldi cont,2
call Escribir_Numero
decodificar
ldi tempo,0x04
sts A_reloj,tempo
call Read_I2C
ldi xh,HIGH(Dia_r)
ldi xl,LOW(Dia_r)
call Decodificar_I
ldi xh,HIGH(Dia_r)
BCD
ldi xl,LOW(Dia_r)
ldi yh,HIGH(Digito_d_r)
ldi yl,LOW(Digito_d_r)
call BIN_BCD
cbi portb,1
presentar en el LCD
Jonathan Tirado
ldi xl,LOW(Digito_d_r+1)
call Escribir_Numero
separacion
cbi portb,1
ldi tempo,0b11000000
out porta,tempo
sbi portb,0
call Espera
cbi portb,0
ldi tempo,0b01010000
out porta,tempo
sbi portb,0
call Espera
cbi portb,0
ldi zh,HIGH(T_separa_1<<1)
ldi zl,LOW(T_separa_1<<1)
ldi cont,1
call Escribir
separador
cbi portb,1
ldi tempo,0b11000000
out porta,tempo
sbi portb,0
call Espera
cbi portb,0
ldi tempo,0b10000000
out porta,tempo
sbi portb,0
call Espera
cbi portb,0
ldi zh,HIGH(T_separa_1<<1)
ldi zl,LOW(T_separa_1<<1)
ldi cont,1
call Escribir
decodificar
;apuntando al mensaje de
;numero de elementos del mensaje
ldi tempo,0x05
sts A_reloj,tempo
call Read_I2C
ldi xh,HIGH(Mes_r)
ldi xl,LOW(Mes_r)
call Decodificar_I
ldi xh,HIGH(Mes_r)
BIN-BCD
ldi xl,LOW(Mes_r)
ldi yh,HIGH(Digito_me_r)
ldi yl,LOW(Digito_me_r)
call BIN_BCD
cbi portb,1
ldi tempo,0b11000000
out porta,tempo
sbi portb,0
Jonathan Tirado
ldi xl,LOW(Digito_me_r+1)
ldi cont,2
call Escribir_Numero
decodificar
ldi tempo,0x06
sts A_reloj,tempo
call Read_I2C
ldi xh,HIGH(Ano_r)
ldi xl,LOW(Ano_r)
call Decodificar_I
ldi xh,HIGH(Ano_r)
BCD
ldi xl,LOW(Ano_r)
ldi yh,HIGH(Digito_a_r)
ldi yl,LOW(Digito_a_r)
call BIN_BCD
cbi portb,1
ldi tempo,0b11000000
out porta,tempo
sbi portb,0
call Espera
cbi portb,0
ldi tempo,0b10010000
out porta,tempo
sbi portb,0
call Espera
cbi portb,0
presentar en el LCD
ldi xh,HIGH(Digito_a_r+1)
ldi xl,LOW(Digito_a_r+1)
ldi cont,2
call Escribir_Numero
call Esperar_1
No_pasa:
Jonathan Tirado
ldi tempo,SLA_w
;cargamos la direccion de
sts TWDR,tempo
ldi tempo,(1<<TWINT)|(1<<TWEN)
habilitamos el envio
;bajamos la bandera y
sts TWCR,tempo
Wait2_w:
informacion
lds tempo,TWCR
sbrs tempo,TWINT
nuevamente se levante la bandera
rjmp Wait2_w
lds tempo,A_reloj
;cargamos la direccion de
escitura a ser enviado desde el Master
sts TWDR,tempo
ldi tempo,(1<<TWINT)|(1<<TWEN)
;bajamos la bandera y
habilitamos el envio
sts TWCR,tempo
Wait3_w:
;Tiempo de espera hasta que se haya enviado la
informacion
lds tempo,TWCR
sbrs tempo,TWINT
;esperamos hasta que
nuevamente se levante la bandera
rjmp Wait3_w
desde el Master
lds tempo,M_send
sts TWDR,tempo
ldi tempo,(1<<TWINT)|(1<<TWEN)
habilitamos el envio
sts TWCR,tempo
Wait4_w:
informacion
lds tempo,TWCR
sbrs tempo,TWINT
nuevamente se levante la bandera
rjmp Wait4_w
Jonathan Tirado
;bajamos la bandera y
;habilitando el
Read_I2C:
Jonathan Tirado
lds tempo,TWCR
sbrs tempo,TWINT
nuevamente se levante la bandera
rjmp Wait5_r
ldi tempo,(1<<TWINT)|(1<<TWEN)
;bajamos la bandera y
habilitamos el envio una ves ms para que lleguen los datos desde el integrado
sts TWCR,tempo
Wait7_r:
;Tiempo de espera hasta que se haya enviado la
informacion
lds tempo,TWCR
sbrs tempo,TWINT
;esperamos hasta que
nuevamente se levante la bandera
rjmp Wait7_r
Slave
lds tempo,TWDR
recibido
sts S_send,tempo
ldi tempo,(1<<TWINT)|(1<<TWEN)
habilitamos el envio para devolver un NOT ACKNOWLEDGE
sts TWCR,tempo
Wait6_r:
informacion
;bajamos la bandera y
lds tempo,TWCR
sbrs tempo,TWINT
nuevamente se levante la bandera
rjmp Wait6_r
ldi tempo,(1<<TWINT)|(1<<TWEN)|(1<<TWSTO)
envio de la Stop Condition
sts TWCR,tempo
ret
;habilitando el
Saltox_k:
Saltoy_k:
Jonathan Tirado
ldi tempo,255
dec tempo
ret
pop tempo
out SREG,tempo
pop cont
pop tempo
BIN_BCD:
;recuperando estado
Centenas:
Decenas:
Decenas1:
Unidades:
subi tempo,100
brcs Decenas
inc cont
rjmp Centenas
st y+,cont
clr cont
subi tempo,-100
subi tempo,10
brcs Unidades
inc cont
rjmp Decenas1
;resta de 8 bits
;cuando ya es menor
st y+,cont
subi tempo,-10
st y,tempo
pop tempo
pop cont
ret
Codificar_I:
;Subrutina ubicar la informacion de horas, minutos
y segundos en el formato de envio M_send
push tempo
push aux
push cont
ld aux,x+
referencia, ya sea los digitos de Hora, Minuto, Segundo
swap aux
para armar el byte de envio M_send
andi aux,0b11110000
ld tempo,x
argumento de entrada
andi tempo,0b00001111
or tempo,aux
sts M_send,tempo
DS1307
pop cont
pop aux
pop tempo
ret
Jonathan Tirado
andi aux,0b01110000
swap aux
ldi tempo,10
mul aux,tempo
mov aux,r0
lds tempo,S_send
andi tempo,0b00001111
add tempo,aux
st x,tempo
pop cont
pop aux
pop tempo
ret
/*Limpiar la Pantalla*/
Limpiar:
push tempo
cbi portb,1
ldi tempo,0b00000000
out porta,tempo
sbi portb,0
call Espera
cbi portb,0
ldi tempo,0b00010000
out porta,tempo
sbi portb,0
call Espera
cbi portb,0
pop tempo
ret
/*Subrutina para Escribir un Mensaje en el LCD*/
Escribir:
push tempo
push aux
sbi portb,1
Lazo_Pasar:
lpm tempo,z
andi tempo,0b11110000
out porta,tempo
sbi portb,0
call Espera
cbi portb,0
Jonathan Tirado
;RS en 1L
;habilitar
;subrutina para esperar la escritura
ret
dec cont
brne Lazo_Pasar
pop aux
pop tempo
;habilitar
;subrutina para esperar la escritura
;RS en 1L
;los 4 primeros bits implican
;habilitar
;subrutina para esperar la
;habilitar
;subrutina para esperar la
cbi portb,0
dec cont
brne Pasar_Numero
pop aux
pop tempo
ret
/*Subrutina de Inicializacin de LCD 16x2 a 4 bits*/
I_LCD_4:
push tempo
in tempo,SREG
push tempo
cbi portb,1
/*Espera de mas de 15 [ms] para que alcance los 4.5 [V]*/
ldi tempo,124
out ocr0a,tempo
ldi tempo,5
;preescalador 1:1024
out tccr0b,tempo
Wait1:
sbrs flag,0
rjmp Wait1
Jonathan Tirado
encerandolo
clr flag
out tccr0b,flag
;parando el timer 0 y
out ocr0a,flag
/*Function Set*/
ldi tempo,0x30
out porta,tempo
sbi portb,0
/*Espera de mas de 4,1 [ms]*/
ldi tempo,124
out ocr0a,tempo
ldi tempo,5
out tccr0b,tempo
Wait2:
sbrs flag,0
rjmp Wait2
clr flag
out tccr0b,flag
;preescalador 1:1024
;parando el timer 0 y
encerandolo
out ocr0a,flag
cbi portb,0
/*Function Set segunda vez*/
ldi tempo,0x30
out porta,tempo
sbi portb,0
/*Espera de mas de 100 [us]*/
ldi tempo,14
out ocr0a,tempo
ldi tempo,3
out tccr0b,tempo
Wait3:
sbrs flag,0
rjmp Wait3
clr flag
out tccr0b,flag
encerandolo
out ocr0a,flag
cbi portb,0
/*Function Set tres vez*/
ldi tempo,0x30
out porta,tempo
sbi portb,0
call Espera
call Espera
cbi portb,0
/*Function Set cuarta vez*/
ldi tempo,0b00100000
out porta,tempo
sbi portb,0
call Espera
call Espera
cbi portb,0
ldi tempo,0b00100000
display
out porta,tempo
sbi portb,0
Jonathan Tirado
;preescalador 1:64
;parando el timer 0 y
;4 bits
;fuente
ldi tempo,0b00000000
out porta,tempo
sbi portb,0
call Espera
cbi portb,0
ldi tempo,0b11110000
out porta,tempo
sbi portb,0
call Espera
cbi portb,0
/*Modo de Ingreso*/
ldi tempo,0b00000000
out porta,tempo
sbi portb,0
call Espera
cbi portb,0
ldi tempo,0b01100000
out porta,tempo
sbi portb,0
call Espera
cbi portb,0
/*Limpiar Display*/
ldi tempo,0
out porta,tempo
sbi portb,0
call Espera
cbi portb,0
ldi tempo,1
out porta,tempo
sbi portb,0
call Espera
cbi portb,0
ret
Espera:
Lazo_ret:
Jonathan Tirado
pop tempo
out SREG,tempo
pop tempo
;aproximadamente 96 [us] a 8 [MHz]
push aux
in aux,SREG
push aux
ldi aux,255
;retardo
ret
/*Subrutina de Interrupcion del Timer0*/
Tiempo_Espera:
push tempo
in tempo,SREG
push tempo
com flag
reti
pop tempo
out SREG,tempo
pop tempo
inc conta
correspondiente a las opciones del menu
cpi conta,6
Normal, Horas, Minutos, Das, Meses y Aos
brcs Salir_Menu
clr conta
Salir_Menu:
pop cont
pop aux
pop tempo
out SREG,tempo
pop tempo
reti
Jonathan Tirado
;incremento el valor
;solo hay 6 opciones en el Menu:
call Kill_Rebote
push tempo
out SREG,tempo
push tempo
push aux
push cont
minutos
;salvar estado
cpi conta,0
breq Normal_U
cpi conta,1
breq Up_H
cpi conta,2
breq Up_M
cpi conta,3
breq Up_D
cpi conta,4
breq Up_Me
cpi conta,5
breq Up_A
Normal_U:
Up_H:
Up_M:
Up_D:
Up_Me:
Up_A:
Up_H_1:
integrado
rjmp Salir_Up
rjmp Up_H_1
rjmp Up_M_1
rjmp Up_D_1
rjmp Up_Me_1
rjmp Up_A_1
ldi tempo,0x02
sts A_reloj,tempo
lds tempo,Hora_r
que mando el Slave
Hora_Ok:
BIN-BCD
inc tempo
cpi tempo,24
brcs Hora_Ok
clr tempo
sts Hora_w,tempo
ldi xh,HIGH(Hora_w)
ldi xl,LOW(Hora_w)
ldi yh,HIGH(Digito_h_w)
Jonathan Tirado
;digitos de la hora
Codificar
M_send
lds tempo,Digito_h_w+1
andi tempo,0b11110011
sts Digito_h_w+1,tempo
;modo 24H
ldi xh,HIGH(Digito_h_w+1)
ldi xl,LOW(Digito_h_w+1)
call Codificar_I
call Write_I2C
al integrado
Up_M_1:
integrado
enviado por el Slave
jmp Salir_Up
ldi tempo,0x01
sts A_reloj,tempo
lds tempo,Minuto_r
inc tempo
Minuto_Ok:
escritos
BIN-BCD
cpi tempo,60
brcs Minuto_Ok
clr tempo
sts Minuto_w,tempo
ldi xh,HIGH(Minuto_w)
ldi xl,LOW(Minuto_w)
ldi yh,HIGH(Digito_m_w)
ldi yl,LOW(Digito_m_w)
call BIN_BCD
lds tempo,Digito_m_w+1
andi tempo,0b11110111
sts Digito_m_w+1,tempo
para Codificar
ldi xh,HIGH(Digito_m_w+1)
ldi xl,LOW(Digito_m_w+1)
call Codificar_I
;argumentos de entrada
;para preparar el dato a enviar
M_send
al integrado
Up_D_1:
integrado
por el Slave
Jonathan Tirado
call Write_I2C
jmp Salir_Up
ldi tempo,0x04
sts A_reloj,tempo
lds tempo,Dia_r
inc tempo
Dia_Ok:
BIN-BCD
cpi tempo,32
brcs Dia_Ok
ldi tempo,1
sts Dia_w,tempo
ldi xh,HIGH(Dia_w)
ldi xl,LOW(Dia_w)
ldi yh,HIGH(Digito_d_w)
ldi yl,LOW(Digito_d_w)
call BIN_BCD
lds tempo,Digito_d_w+1
andi tempo,0b11110011
sts Digito_d_w+1,tempo
ldi xh,HIGH(Digito_d_w+1)
para Codificar
M_send
ldi xl,LOW(Digito_d_w+1)
call Codificar_I
call Write_I2C
al integrado
Up_Me_1:
integrado
enviado por el Slave
;argumentos de entrada
;para preparar el dato a enviar
;subrutina de envio de informacion
jmp Salir_Up
ldi tempo,0x05
sts A_reloj,tempo
lds tempo,Mes_r
inc tempo
Mes_Ok:
BIN-BCD
cpi tempo,13
brcs Mes_Ok
ldi tempo,1
sts Mes_w,tempo
ldi xh,HIGH(Mes_w)
ldi xl,LOW(Mes_w)
ldi yh,HIGH(Digito_me_w)
ldi yl,LOW(Digito_me_w)
call BIN_BCD
lds tempo,Digito_me_w+1
andi tempo,0b11110001
sts Digito_me_w+1,tempo
ldi xh,HIGH(Digito_me_w+1)
para Codificar
M_send
Jonathan Tirado
ldi xl,LOW(Digito_me_w+1)
call Codificar_I
;argumentos de entrada
;para preparar el dato a enviar
jmp Salir_Up
ldi tempo,0x06
sts A_reloj,tempo
lds tempo,Ano_r
inc tempo
Ano_Ok:
BIN-BCD
cpi tempo,100
brcs Ano_Ok
clr tempo
sts Ano_w,tempo
ldi xh,HIGH(Ano_w)
ldi xl,LOW(Ano_w)
ldi yh,HIGH(Digito_a_w)
ldi yl,LOW(Digito_a_w)
call BIN_BCD
ldi xh,HIGH(Digito_a_w+1)
para Codificar
M_send
ldi xl,LOW(Digito_a_w+1)
call Codificar_I
call Write_I2C
;argumentos de entrada
;para preparar el dato a enviar
;subrutina de envio de informacion
al integrado
Salir_Up:
reti
pop cont
pop aux
pop tempo
out SREG,tempo
pop tempo
Down_I:
software
call Kill_Rebote
push tempo
out SREG,tempo
push tempo
push aux
push cont
minutos
Jonathan Tirado
cpi conta,0
breq Normal_D
cpi conta,1
breq D_H
cpi conta,2
breq D_M
cpi conta,4
breq D_Me
cpi conta,5
breq D_A
Normal_D:
D_H:
D_M:
D_D:
D_Me:
D_A:
D_H_1:
integrado
rjmp Salir_D
rjmp D_H_1
rjmp D_M_1
rjmp D_D_1
rjmp D_Me_1
rjmp D_A_1
ldi tempo,0x02
sts A_reloj,tempo
lds tempo,Hora_r
Hora_1:
H_Ok:
BIN-BCD
cpi tempo,0
breq Hora_1
dec tempo
rjmp H_Ok
ldi tempo,23
sts Hora_w,tempo
ldi xh,HIGH(Hora_w)
ldi xl,LOW(Hora_w)
ldi yh,HIGH(Digito_h_w)
ldi yl,LOW(Digito_h_w)
call BIN_BCD
Codificar
;digitos de la hora
lds tempo,Digito_h_w+1
andi tempo,0b11110011
sts Digito_h_w+1,tempo
;modo 24H
ldi xh,HIGH(Digito_h_w+1)
ldi xl,LOW(Digito_h_w+1)
call Codificar_I
M_send
al integrado
call Write_I2C
jmp Salir_D
Jonathan Tirado
ldi tempo,0x01
sts A_reloj,tempo
lds tempo,Minuto_r
Minuto_1:
M_Ok:
escritos
BIN-BCD
cpi tempo,0
breq Minuto_1
dec tempo
rjmp M_Ok
ldi tempo,59
sts Minuto_w,tempo
ldi xh,HIGH(Minuto_w)
ldi xl,LOW(Minuto_w)
ldi yh,HIGH(Digito_m_w)
ldi yl,LOW(Digito_m_w)
call BIN_BCD
lds tempo,Digito_m_w+1
andi tempo,0b11110111
sts Digito_m_w+1,tempo
para Codificar
ldi xh,HIGH(Digito_m_w+1)
ldi xl,LOW(Digito_m_w+1)
call Codificar_I
;argumentos de entrada
;para preparar el dato a enviar
M_send
al integrado
D_D_1:
integrado
call Write_I2C
jmp Salir_D
ldi tempo,0x04
sts A_reloj,tempo
lds tempo,Dia_r
Dia_1:
D_Ok:
BIN-BCD
cpi tempo,1
breq Dia_1
dec tempo
rjmp D_Ok
ldi tempo,31
sts Dia_w,tempo
ldi xh,HIGH(Dia_w)
ldi xl,LOW(Dia_w)
ldi yh,HIGH(Digito_d_w)
ldi yl,LOW(Digito_d_w)
Jonathan Tirado
Codificar
ldi xh,HIGH(Digito_d_w+1)
ldi xl,LOW(Digito_d_w+1)
call Codificar_I
M_send
al integrado
D_Me_1:
integrado
call Write_I2C
jmp Salir_D
ldi tempo,0x05
sts A_reloj,tempo
lds tempo,Mes_r
Mes_1:
Me_Ok:
BIN-BCD
cpi tempo,1
breq Mes_1
dec tempo
rjmp Me_Ok
ldi tempo,12
sts Mes_w,tempo
ldi xh,HIGH(Mes_w)
ldi xl,LOW(Mes_w)
ldi yh,HIGH(Digito_me_w)
ldi yl,LOW(Digito_me_w)
call BIN_BCD
lds tempo,Digito_me_w+1
andi tempo,0b11110001
sts Digito_me_w+1,tempo
para Codificar
ldi xh,HIGH(Digito_me_w+1)
ldi xl,LOW(Digito_me_w+1)
call Codificar_I
;argumentos de entrada
;para preparar el dato a enviar
M_send
al integrado
call Write_I2C
jmp Salir_D
D_A_1:
integrado
que mando el Slave
Jonathan Tirado
ldi tempo,0x06
sts A_reloj,tempo
lds tempo,Ano_r
A_1:
ldi tempo,99
A_Ok:
BIN-BCD
sts Ano_w,tempo
ldi xh,HIGH(Ano_w)
ldi xl,LOW(Ano_w)
ldi yh,HIGH(Digito_a_w)
ldi yl,LOW(Digito_a_w)
call BIN_BCD
ldi xh,HIGH(Digito_a_w+1)
Codificar
ldi xl,LOW(Digito_a_w+1)
call Codificar_I
M_send
call Write_I2C
al integrado
Salir_D:
pop cont
pop aux
pop tempo
out SREG,tempo
pop tempo
reti
T_separa:
.db ":"
;cadena de 1 caracter
T_separa_1:
.db "/"
T_vacio:
.db "
"
Jonathan Tirado