+ Reply to Thread
Results 1 to 9 of 9

Thread: How to set a function in a certain address?

  1. #1
    Banned alphadog Bad
    Join Date
    Feb 2009
    Posts
    236

    Default How to set a function in a certain address?

    I have a port that when any of its pin causes an interrupt, it vectors the MCU to address 0x7B.
    I would like to create a new file, and write inside it a function, and have the function's address to be 0x7B.
    I'd mention that i write the code in C language, not in assembly language.

    How can i do that?

    Thanks!


  2. #2
    dknguyen Excellent dknguyen Excellent dknguyen Excellent dknguyen Excellent dknguyen Excellent dknguyen Excellent dknguyen Excellent dknguyen Excellent dknguyen Excellent
    Join Date
    May 2006
    Location
    Alberta, Canada
    Posts
    6,029

    Default

    At least for PICs, there is a preset function name of some sorts that is at that memory address and gets called whenever the interrupt is triggered. You just declare the function using that name and type out your routine and it just runs whenever the interrupt fires. Check your compiler user manual about interrupts.
    Last edited by dknguyen; 11th February 2009 at 07:58 PM.

  3. #3
    Banned alphadog Bad
    Join Date
    Feb 2009
    Posts
    236

    Default

    Thanks for the answer.
    You suggest a nice way how to bypass the setting of a function in a ceratin address.
    I'd still like to know how you do that, becuase i assume its possible.

    By the way, i use the CC2430 MCU.

  4. #4
    dknguyen Excellent dknguyen Excellent dknguyen Excellent dknguyen Excellent dknguyen Excellent dknguyen Excellent dknguyen Excellent dknguyen Excellent dknguyen Excellent
    Join Date
    May 2006
    Location
    Alberta, Canada
    Posts
    6,029

    Default

    I don't know anything about that processor.

  5. #5
    Banned alphadog Bad
    Join Date
    Feb 2009
    Posts
    236

    Default

    Alirght,
    I know that if i used assembly language, i could use the command ' DSEG AT 0x7B '
    and their i would be calling my function that serves interrupts.
    I just dont know how to write it in C language.

  6. #6
    dknguyen Excellent dknguyen Excellent dknguyen Excellent dknguyen Excellent dknguyen Excellent dknguyen Excellent dknguyen Excellent dknguyen Excellent dknguyen Excellent
    Join Date
    May 2006
    Location
    Alberta, Canada
    Posts
    6,029

    Default

    YOu can write sections of assembly in C you know.

    I think you use asm{...} or something like that.

  7. #7
    Banned alphadog Bad
    Join Date
    Feb 2009
    Posts
    236

    Default

    Yes but the whole other code is written in C, so implementing single asm file in the code wouldn't be a good idea.

  8. #8
    colin mac Good colin mac Good colin mac Good colin mac Good
    Join Date
    Jun 2007
    Location
    Ireland
    Posts
    342

    Default

    You don't need asm. What compiler and have you read the manual.?

  9. #9
    Papabravo Excellent Papabravo Excellent Papabravo Excellent Papabravo Excellent Papabravo Excellent Papabravo Excellent Papabravo Excellent
    Join Date
    Mar 2006
    Location
    Michigan, USA (GMT-5)
    Posts
    2,892

    Default

    The IAR Compiler for the 8051 has an interrupt keyword that is used to bind a function to an interrupt vector.
    Code:
    interrupt [0x0023] using [SP_BANK] void SERIALISR(void)
    {
    ...SERIALISR Code
    }
    
    It is common to declare an interrupt function as having no return value and taking no arguments. So 0x0023 is the absolute address of the serial port ISR inb all the 8051s you will ever see besides all the ones that you won't. The using qualifier selects one of 4 register banks to be used by the interrupt procedure.
    We never have time to do it right; but we always have time to do it over.

+ Reply to Thread

Similar Threads

  1. Incrementing Register Address??
    By Suraj143 in forum Micro Controllers
    Replies: 2
    Latest: 8th December 2008, 01:30 AM
  2. want an address sequence file
    By srujan in forum Electronic Projects Design/Ideas/Reviews
    Replies: 4
    Latest: 10th March 2008, 10:59 AM
  3. address 0x000
    By aljamri in forum Micro Controllers
    Replies: 0
    Latest: 25th May 2007, 09:19 AM
  4. MAC address problem
    By tkvenki in forum Micro Controllers
    Replies: 4
    Latest: 22nd March 2007, 08:25 AM
  5. Function Generator question: What is GATE function?
    By Cifrocco in forum General Electronics Chat
    Replies: 8
    Latest: 14th April 2005, 03:11 AM

Tags for this Thread