We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
my code :
#include <reg52.h> #include <stdio.h> #define uchar unsigned char void main() { uchar value; unsigned int address; uchar *data_buf; TMOD=0X20; // timer 1 mode 2 TH1=0xFD; // 9600 baud at 11.0592MHz TCON=0x40; // start baud rate clock SCON=0x52; // enable RX,TX address=0x01CF; value=0x66; *data_buf=value; printf("\nAddress %04xH Value : %02x",address,*data_buf); while (1); }
This purpose for my pointer that I want to use in my function
//=============================================== // read EEPROM 24lc256 // input : address 16-bit, // return : 0 if write error // 1 if write complete and get data 1 byte from *data_buf //=============================================== bit read_EEPROM(unsigned int addr,unsigned char *data_out) { bit err; uchar data_in; err=0; i2c_start (); if (!i2c_write_one_byte(0xA0)) { if (!i2c_write_one_byte(addr>>8)) { if (!i2c_write_one_byte(addr)) { i2c_stop (); i2c_start (); if (!i2c_write_one_byte(0xA1)) { data_in = i2c_read_one_byte(No_ack); // read and send no ack *data_out = data_in; } else err=1; } else err=1; } else err=1; } else err=1; i2c_stop(); return (err); } void main() { unsigned char data_buf[1]; unsigned char value; . . . if (!read_EEPROM(0x1234,&data_in)) { value=data_buf[0]; printf("Read %2bX OK",value); } else printf("Read error"); . . } please help me if it wrong. thanks