this is the driver for ade7753:
#ifndef ADE7753_CS
#define ADE7753_CS RC0
#endif
//The following memory locations come from the ADE7758 datasheet
//Name Address No. Bits
#define _WAVEFORM 0x01 //24
#define _AENERGY 0x02 //24
#define _RAENERGY 0x03 //24
#define _LAENERGY 0x04 //24
#define _VAENERGY 0x05 //24
#define _RVAENERGY 0x06 //24
#define _LVAENRGY 0x07 //24
#define _LVARENERGY 0x08 //16
#define _MODE 0x09 //16
#define _IRQEN 0x0A //16
#define _STATUS 0x0B //16
#define _RSTSTATUS 0x0C //16
#define _CH1OS 0x0D //8
#define _CH2OS 0x0E //8
#define _GAIN 0x0F //8
#define _PHCAL 0x10 //6
#define _APOS 0x11 //16
#define _WGAIN 0x12 //12
#define _WDIV 0x13 //8
#define _CFNUM 0x14 //12
#define _CFDEN 0x15 //12
#define _IRMS 0x16 //24
#define _VRMS 0x17 //24
#define _IRMSOS 0x18 //12
#define _VRMSOS 0x19 //12
#define _VAGAIN 0x1A //12
#define _VADIV 0x1B //8
#define _LINECYC 0x1C //16
#define _ZXTOUT 0x1D //12
#define _SAGCYC 0x1E //8
#define _SAGLVL 0x1F //8
#define _IPKLVL 0x20 //8
#define _VPKLVL 0x21 //8
#define _IPEAK 0x22 //24
#define _RSTIPEAK 0x23 //24
#define _VPEAK 0x24 //24
#define _RSTVPEAK 0x25 //24
#define _TEMP 0x26 //8
#define _PERIOD 0x27 //16
#define _TMODE 0x3D //8
#define _CHKSUM 0x3E //6
#define _DIEREV 0x3F //8
#byte POSTINC0= getenv("SFR
OSTINC0")
#word FSR0= getenv("SFR:FSR0L")
void read_ADE7753(int16 *val,int8 addres,int8 len){
ADE7753_CS=0;
spi_write(0x80&addres);
FSR0=val;
do{
Delay_us(4);
POSTINC0=spi_read();
}while(--len);
ADE7753_CS=1;
}
void write_ADE7753(int32 val,int8 addres,int8 len){
ADE7753_CS=0;
spi_write(0x80&addres);
do{
Delay_us(4);
spi_write(*val++);
}while(--len);
ADE7753_CS=1;
}
and this is the code to read the ade7753:
#include <18f4550.h> //pic a utilizar
#DEVICE ADC=10
#include <Puertos.c>
#fuses XT,NOMCLR,NOWDT,NOPROTECT,NOLVP,NODEBUG,USBDIV,PLL1,CPUDIV1,NOVREGEN,NOPBADEN // fuse con cristal 48Mhz
#use delay (clock=48M) //Fosc=48Mhz
#define LCD_DATA4 PIN_B0
#define LCD_DATA5 PIN_B1
#define LCD_DATA6 PIN_B2
#define LCD_DATA7 PIN_B3
#define LCD_ENABLE_PIN PIN_B4
#define LCD_RS_PIN PIN_B5
#define LCD_RW_PIN PIN_B6
#include <lcd.c> //libreria manejo lcd
#include "ADE7753_Driver.c"
int32 Vrms;
void main(){
TRISA=0;
setup_spi(SPI_MASTER | SPI_H_TO_L | SPI_CLK_DIV_16 );
lcd_init(); //Iniciamos el LCD
lcd_putc("Vrms="); //Escribimos Vrms en el LCD
while(1){
read_ADE7753(&Vrms,_VRMS,3); //Leemos el Vrms del ADE7753
printf(lcd_putc,"%Lu",Vrms); //Lo imprimimos en la pantalla
lcd_gotoxy(6,1); //Enviamos el Cursor a la posicion 6,1
}
}
Added after 3 minutes:
actually i have an error in word in line of the driver:
#word FSR0= getenv("SFR:FSR0L")
thanks!