Yes, this is my code
#define Mesure
#define MODBUS_DEBUG_PRINT 1 // define to 1 to print transactions
#define CINBUFSIZE 31
#define COUTBUFSIZE 31
#define MODBUS_PORT C
#define _RS485 485
#define SERIAL_PORT_MODE _RS485
#use modbus_master.lib
void brdInit();
int MBM_Send_ADU ( char *Packet, int ByteCount );
int MBM_Rcv_Resp ( char * Packet );
void serInit ( void );
void ser485Tx( void ) ;
void ser485Rx( void );
main ()
{ int b,p, RegsValue[50];
brdInit();
serInit();
b = MBM_ReadRegs(5, &RegsValue[0], 0x1000, 30 ); // read reg 0
for ( p=0; p<50; p++ )
printf("%d,
", b);
while(1);
}
/* START FUNCTION DESCRIPTION ********************************************
MBM_Send_ADU
END DESCRIPTION **********************************************************/
void brdInit()
{ WrPortI(PCFR, &PCFRShadow, PCFRShadow&0xEA); //clear bit 4,2,0 to normal function
//bits 5,3,1 normally inputs
WrPortI(PCDR, &PCDRShadow, PCDRShadow|0x15); //set bits 4,2,0 high
WrPortI(PDCR, &PDCRShadow, 0x00); //clear all bits to pclk/2
WrPortI(PDFR, &PDFRShadow, 0x00); //clear all bits to normal function
WrPortI(PDDCR, &PDDCRShadow, 0x00); //clear all bits to drive high and low
WrPortI(PDDR, &PDDRShadow, 0x0b); //set bits 3,1,0 high
WrPortI(PDDDR, &PDDDRShadow, 0x8b); //set bits 7,3,1,0 to output, rest inputs
WrPortI(PECR, &PECRShadow, 0x00); //clear all bits to pclk/2
WrPortI(PEFR, &PEFRShadow, 0x00); //clear all bits to normal function
WrPortI(PEDR, &PEDRShadow, 0xc0); //set bits 7,6 output high
WrPortI(PEDDR, &PEDDRShadow, 0xc8); //set bits 7,6,3 to output, rest inputs
WrPortI(PFCR, &PFCRShadow, 0x00); //clear all bits for pclk/2
WrPortI(PFFR, &PFFRShadow, 0x00); //clear all bits for normal function
WrPortI(PFDR, &PFDRShadow, 0x0f); //set bits 7,6,5,4 output low
WrPortI(PFDDR, &PFDDRShadow, 0xf0); //set bits 7,6,5,4 to output
WrPortI(PGCR, &PGCRShadow, 0x00); //clear all bits for pclk/2
WrPortI(PGFR, &PGFRShadow, 0x00); //clear all bits for normal function
WrPortI(PGDDR, &PGDDRShadow, 0x30); //set bits 5,4 to output, clear rest to input
WrPortI(PGDCR, &PGDCRShadow, 0x00); //clear all bits to drive output
WrPortI(PGDR, &PGDRShadow, 0x30); //set bit 5,4 high
WrPortI(PBDR, &PBDRShadow, PBDRShadow|0xfc); //set all bits high, except bit 1,0
WrPortI(PBDDR, &PBDDRShadow, PBDDRShadow|0xfc); //set all bits to output, except bit 1,0
WrPortI(PADR, &PADRShadow, 0xff); //set to output all high
WrPortI(SPCR, &SPCRShadow, 0x8c); //Enables Auxiliary i/o bus
}
void serInit ( void )
{
serCopen (9600);
}
void ser485Tx( void )
{
#asm
ld a,(PDDRShadow)
set 7,a ;set bit 7
ld (PDDRShadow),a
ioi ld (PDDR),a ;set PD7 high
#endasm
}
void ser485Rx( void )
{
#asm
ld a,(PDDRShadow)
set 7,a ;set bit 7
ld (PDDRShadow),a
ioi ld (PDDR),a ;set PD7 high
#endasm
}
int MBM_Send_ADU ( char *Packet, int ByteCount )
{ auto unsigned CRCvalue;
auto unsigned long Endtime;
int i;
// insert CRC
CRCvalue = MODBUS_CRC ( Packet, ByteCount );
Packet[ByteCount+1] = CRCvalue; // store low byte
Packet[ByteCount] = CRCvalue>>8; // store high byte
ByteCount+=2; // adjust for CRC
#ifdef MODBUS_DEBUG_PRINT & 0
printf ( “Tx:” );
for ( i=0; i