#include <p18f4520.h>
#include <delays.h>
#include "myHeader.h"
#include <stdlib.h>
#include <i2c.h>
void highPriorityISR(void);
void SSPISR(void);
unsigned char data=0x22, temp,i=0, data2;
#pragma code high_vector=0x08
void interrupt_at_high_vector(void)
{
_asm GOTO highPriorityISR _endasm
}
#pragma code
#pragma interrupt highPriorityISR
void highPriorityISR() {
if (PIR1bits.SSPIF) {
AckI2C();
SSPISR();
PIR1bits.SSPIF = 0; // Clear the interrupt flag
}
return;
}
void SSPISR(void) {
PORTBbits.RB1=~PORTBbits.RB1;
Delay10KTCYx(255);
}
void main(void)
{
unsigned char sync_mode = 0, slew = 0,slave_address = 0x88,i;
ADCON1=0x0F;
INTCONbits.GIEH = 0;
RCONbits.IPEN = 1; // Enable interrupt priorities
INTCON &= 0x3F; // Globally enable interrupts
PIE1bits.SSPIE = 1; // Enable SSP interrupt
IPR1bits.SSPIP = 1; // Set SSP interrupt priority to high
PIR1bits.SSPIF = 0;
SSPCON2bits.SEN = 1;
SSPCON1bits.CKP = 1;
INTCONbits.GIEH = 1;
ADCON1=0x0f; // Set Port A & E as digital I/O
TRISA = 0b11010111;
TRISB = 0b11000000; // all input
TRISC = 0b10011000;
TRISE = 0b11101100; // bit 1, 2 & 3 of Port A as output
TRISD = 0b00001111; // Port D as output
PORTA = 0b11010000;
PORTB = 0b00000001;
PORTC = 0b11111111;
PORTD = 0b00000000;
PORTE = 0;
Init_LCD();
OpenI2C (SLAVE_7, SLEW_OFF);
SSPADD=0x88;
while(DataRdyI2C()==0);
ReadI2C();
data2=SSPBUF;
while(DataRdyI2C()==0);
ReadI2C();
data2=SSPBUF;
}