This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

#define COUNT 2000

can any one give me the meaning of following line

#define COUNT  2000
#define KEY2    0x2F
#define KEY1    0xF8

COUNT,KEY2,KEY1 are the name's given which we going to use next in the prog. but what is 2000,0x2F,0xF8 is address i.e memory location or simply just value.

Parents
  • i've been trying to write to an address location in serial flash and read it back,
    This program works for some addresses, not all,
    could you help me with what the problem is,

    #include<reg51.h>
    #include<stdio.h>
    
    sbit si = P1^1;  // bits of flash controlled thru Port1 pins  of 8051
    // SI= Serial IN
    sbit SCK = P1^3;  // S clock
    sbit SO = P1^5;   // Serial Out
    sbit ce = P1^0;   // Chip Enable
    
    unsigned char Get_Byte();
    void Send_Byte(unsigned char b_out);
    void E_WRSR();
    // unsigned char Read_Status_Register();
    void WREN();
    void Byte_Program();
    void Delay();
    unsigned char Read_Func();
    // unsigned char Read_ID();
    
            unsigned char i, SR_byte, r_byte;
    
    void main(void){
    ce = 1;
    SCK = 0;
    TMOD = 0x20;    // timer 1,mod 2
    TH1 = -3;               // 9600 baud
    SCON = 0x50;
    TR1 = 1;
    TI = 1;
    
            Delay();
            Byte_Program();   // Writes to flash
            ce = 0;
            Read_Func();      // reads from flash
    }
    
    unsigned char Get_Byte(){    // sending 8 bitword thru Single pin serially,
            unsigned char i=0, in=0, temp=0;
            for(i=0;i<8;i++){
                    in = (in << 1);
                    temp = SO;
                    SCK = 1;
                    if (temp == 1){
                            in = in | 0x01;
                    }
                    SCK = 0;
            }
            return in;
    }
    void Send_Byte(unsigned char b_out){
            for(i=0;i<8;i++){
                    if((b_out & 0x80) == 0x80)
                            si = 1;
                    else
                            si = 0;
                            SCK = 1;
                            b_out = (b_out << 1);
                            SCK = 0;
            }
    }
    
    void E_WRSR(){
            ce = 0;
            Send_Byte(0x50);                // enable Status Reg
            ce = 1;
            Delay();
            ce = 0;
            Send_Byte(0x01);                // select write to status register
            Send_Byte(0x00);                // (BPL = 0, mode 00, None of memory protected)
            ce = 1;
    }
    void WREN(){   // Write Enable operation in stauts reg.
            ce = 0;
            Send_Byte(0x06);
            ce = 1;
    }
    
    unsigned char Read_Func(){
            ce = 0;
            Send_Byte(0x03);                                                // Read CMD
    
            Send_Byte(0x00);                                        // Sending address bytes
            Send_Byte(0x21);
            Send_Byte(0x94);
    
            r_byte = Get_Byte();
            SBUF = r_byte;
            P1 = r_byte;
            while(TI){
            }
            TI = 0;
    
            ce = 1;
            return r_byte;
    }
    
    void Byte_Program(){
            E_WRSR();
            WREN();
    
            ce = 0;
            Send_Byte(0x02);        // Byte Program CMD
    
            Send_Byte(0x00);        // sending 3 address bytes
            Send_Byte(0x21);
            Send_Byte(0x94);
    
            Send_Byte(0x05);        // sending ONE databyte which is to be programmed
            Delay();
            ce = 1;
    }
    
    void Delay(){    // gives approx 20 usecond delay
            for(i=0;i<2;i++){
            }
    }
    

    Thanks a ton,

Reply
  • i've been trying to write to an address location in serial flash and read it back,
    This program works for some addresses, not all,
    could you help me with what the problem is,

    #include<reg51.h>
    #include<stdio.h>
    
    sbit si = P1^1;  // bits of flash controlled thru Port1 pins  of 8051
    // SI= Serial IN
    sbit SCK = P1^3;  // S clock
    sbit SO = P1^5;   // Serial Out
    sbit ce = P1^0;   // Chip Enable
    
    unsigned char Get_Byte();
    void Send_Byte(unsigned char b_out);
    void E_WRSR();
    // unsigned char Read_Status_Register();
    void WREN();
    void Byte_Program();
    void Delay();
    unsigned char Read_Func();
    // unsigned char Read_ID();
    
            unsigned char i, SR_byte, r_byte;
    
    void main(void){
    ce = 1;
    SCK = 0;
    TMOD = 0x20;    // timer 1,mod 2
    TH1 = -3;               // 9600 baud
    SCON = 0x50;
    TR1 = 1;
    TI = 1;
    
            Delay();
            Byte_Program();   // Writes to flash
            ce = 0;
            Read_Func();      // reads from flash
    }
    
    unsigned char Get_Byte(){    // sending 8 bitword thru Single pin serially,
            unsigned char i=0, in=0, temp=0;
            for(i=0;i<8;i++){
                    in = (in << 1);
                    temp = SO;
                    SCK = 1;
                    if (temp == 1){
                            in = in | 0x01;
                    }
                    SCK = 0;
            }
            return in;
    }
    void Send_Byte(unsigned char b_out){
            for(i=0;i<8;i++){
                    if((b_out & 0x80) == 0x80)
                            si = 1;
                    else
                            si = 0;
                            SCK = 1;
                            b_out = (b_out << 1);
                            SCK = 0;
            }
    }
    
    void E_WRSR(){
            ce = 0;
            Send_Byte(0x50);                // enable Status Reg
            ce = 1;
            Delay();
            ce = 0;
            Send_Byte(0x01);                // select write to status register
            Send_Byte(0x00);                // (BPL = 0, mode 00, None of memory protected)
            ce = 1;
    }
    void WREN(){   // Write Enable operation in stauts reg.
            ce = 0;
            Send_Byte(0x06);
            ce = 1;
    }
    
    unsigned char Read_Func(){
            ce = 0;
            Send_Byte(0x03);                                                // Read CMD
    
            Send_Byte(0x00);                                        // Sending address bytes
            Send_Byte(0x21);
            Send_Byte(0x94);
    
            r_byte = Get_Byte();
            SBUF = r_byte;
            P1 = r_byte;
            while(TI){
            }
            TI = 0;
    
            ce = 1;
            return r_byte;
    }
    
    void Byte_Program(){
            E_WRSR();
            WREN();
    
            ce = 0;
            Send_Byte(0x02);        // Byte Program CMD
    
            Send_Byte(0x00);        // sending 3 address bytes
            Send_Byte(0x21);
            Send_Byte(0x94);
    
            Send_Byte(0x05);        // sending ONE databyte which is to be programmed
            Delay();
            ce = 1;
    }
    
    void Delay(){    // gives approx 20 usecond delay
            for(i=0;i<2;i++){
            }
    }
    

    Thanks a ton,

Children