Está en la página 1de 3

Código Micro Maestro dayN =

ds1307_getdayofweek(year,month,day);
/*
* MicroMaestro.c if(dayN==1){PORTB |=
* Author : Jairo Fernandez (1<<PB0);PORTB &=~ (1<<PB1);PORTB &=~
*/ (1<<PB3);PORTC &=~ (1<<PC2);PORTC &=~
#define F_CPU 8000000L (1<<PC3);PORTC &=~ (1<<PC4);PORTC &=~ (1<<PC5);}
#include <avr/io.h> if(dayN==2){PORTB &=~
#include <util/delay.h> //delays (1<<PB0);PORTB |= (1<<PB1);PORTB &=~
#include <stdio.h> (1<<PB3);PORTC &=~ (1<<PC2);PORTC &=~
#include <string.h> (1<<PC3);PORTC &=~ (1<<PC4);PORTC &=~ (1<<PC5);}
#include <avr/interrupt.h> if(dayN==3){PORTB &=~
#include <SPI_Master_H_file.h> (1<<PB0);PORTB &=~ (1<<PB1);PORTB |=
#include "ds1307.h" (1<<PB3);PORTC &=~ (1<<PC2);PORTC &=~
#include "i2cmaster.h" (1<<PC3);PORTC &=~ (1<<PC4);PORTC &=~ (1<<PC5);}
int display[] = if(dayN==4){PORTC &=~
{0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6 (1<<PB0);PORTB &=~ (1<<PB1);PORTB &=~
f}; (1<<PB3);PORTC |= (1<<PC2);PORTC &=~
// Funcion de barrido (1<<PC3);PORTC &=~ (1<<PC4);PORTC &=~ (1<<PC5);}
void barrido(int entrada); if(dayN==5){PORTC &=~
uint8_t day; (1<<PB0);PORTB &=~ (1<<PB1);PORTB &=~
uint8_t dayN; (1<<PB3);PORTC &=~ (1<<PC2);PORTC |=
uint8_t month; (1<<PC3);PORTC &=~ (1<<PC4);PORTC &=~ (1<<PC5);}
uint8_t hour; if(dayN==6){PORTC &=~
uint8_t minnts; (1<<PB0);PORTB &=~ (1<<PB1);PORTB &=~
uint8_t seconts; (1<<PB3);PORTC &=~ (1<<PC2);PORTC &=~
uint8_t year; (1<<PC3);PORTC |= (1<<PC4);PORTC &=~ (1<<PC5);}
uint8_t message; if(dayN==7){PORTC &=~
uint8_t pulsador; (1<<PB0);PORTB &=~ (1<<PB1);PORTB &=~
uint8_t probar=10; (1<<PB3);PORTC &=~ (1<<PC2);PORTC &=~
uint8_t change=0; (1<<PC3);PORTC &=~ (1<<PC4);PORTC |= (1<<PC5);}
uint8_t Dip;
int main(void) if((PINC & (1<<PC6)) == 0){
{ barrido(hour*100+minnts);
//Configurar puertos }else{
DDRA = 0xff; barrido(month*100+day);
DDRB |= ((1<<PB0)|(1<<PB1)|(1<<PB3)); }
DDRB &=~ (1<<PB2); _delay_us(10);
DDRD |=
((1<<PD4)|(1<<PD5)|(1<<PD6)|(1<<PD7)); Dip = PIND;
DDRD &=~ Dip = Dip & 0b00000011;
((1<<PD0)|(1<<PD1)|(1<<PD2)|(1<<PD3));
//DDRD |= ((1<<PD0)|(1<<PD1)); if(Dip==1){
DDRC |= SPI_Write(1);
((1<<PC2)|(1<<PC3)|(1<<PC4)|(1<<PC5)); }
DDRC &=~ (1<<PC6); if(Dip==2){
PORTA = 0x00; SPI_Write(2);
PORTB &=~ ((1<<PB0)|(1<<PB1)|(1<<PB3)); }
PORTB |= (1<<PB2); if(Dip==3){
PORTD &=~ SPI_Write(3);
((1<<PD4)|(1<<PD5)|(1<<PD6)|(1<<PD7)); }
PORTD |= }
((1<<PD0)|(1<<PD1)|(1<<PD2)|(1<<PD3)); }
PORTC &=~
((1<<PC2)|(1<<PC3)|(1<<PC4)|(1<<PC5)); void barrido(int numero){
//DDRD &=~ ((1<<PD0)|(1<<PD1)); int auxiliar;
PORTC |= (1<<PC6); for(char i=0;i<4;i++){
//Configurar las interrupciones auxiliar = numero;
EICRA = 0b00101010; auxiliar =numero%10;
EIMSK = 0b00000111; numero = numero/10;
PORTD |=
//ConfiguracióN SPI ((1<<PD4)|(1<<PD5)|(1<<PD6)|(1<<PD7));
SPI_Init(); PORTA = display[auxiliar];
ds1307_init(); PORTD = (PORTD &~ (1<<(i+4)));
SS_Enable; _delay_ms(10);
}
sei(); }
/* Replace with your application code */
while (1) ISR(INT0_vect){
{ if((PINC & (1<<PC6)) == 0){
if(change==0){
ds1307_getdate(&year,&month,&day,&hour,&mi hour++;
nnts,&seconts); }
if(change==1){ Código Micro Esclavo
minnts++; /*
} * Micro_Esclavo.cpp
}else{ *
if(change==0){ * Author : jairo
month++; */
}
if(change==1){ #define F_CPU 5000000L
day++; #include <avr/io.h>
} #include <util/delay.h>
#include <stdio.h>
}
#include <SPI_Slave_H_file.h>
ds1307_setdate(year,month,day,hour,minnts, #include <string.h>
seconts);
} uint8_t orden;
uint8_t conteo;
ISR(INT1_vect){
if(change==0){ int main(void)
change=1; {
DDRA = 0xff;
}else if(change=1){
PORTA = 0x00;
change=0; SPI_Init();
}
} while (1)
{
ISR(INT2_vect){ orden=SPI_Receive();
if((PINC & (1<<PC6)) == 0){ if(orden == 1){
if(change==0){ PORTA = 0b00000001;
_delay_ms(50);
hour--;
PORTA = 0b00000010;
} _delay_ms(50);
if(change==1){ PORTA = 0b00000100;
minnts--; _delay_ms(50);
} PORTA = 0b00001000;
}else{ _delay_ms(50);
if(change==0){ PORTA = 0b00010000;
month--; _delay_ms(50);
PORTA = 0b00100000;
}
_delay_ms(50);
if(change==1){ PORTA = 0b01000000;
day--; _delay_ms(50);
} PORTA = 0b10000000;
} _delay_ms(50);
ds1307_setdate(year,month,day,hour,minnts, PORTA = 0b01000000;
seconts); _delay_ms(50);
} PORTA = 0b00100000;
_delay_ms(50);
PORTA = 0b00010000;
_delay_ms(50);
PORTA = 0b00001000;
_delay_ms(50);
PORTA = 0b00000100;
_delay_ms(50);
PORTA = 0b00000010;
_delay_ms(50);
}
if(orden == 2){
PORTA = conteo;
conteo++;
_delay_ms(100);
}
if(orden == 3){
PORTA = conteo;
conteo--;
_delay_ms(100);
}
}
}
Circuito Implementado

También podría gustarte