I am using 6164 external RAM. To write data to memory i need to bring /CE1 and /WE(active low) low and to read data from i need to enable /CE1 and /OE (active low). I want to know where do i need place the read and write functions in my source code. I am placing my source code which write variables to external RAM and makes port pin 3.0 high and low after a delay of 1s.this program has not been compiled. just tell me where to place the chip select functions in the code.
#include "absacc.h" // header file acessing external RAM{xbyte/xdata) #include<reg52.h>
#define i_variable XBYTE[0xA00A]
sbit test_pin=P1^0; sbit write_pin=P3^6; sbit read_pin=P3^7; sbit clock_pin=P3^5; sbit RX_pin=P3^0; sbit TX_pin=P3^1;
void high_low(void); void port_init(void); void delay_1ms(void); void delay_9ms(void); void enable_external_ram(void); void main(void) { test_pin=0; while (1) { high_low(); } }
void high_low(void) { xdata int i; //data is written at address 0xA002 i=i_variable; // The variable i is stored at the location at specified by XBYTE test_pin=1; for (i=0;i<=100;i++) { delay_1ms(); delay_9ms(); } test_pin=0; for (i=0;i<=100;i++) { delay_1ms(); delay_9ms(); } }
void read_external_ram(void) { //This function reads the external RAM memory. To read the external Ram memory the /CS5 // and /OE pin need to be enabled. //The write pin is inactive when the read operation is performed. P2=0x00; read_pin=0; //Enable A13, A14,A15 to de-select /CS5 //which is chip select to 6164 EX RAM }
void write_external_ram(void) { //This function writes to external RAM memory. To write the external Ram memory the /CS5 // and /OE pin need to be disabled. //The read pin is inactive when the read operation is performed. P2=0x00; //setting port0 as output P2=0x05; //set A13, A14,A15 to select /CS5 which is addressed to 6164 EX RAM write_pin=1; //active low for 6164 input for 6164 is 0 }
void delay_1ms(void) { // Configure Timer 0 as a 16-bit timer TMOD &= 0xF0; // Clear all T0 bits (T1 left unchanged) TMOD |= 0x01; // Set required T0 bits (T1 left unchanged) ET0 = 0; // No interupts // Values for 1 ms delay TH0 = 0xF8; // Timer 0 initial value (High Byte) TL0 = 0x2F; // Timer 0 initial value (Low Byte) TF0 = 0; // Clear overflow flag TR0 = 1; // Start timer 0 while (TF0 == 0); // Loop until Timer 0 overflows (TF0 == 1) TR0 = 0; // Stop Timer 0 } void delay_9ms(void) { // Configure Timer 0 as a 16-bit timer TMOD &= 0xF0; // Clear all T0 bits (T1 left unchanged) TMOD |= 0x01; // Set required T0 bits (T1 left unchanged) ET0 = 0; // No interupts // Values for 9ms delay TH0 = 0xB9; // Timer 0 initial value (High Byte) TL0 = 0xAF; // Timer 0 initial value (Low Byte) TF0 = 0; // Clear overflow flag TR0 = 1; // Start timer 0 while (TF0 == 0); // Loop until Timer 0 overflows (TF0 == 1) TR0 = 0; // Stop Timer 0 }