Microcontroller › 8051 › eeprom 24c02 with 89v51rd2
- This topic has 1 reply, 2 voices, and was last updated 11 years ago by
AJISH ALFRED.
Viewing 2 posts - 1 through 2 (of 2 total)
-
AuthorPosts
-
February 25, 2014 at 12:29 pm #2898
Amit Raijade
Participanthello frnds..
i am using above mentioned modules
i just want to check whether my code is right wrong or will it run…because it is not showing response at the time of viewing response on seven segment display.
here is my code.
#include<reg51.h>sbit sda =P3^7;sbit scl =P3^6;sbit dig0 = P2^1;sbit dig1 = P2^2;sbit dig2 = P2^3;sbit dig3 = P2^4;sbit dig4 = P2^5;sbit dig5 = P2^6;bit flag_wr,flag_rd;unsigned char RxByte = 0;#define PORT_SEVEN_SEG P0 //Output Port#define I2C_SPEED_FACTOR 1#define Crystal_Value 12#define HalfBitDelay (500*Crystal_Value)/(12*I2C_SPEED_FACTOR)void start();void stop();void init();void restart();void ack();void I2C_Write_Byte(byte);unsigned char I2C_Read_Byte(void );void display(unsigned char );void delay(unsigned int d){unsigned int i, limit;limit = d/15;for(i=0;i<limit;i++);}void main(){init(); // Initialize i2c pinsstart(); // Send start bit on i2cI2C_Write_Byte(0x08);RxByte = I2C_Read_Byte(); // Read value from i2cack(); // Send ACK bit on i2cstop(); // Send stop bit on i2c//if(flag_rd)// display(RxByte);while(1);}void init(){sda = 1;scl = 1;}void start(){scl=1;sda=1;delay(HalfBitDelay);sda=0;scl=0;}void stop(){scl=1;sda=0;delay(HalfBitDelay/2);sda=1;}void restart(){scl = 0;delay(HalfBitDelay/2);sda = 1;delay(HalfBitDelay/2);scl = 1;delay(HalfBitDelay/2);sda = 0;delay(HalfBitDelay/2);}void ack(){sda = 0;delay(HalfBitDelay/2);scl = 1;delay(HalfBitDelay/2);scl = 0;delay(HalfBitDelay/2);sda = 1;delay(HalfBitDelay/2);}void I2C_Write_Byte(unsigned char Byte){unsigned char i;for(i=0;i<8;i++){scl=0;delay(HalfBitDelay/2);if((Byte<<i)&0x80)sda=1;elsesda=0;delay(HalfBitDelay/2);scl=1;delay(HalfBitDelay/2);}flag_wr = 1;}unsigned char I2C_Read_Byte(void){unsigned char i, d, RxData = 0;for(i=0;i<8;i++){scl=0; // Make SCK pin lowsda=1; // Don’t drive SDAdelay(HalfBitDelay); // Half bit delayscl=1; // Make SCK pin highdelay(HalfBitDelay/2); // 1/4 bit delayd = sda; // Capture Received BitRxData = RxData|(d<<(7-i)); // Copy it in RxDatadelay(HalfBitDelay/2); // 1/4 bit delay}return RxData; // Return received byteflag_rd = 1;}/*void display(unsigned char RxByte ){dig0 = 0;dig1 = 1;dig2 = 1;dig3 = 1;dig4 = 1;dig5 = 1;PORT_SEVEN_SEG = RxByte; */}on my card there are 6 displays thats why this dig0 to dig5March 1, 2014 at 4:55 am #11135AJISH ALFRED
ParticipantHi,
The code itself dosen’t mean anything. Please share the details of the hardware including circuit diagram and a brief idea about how you expect it to work.
-
AuthorPosts
Viewing 2 posts - 1 through 2 (of 2 total)
- You must be logged in to reply to this topic.