??? 01/27/12 04:56 Read: times |
#185695 - interfacing with 93c66 Responding to: ???'s previous message |
friends this coad is not store data in external memory.i get coad of 93c46 from 8052 library and try to edit for 93c66 but i do more effort but this coad is not storing data in external memory.
so plz check it . /*****************************************/ /* 0000 to 9999 Display */ /* with 4094 */ /* */ /*****************************************/ #include <REGX51.H> unsigned char buffer[5]; unsigned int num1,num2,num3,num4,num5,test=0; unsigned int num=0; void Initialize(void); // Function to Initiallize Variables void ROM(void); // Function to deal with EEPROM(93C46B) void ERASE_WRITE (void); // Function for write cycle of 93C46B int ROM_WRD; // ROM_WRD acts as a IO buffer for the EEPROM char ROM_OPAD; // ROM_OPAD keeps current OPCODE+ADDRESS for the EEPROM sbit CLK = P2^1; sbit DIN = P2^0; sbit strobe = P2^2; sbit ROM_CS = P1^4; // P1.4 EEPROM CS pin of 93C46B is connected here sbit ROM_DO = P1^7; // p1.5 EEPROM DI pin of 93C46B is connected here sbit ROM_DI = P1^6; // P1.6 EEPROM DO pin of 93C46B is connected here sbit ROM_CK = P1^5; // P1.7 EEPROM CK pin of 93C46B is connected here sbit up = P1^0; sbit down = P1^1; sbit reset = P1^2; sbit set = P1^3; char code segment[11]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x39}; void delay(int num) // timer { int i; for(i=0;i<num;i++) { TH0=0xfc; TL0=0x67; } } void Initialize(void) { ROM_DO =1; // Get Ready to receive data on this pin ROM_OPAD=0x80; // Make it a read command so nothing is erased ROM(); /* Call to ROM Routine to cancel out false start bit given because when 8051 starts all its pins are at logic 1 but ROM_CS = ROM_DI = ROM_CK = 1 means start bit for ROM We Shall keep ROM_CK = 0 in future and this is done at the end of ROM() function*/ // } void ROM(void) // { // char i; // Variable to count in loops unsigned char ROM_OP=ROM_OPAD; // Copy ROM OPCODE from OPCODE+ADDRESS byte ROM_OP&=0xC0; // Decode ROM OPCODE (i.e. Remove Address) if (!ROM_OP) // OPCODE = 00? { // ROM_OP=ROM_OPAD & 0x30; // Mask so only first two bits of the Address field of ROM_OPAD Remain if (ROM_OP == 0x10) // A WRAL command? ROM_OP=0x100; // Convert it to a write Command to send 16 bits to EEPROM after OPAD } // //-------------------Start Bit---------------------------// ROM_CS=1; // Select the ROM Chip ROM_DI=1; // Start bit ready ROM_CK=1; // Start bit given by Positive edge of clock //----------------------OPCODE+ADDRESS-------------------// for(i=0;i<8;i++) // Give OPAD (Opcode + Address) Byte to EEPROM { // ROM_CK=0; // Get ROM clock ready ROM_OPAD<<=1; // Left-shift ROM OPCODE+ADDRESS by one bit. Carry = MSB ROM_DI=CY; // Put the carry bit onto ROM Data In ROM_CK=1; // Give this bit to ROM by Positive edge of clock } // //------------------------Write--------------------------// if(ROM_OP==0x100) // ROM OPCODE is for WRITE or WRAL(Write ALL) instruction? { // for(i=0;i<16;i++) // Give the 16 bit Data to the ROM { // ROM_CK = 0; // Get ROM clock ready ROM_WRD <<= 1; // Left-shift ROM_WRD by one bit. Carry = MSB ROM_DI = CY; // Put the carry bit into ROM Data In ROM_CK = 1; // Give this bit to ROM by Positive edge of clock } // } // //------------------------READ--------------------------// else if(ROM_OP==0x80 ) // ROM OPCODE for Read Instruction? { // ROM_WRD=0; // Initiallize ROM_WRD to store read DATA for(i=0;i<16;i++) // Read the 16 bit Data from the ROM { // ROM_CK = 0; // Get ROM clock ready ROM_CK = 1; // Give Positive edge of clock for ROM to put MSB at ADDRESS on DO ROM_WRD <<=1; // Left_shift the ROM_WRD to make room for new bit to ADD if (ROM_DO) // A '1'? ROM_WRD++; // Add '1'to ROM_WRD } // } // ROM_CS=0; // Unselect the ROM chip ROM_DI=0; // Reset the ROM DI ROM_CK=0; // Get Ready for next Start Bit } // void ERASE_WRITE (void) // { // char TEMP; // Temporay storage of a byte TEMP=ROM_OPAD; // Save a copy of user's OPCODE + Address ROM_OPAD=0x30; // EWEN COMMAND for ROM (00¦110000) ROM(); // CALL to ROM Function to send command ROM_OPAD=TEMP; // Restore the copy of user's OPCODE + Address ROM(); // Call to ROM Function for writing the data to respective Location ROM_CS=1; // Select ROM Chip to read status while(!ROM_DO); // Wait for ROM chip to become ready ROM_OPAD=0x00; // EWDS Command (00¦000000) ROM(); // Call to ROM Function to Send command } void write_led() { char i,j; for(j=0; j<5; j++) { for(i=0;i<8; i++) { if(buffer[j]&0x80) DIN = 1; else DIN=0; CLK= 1; buffer[j] <<=1; CLK = 0; } } strobe = 1; ; strobe = 0; } void move_Buffer() { buffer[0] = segment[num1%10]; buffer[1] = segment[num2%10]; buffer[2] = segment[num3%10]; buffer[3] = segment[num4%10]; buffer[4] = segment[num5%10]; } void updatedisplay() { move_Buffer(); write_led(); } void counter() { if(up==0&&down==1) //check if up pin is pressed { test++; num=test; num1=num%10; num=num/10; num2=num%10; num=num/10; num3=num%10; num=num/10; num4=num%10; num5=num/10; if(test==99999) test=0; } if(up==1&&down==0) //check if down pin is pressed { test--; num=test; num1=num%10; num=num/10; num2=num%10; num=num/10; num3=num%10; num=num/10; num4=num%10; num5=num/10; if(test==0) test=99999; } } void re() // reset display { if (reset==0) buffer[4]=buffer[3]=buffer[2]=buffer[1]=buffer[0]=0; } void timer_isr(void) interrupt 1 using 1 { counter(); re(); delay(5000); updatedisplay(); } void main() { Initialize(); TMOD = 0x01; EA = 1; ET0 = 1; TR0 = 1; up = 1; down = 1; reset= 1; set = 1; while(1) { ERASE_WRITE(); ROM(); } } |