// RB7 --> ENTRADA ON/OFF
// RB6 --> ENTRADA ON/OFF
// RB5 --> ENTRADA ON/OFF
// RB4 --> ENTRADA ON/OFF
// RB0/INT -->
// RA0 --> LED STATUS
// RC7 -->
// RC6 -->
// RC5 -->
// RC4 --> SDA
// RC3 --> SCL
// RC2 -->
// RC1 -->
// RD0 --> OUT E
// RD1 --> OUT RS
// RD2 --> OUT RW
// RD3 -->
// RD4 --> OUT D4
// RD5 --> OUT D5
// RD6 --> OUT D6
// RD7 --> OUT D7
//
//
//
////////////////////////////////////////////////////////////////////////////////
#include <16f877A.h> //pic a utilizar
#fuses XT,NOWDT,NOPROTECT,PUT,NOLVP,NOBROWNOUT //ordenes para el programador
#use delay (clock=4000000) //Fosc=4Mhz
#use i2c(MASTER, SDA=PIN_C4, SCL=PIN_C3,FAST,FORCE_HW)
#use fast_io(A)
#use fast_io(B)
#use fast_io(C)
#use fast_io(D)
#use fast_io(E)
#byte port_a = 0x05
#byte port_b = 0x06
#byte port_c = 0x07
#byte port_d = 0x08
#byte port_e = 0x09
int dato=0;
void i2c(int dato)
{
i2c_start(); //condicion de inicio
i2c_write(0xa0); //direccion del esclavo con el que haremos la comunicacion
//A6 A5 A4 A2 A1 A0 R/W -> R/W = 0 escritura; 1 lectura
i2c_write(dato); //enviamos dato
i2c_stop(); //finalizacion de la comunicacion
delay_ms(1000); //introducimos retardo para que no este constantemte escribiendo
}
#INT_TIMER1
void control_timer1(void)
{
output_bit(pin_a0,!input(pin_a0));
set_timer1(3036);
}
void main(void)
{
disable_interrupts(GLOBAL);
set_tris_a(0x00); // RA0 --> LED STATUS
// RA1 -->
// RA2 -->
// RA3 -->
// RA4 -->
// RA5 -->
port_b_pullups(false); // Resistencias de polarización del puerto B
set_tris_b(0xF0); // RB7 -->
// RB6 -->
// RB5 -->
// RB4 -->
// RB3 -->
// RB2 -->
// RB1 -->
// RB0 -->
set_tris_c(0x00); // RC0 -->
// RC1 -->
// RC2 -->
// RC3 --> SCL
// RC4 --> SDA
// RC5 -->
// RC6 -->
// RC7 -->
set_tris_d(0x00); // RD0 --> OUT E
output_d (0x00); // RD1 --> OUT RS
// RD2 --> OUT RW
// RD3 -->
// RD4 --> OUT D4
// RD5 --> OUT D5
// RD6 --> OUT D6
// RD7 --> OUT D7
setup_adc_ports(NO_ANALOGS);
setup_comparator(NC_NC_NC_NC);
setup_timer_1(T1_INTERNAL|T1_DIV_BY_8);
enable_interrupts(INT_TIMER1);
enable_interrupts(GLOBAL);
while(1)
{
delay_ms(2000);
output_bit(pin_d0,1);
dato=0;
i2c(dato);
delay_ms(500);
output_bit(pin_d0,0);
delay_ms(2000);
output_bit(pin_d1,1);
dato=1;
i2c (dato);
delay_ms(500);
output_bit(pin_d1,0);
delay_ms(2000);
output_bit(pin_d2,1);
dato=2;
i2c(dato);
delay_ms(500);
output_bit(pin_d2,0);
delay_ms(2000);
output_bit(pin_d3,1);
dato=3;
i2c(dato);
delay_ms(500);
output_bit(pin_d3,0);
}
}