mikroBasic: stuck with pointers

General discussion on mikroBasic PRO for PIC.
Post Reply
Author
Message
vladgrijo
Posts: 7
Joined: 16 Feb 2020 03:29

mikroBasic: stuck with pointers

#1 Post by vladgrijo » 17 Jul 2020 04:11

Hi everyone,

I am in trouble with pointers in mikroBasic. I'm trying to convert the mikroC code below. The main problem is adapting the variables definitions and the functions using pointers in mikroBasic (bold marked). Can anyone help me? Regards.


void EEPROM_Write_byte(unsigned char address, unsigned char writing_data)
{
char STATUS_GIE = 0;
EEADR = address;
EEDATA = writing_data;
EECON1.EEPGD = 0;
EECON1.CFGS = 0;
EECON1.WREN = 1;
STATUS_GIE = INTCON.GIEH;
INTCON.GIEH = 0;
EECON2 = 0x55;
EECON2 = 0xAA;
EECON1.WR = 1;
while(EECON1.WR == 1);
INTCON.GIEH = STATUS_GIE;
EECON1.WREN = 0;

}

unsigned char EEPROM_Read_byte(unsigned char address)
{
EEADR = address;
EECON1.CFGS = 0;
EECON1.EEPGD = 0;
EECON1.RD = 1;
asm nop;
asm nop;
return EEDATA;
}

void EEPROM_Write_array(unsigned char address, unsigned char amount_byte, unsigned char *w_data)
{
char count;
for(count = 0; count < amount_byte; ++count)
{
EEPROM_Write_byte(address+count, *w_data);
++w_data;
}
}

void EEPROM_Read_array(unsigned char address, unsigned char amount_byte,unsigned char *r_data)
{
char count;
for(count = 0; count < amount_byte; ++count)
{
*r_data = EEPROM_Read_byte(address+count);
++r_data;
}
}

void main() {

unsigned char w_txt[] = {0,1,0,1,0,1,0,1};
unsigned char r_Txt[8];
char count;


TRISD = 0;
PORTD = 0;

//Writing and Reading EEPROM test

EEPROM_Write_array(0,8, w_Txt);
Delay_ms(25);

EEPROM_Read_array(0, 8, r_Txt);

for(count = 0; count < 8; ++count)
{
PORTD = r_Txt[count];

Delay_ms(1000);
}
}

User avatar
stefan.filipovic
mikroElektronika team
Posts: 1135
Joined: 18 Dec 2018 10:30

Re: mikroBasic: stuck with pointers

#2 Post by stefan.filipovic » 17 Jul 2020 11:28

Hi,

Welcome to the MikroE forum.

I suggest you check the project from the following path: C:\Users\Public\Documents\Mikroelektronika\mikroBasic PRO for PIC\Examples\Development Systems\EasyPic7\EEPROM (I2C)\I2C Advanced
There's a similar function for reading multiple bytes called "EEPROM_24C02_RdSeq", I believe you can get an idea from there.

Also, I suggest you read the following section from the compiler help file (F1): mikroBasic PRO for PIC Language Reference > Types > Derived Types > Pointer Arithmetic.

Kind regards,
Stefan Filipović

vladgrijo
Posts: 7
Joined: 16 Feb 2020 03:29

Re: mikroBasic: stuck with pointers

#3 Post by vladgrijo » 17 Jul 2020 13:36

Thank you Stefan, I will follow your suggestions.
Best regards,
Vladimir

Post Reply

Return to “mikroBasic PRO for PIC General”