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.

  • "How can you write something and have nothing to show?"

    Errr.... use invisible ink?! ;-)

  • " use invisible ink?! " ink, on PC or 8051 ...

    i mean, output for the program,

  • 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,

  • Actually, it works for an address, when we write to the same location again, or write to the next location, the program does not work,
    Is there something more to be added,

    When i write Auto address increment on the same lines,
    it does not write,

    Would you please say wat could be the mistake,

  • "Sarcastically, of course,"

    Yes, of course; in keeping with the tone that you set!

  • in serial flash

    1) I have no idea how this ended up in a thread about "#define COUNT 2000" why did you hijack thais thread instead of starting a new?

    2) there is no such thing as general "serial flash", if you do not specify the chip (e.g. AT1234 serial flash) (and give a link to the datasheet) nobody can help you

    Erik

  • Sorry,
    i didnt mean to hijack any thread,

    shd have started a new one,
    ok

    rgds,
    HannaH.

  • Sorry,
    for the long delay in replying,
    was into reviewing basics in C as Mr. Andy said,
    it took some delay to convey the same within a short time,
    Guess i am taking more time in a bid to being polite,

    Hope its not being misunderstood,

    Here are the details of the chip, Serial Flash SST25VF512
    Datasheet at : www.sst.com/.../S71192.pdf

  • "I didnt mean to hijack any thread"

    But you did!

    "shd have started a new one"

    No! Not another one!

    You already have three threads running on exactly the same topic!

    http://www.keil.com/forum/docs/thread8478.asp
    http://www.keil.com/forum/docs/thread8507.asp
    http://www.keil.com/forum/docs/thread8346.asp

  • What do you exactly mean by "hijacking" a thread?
    "HI-JACK" a THREAD, Pleeease,

    All along have been working on the same project,
    so much for your research on the threads,

    Did you happen to see that they were on different topics all related to the same thing?

    For instance,
    http://www.keil.com/forum/docs/thread8507.asp
    was about 'Accessing absolute memory locations'

    http://www.keil.com/forum/docs/thread8478.asp was as you see, what was wrong with the program, i was not getting the output, you guessed or suggested there could be a mismatch in speed of PC and chip,

    Eric said rightly, "why did you hijack THIS thread instead of starting a new?"

    While searching for answers from others i had totally overlooked the fact that it was started by somebody else,

  • What do you exactly mean by "hijacking" a thread?
    "HI-JACK" a THREAD, Pleeease,

    All along have been working on the same project,
    so much for your research on the threads,

    Did you happen to see that they were on different topics all related to the same thing?

    For instance,
    http://www.keil.com/forum/docs/thread8507.asp
    was about 'Accessing absolute memory locations'

    http://www.keil.com/forum/docs/thread8478.asp was as you see, what was wrong with the program, i was not getting the output, you guessed or suggested there could be a mismatch in speed of PC and chip,

    Eric said rightly, "why did you hijack THIS thread instead of starting a new?"
    Agree with him,
    While searching for answers from other threads i had totally overlooked the fact that it was started by somebody else, so wrote in my program in Mr. Danish's thread on an impulse,

    are you moderating for KEIL FORUM?

  • What do you exactly mean by "hijacking" a thread?

    what does "i've been trying to write to an address location in serial flash and read it back," have to do with #define COUNT 2000

  • " #define " is a control directive.It is the C equivalent to assembly directive " equ ".
    What it does is somthing like this :
    During PRE-PROCESSING, the Cross compiler passes the program file.Then the ' #define X Y' would represent every X in the program body with Y. As simple as this.....
    Debasish