#include <18F4550.h>
#fuses HSPLL,NOWDT,NOPROTECT,NOLVP,NODEBUG,USBDIV,PLL5,CPUDIV1,VREGEN,NOBROWNOUT,NOMCLR
#use delay(clock=48000000)
#define AD7758_CS PIN_A0
#define ADE_DOUT PIN_C7
#define ADE_DIN PIN_B0
#define ADE_CLK PIN_B1
#include "LCD420.c"
int test = 0, i, count;
int ADE_OUT_DATA = 63; //chip version register from datasheet
void main()
{
lcd_init();
printf(lcd_putc,"Ready");
output_high(AD7758_CS);
delay_ms(1000);
while(1)
{
ADE_OUT_DATA = 63;
output_low(AD7758_CS);
delay_us(1);
for(i=1;i<=8;++i)
{
output_high(ADE_CLK);
delay_us(1);
output_bit(ADE_DOUT, shift_left(&ADE_OUT_DATA,1,0));
delay_us(1);
output_low(ADE_CLK);
delay_us(1);
}
output_low(ADE_DOUT);
delay_us(4);
for(i=1;i<=8;++i)
{
output_high(ADE_CLK);
delay_us(1);
shift_left(&test,1,input(ADE_DIN));
output_low(ADE_CLK);
delay_us(1);
}
output_high(AD7758_CS);
lcd_gotoxy(1,1); //data returned from ADE7753
printf(lcd_putc,"Data = %U",test);
lcd_gotoxy(1,2); //Counter to show PIC is working
printf(lcd_putc,"%U",count);
delay_ms(500);
count++;
}
}