Read register in C

This is a discussion on Read register in C within the C Programming forums, part of the General Programming Boards category; In my code I have to read the registers that I it uses, therefore I will use this function Code: ...

  1. #1
    Registered User
    Join Date
    Nov 2007
    Posts
    19

    Read register in C

    In my code I have to read the registers that I it uses, therefore I will use this function
    Code:
    void leesRegister( unsigned char* Register )
    The microcontroller is a Fujitsu MB90F497 and the registers I use are
    Code:
    DDR0;
    DDR2;
    DDR4;
    Is there someone who can help me to find the right structure to read these registers? I have looked up on the internet and the datasheet but not very succesfull. The datasheet can be found here http://www.alldatasheet.co.kr/datash.../MB90F497.html

  2. #2
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    On page 19 [as numbered in the document, not PDF reader's pages]:
    Address 2: 0x4000

    Address 2 is the base-address for extension IO addresses.

    The DDR registers are listed on page 20 of the document.

    To actually access these registers, you need a unsigned char pointer that points to the relevant address:
    Code:
    #define IOBASE 0x4000
    unsigned char *DDR0 = (unsigned char *)(IOBASE + 0x10);
    ...
       unsigned char value = *DDR0;
    ...
    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  3. #3
    Registered User
    Join Date
    Nov 2007
    Posts
    19
    Thank you very much, this is not the whole code I assume? Could you explain the code just a little bit?
    Code:
    (IOBASE + 0x10);
    especially this code above. Thank you in advance

  4. #4
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by Lettin03 View Post
    Thank you very much, this is not the whole code I assume? Could you explain the code just a little bit?
    Code:
    (IOBASE + 0x10);
    especially this code above. Thank you in advance
    IOBASE (which expands to 0x4000) is the address of the IO region according to page 19 of the document. DDR0 has the address 0x10 according to the following page, so we add that to the base-address. [Could make a further define for that if we wish, but it seems meaningless].

    Once you have those two together, you know the address of that register, right? So now we just need to create a pointer, whcih is the bit that I do in the "unsigned char *DDR0 = (unsigned char *)(IOBASE + 0x10);". The cast is there to tell the compiler "I know this is not a pointer in your opinion, but let's make it a pointer anyways" [IOBASE + 0x10 is not a pointer in the compilers opinion, since it's just integer values].

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  5. #5
    Registered User
    Join Date
    Nov 2007
    Posts
    19
    Oke that part I understand now, thank you for the explenation. However, don't I have to declare value? and the argument Register is unused. After compiling I get an error
    Code:
    E4159C: redefinition of identifier `value'
    I0001C: previous declaration of `value': "c:\documents and settings\gr_mstag2\desktop\lettinga_henk\project\
            software\leesregister.c", line 6
    W1021C: parameter `Register' unused in function `leesRegister'
    Can you explain to me how to fix these errors?
    Last edited by Lettin03; 11-23-2007 at 05:23 AM.

  6. #6
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    I don't know what your function does - and my example wasn't complete by any means.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. read only folder on Windows
    By George2 in forum Windows Programming
    Replies: 2
    Last Post: 11-05-2007, 09:18 AM
  2. brace-enclosed error
    By jdc18 in forum C++ Programming
    Replies: 53
    Last Post: 05-03-2007, 06:49 PM
  3. Read Array pro!!Plz help!!
    By Supra in forum C Programming
    Replies: 2
    Last Post: 03-04-2002, 03:49 PM
  4. data read problem
    By Supra in forum C Programming
    Replies: 0
    Last Post: 02-03-2002, 07:02 PM
  5. Help! Can't read decimal number
    By Unregistered in forum C Programming
    Replies: 2
    Last Post: 09-07-2001, 03:09 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21