Thread: Return value to Register

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

    Return value to Register

    How do you return a value back to the register. I have 2 functions, one reads the value of the register
    Code:
    #define IOBASE 0x4000
    
    void leesRegister( unsigned char* Register )
    {
      Register[0] = *( ( unsigned char* ) ( IOBASE + 0x10 ) );
      Register[2] = *( ( unsigned char* ) ( IOBASE + 0x12 ) );
      Register[4] = *( ( unsigned char* ) ( IOBASE + 0x14 ) );
    }
    and the other must return the value of ddr back to the register
    Code:
    void schrijfRegister( Register, ddr ) 
    {
    }
    But what keywords do I have to use etc? just a little help can get me started.

    Microcontroller = Fujitsu
    Datasheet = MB90F4 http://www.datasheets.org.uk/preview/2236300.html

  2. #2
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    No keywords[1] involved here, but perhaps you want to think about how you would do the exact opposite of what your leesRegister does.

    [1] keywords in C are the words defined by the compiler, such as "if", "while", etc.

    --
    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
    How does a code, that does the exact opposite, look like?
    Code:
    #define IOBASE 0x4000
    
    void schrijfRegister( unsigned char* ddr ) 
    {
      ddr[0] = *( ( unsigned char* ) ( IOBASE + 0x10 ) );
      ddr[2] = *( ( unsigned char* ) ( IOBASE + 0x12 ) );  
      ddr[4] = *( ( unsigned char* ) ( IOBASE + 0x14 ) );
    }
    is this correct?
    Last edited by Lettin03; 11-26-2007 at 06:24 AM.

  4. #4
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by Lettin03 View Post
    How does a code, that does the exact opposite, look like?
    Code:
    #define IOBASE 0x4000
    
    void schrijfRegister( unsigned char* ddr ) 
    {
      ddr[0] = *( ( unsigned char* ) ( IOBASE + 0x10 ) );
      ddr[2] = *( ( unsigned char* ) ( IOBASE + 0x12 ) );  
      ddr[4] = *( ( unsigned char* ) ( IOBASE + 0x14 ) );
    }
    is this correct?
    No, that's EXACTLY THE SAME, not the OPPOSITE.

    --
    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
    Could you show how the opposite looks like then? I cant figure it out and it's driving me crazy

  6. #6
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by Lettin03 View Post
    Could you show how the opposite looks like then? I cant figure it out and it's driving me crazy
    Give it a try - think about what you want to do. Your first function reads FROM a register, the new function should do what?

    --
    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.

  7. #7
    Registered User
    Join Date
    Nov 2007
    Posts
    19
    Uhm I'm thinking about the same code, but = means the variable becomes. Should I use ==?

  8. #8
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by Lettin03 View Post
    Uhm I'm thinking about the same code, but = means the variable becomes. Should I use ==?
    So what do you actually say that this function should do: describe what it does in words, and I think it will be clear to you what you need to do and how to write the code!

    --
    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.

  9. #9
    Registered User
    Join Date
    Nov 2007
    Posts
    19
    The code has to return the ddr value back to the register
    Code:
    #define IOBASE 0x4000
    
    void schrijfRegister( Register, unsigned char* ddr )
    {
      (IOBASE + 0x10) = Register[0], unsigned char*;
    }
    Is this more like it?

  10. #10
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    You've got the rigth idea, but you seem a little confused about which part of the components belong together.

    --
    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.

  11. #11
    Registered User
    Join Date
    Nov 2007
    Posts
    19
    I Think I have written the right code, but there seems to be an error
    Code:
    void schrijfRegister( int Register, unsigned char ddr )
    {
      ( IOBASE + 0x10 ) = ( int ) ( unsigned char );
    }
    Can you see what I am doing wrong?
    Last edited by Lettin03; 11-27-2007 at 01:49 AM.

  12. #12
    Registered User
    Join Date
    Nov 2007
    Posts
    19
    matsp, judge my code above

  13. #13
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    If I were to ask you to do "a[i] = y" backwards, what would you do?

    --
    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.

  14. #14
    Registered User
    Join Date
    Nov 2007
    Posts
    19
    "a[i] = y" backwards would be "y[i] = a" I think. But my code isn't suppost to be the exact opposite cause is contains 2 arguments in stead of 1. Maybe the code must be like this
    Code:
    void schrijfRegister( int Register, unsigned char ddr )
    {
      ( int ( IOBASE + 0x10 ) ) = unsigned char;
    }
    But there still is an errpr
    Code:
    E4062C: syntax error near `0x4000'
    Last edited by Lettin03; 11-27-2007 at 03:56 AM.

  15. #15
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by Lettin03 View Post
    "a[i] = y" backwards would be "y[i] = a" I think. But my code isn't suppost to be the exact opposite cause is contains 2 arguments in stead of 1.
    If a is an array, and y is a simple variable, your backwards version wouldn't compile, right?

    --
    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. New string functions
    By Elysia in forum C Programming
    Replies: 11
    Last Post: 03-28-2009, 05:03 AM
  2. Another weird error
    By rwmarsh in forum Game Programming
    Replies: 4
    Last Post: 09-24-2006, 10:00 PM
  3. Pong is completed!!!
    By Shamino in forum Game Programming
    Replies: 11
    Last Post: 05-26-2005, 10:50 AM
  4. DOS, Serial, and Touch Screen
    By jon_nc17 in forum A Brief History of Cprogramming.com
    Replies: 0
    Last Post: 01-08-2003, 04:59 PM
  5. opengl code not working
    By Unregistered in forum Windows Programming
    Replies: 4
    Last Post: 02-14-2002, 10:01 PM