??? 05/03/10 12:41 Read: times |
#175618 - Corrected code Responding to: ???'s previous message |
dear andy,
How can i pass the three variables to the function. I have to pass the starting address ( for eeprom), number of places in the eeprom that have to be written and the pointer to the first character whic is a pointer. I have removed the parenthesis but still the same result /**************************EEPROM.C**************************************/ #include<reg51.h> #include<generic.h> #include<serial.h> #include<main.h> #include<I2C.h> #include<eeprom.h> unsigned char i = 0,j = 0,k = 0; unsigned char add_L_1 = 0,add_L_2 = 0,add_H_1 = 0,add_H_2 = 0; bit write_now =0,s_add_rd_flag = 0; unsigned char read_add_L = 0,read_add_H = 0,write_add_L = 0,write_add_H = 0; /*=============================================================================*/ unsigned char single_address_read(unsigned int single_read_add) { unsigned char single_read_data = 0; GREEN_LED = 0; read_add_L = single_read_add; read_add_H = single_read_add >> 8; i2c_transmit_start(); i2c_transmit_byte(0xA0); i2c_transmit_byte(read_add_H); i2c_transmit_byte(read_add_L); i2c_transmit_restart(); i2c_transmit_byte(0xA1); single_read_data = i2c_receive_byte(I2C_ACK); i2c_transmit_stop(); GREEN_LED = 1; return(single_read_data); } void single_address_write(unsigned int single_write_add,unsigned char single_write_data) { YELLOW_LED = 0; write_add_L = single_write_add; write_add_H = single_write_add >> 8; msec_wait(1); i2c_transmit_start(); i2c_transmit_byte(0xA0); i2c_transmit_byte(write_add_H); i2c_transmit_byte(write_add_L); i2c_transmit_byte(single_write_data); i2c_transmit_stop(); YELLOW_LED = 1; } void burst_mode_write(unsigned int start_address_1, unsigned char no_of_places_1, unsigned char *p)<< { YELLOW_LED = 0; add_L_1 = start_address_1; add_H_1 = start_address_1 >> 8; msec_wait(10); i2c_transmit_start(); i2c_transmit_byte(0xA0); i2c_transmit_byte(add_H_1); i2c_transmit_byte(add_L_1); for(i = 0; i < no_of_places_1; i++,p++) {i2c_transmit_byte(*p);} i2c_transmit_stop(); YELLOW_LED = 1; } void burst_mode_read(unsigned int start_address_2, unsigned char no_of_places_2, unsigned char *p)<< { GREEN_LED = 0; add_L_2 = start_address_2; add_H_2 = start_address_2 >> 8; i2c_transmit_start(); i2c_transmit_byte(0xA0); i2c_transmit_byte(add_H_2); i2c_transmit_byte(add_L_2); i2c_transmit_restart(); i2c_transmit_byte(0xA1); for(j = 0; j < (no_of_places_2-1); j++,p++) { *p = i2c_receive_byte(I2C_NAK); } *p = i2c_receive_byte(I2C_ACK); i2c_transmit_stop(); GREEN_LED = 1; } /************************************************************************/ /**************************main.c**************************************/ #include<reg51.h> #include<generic.h> #include<serial.h> #include<main.h> #include<I2C.h> #include<eeprom.h> unsigned char add_L = '/0',add_H = '/0'; unsigned char dta; bit single_read = 0,single_write = 0,burst_read = 0,burst_write = 0; unsigned char data_to_eeprom[64] = 0;//{1,2,3,4,5,6,7,8,9,10,1,2,3,4,5,6,7,8,9,10}; unsigned char data_from_eeprom[64]= 0; unsigned char loca_data_1 = 33,loca_data_2 = 33; /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ void serial_interrupt(void) interrupt 4 { if(TI) { TI = 0; } if(RI) { if(SBUF == '!') single_read = 1;//function called to read a single byte else if(SBUF == '@') single_write = 1;//function called to write a single byte else if(SBUF == '#') burst_read = 1;//function called to read in bust mode else if(SBUF == '$') burst_write = 1;//function called to write in bust mode RI = 0; } } void main(void) { sec_wait(1); initialize_serial(); msec_wait(100); while(1) { if(single_read == 1) { SBUF = single_address_read(1280);//single byte read using a static address for testig single_read = 0; } if(single_write == 1) { single_address_write(1280, loca_data_1);//single byte write using a static address for testig single_write = 0; if(loca_data_1 < 127) loca_data_1++; else loca_data_1 = 0; } if(burst_read == 1) { burst_mode_read(1280, 5, &data_from_eeprom); SBUF = data_from_eeprom[0];msec_wait(1); SBUF = data_from_eeprom[1];msec_wait(1); SBUF = data_from_eeprom[2];msec_wait(1); SBUF = data_from_eeprom[3];msec_wait(1); SBUF = data_from_eeprom[4];msec_wait(1); burst_read = 0; } if(burst_write == 1) { data_to_eeprom[0] = loca_data_2; data_to_eeprom[1] = loca_data_2; data_to_eeprom[2] = loca_data_2; data_to_eeprom[3] = loca_data_2; data_to_eeprom[4] = loca_data_2; loca_data_2++; burst_mode_write(1280, 5, &data_to_eeprom); burst_write = 0; } } } /************************************************************************/ |
Topic | Author | Date |
Passing a pointer to a function | 01/01/70 00:00 | |
'C' textbook time! | 01/01/70 00:00 | |
Char-red | 01/01/70 00:00 | |
Typo![]() | 01/01/70 00:00 | |
Corrected code | 01/01/70 00:00 | |
'C' textbook time! | 01/01/70 00:00 | |
Array name is already a pointer. | 01/01/70 00:00 |