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

Interrupt

This is probably pretty basic, but I can't figure out why it doesn't work.

I am working with a MSC1211Y5 evaluation board, and I am trying to
test the serial interrupts on the board. I feel like I've written
what I need to trigger an interrupt, but it doesn't enter into my
interrupt function (this is programmed in C). I'm still pretty new
to this (as you can see) and haven't found the resources to help me
with this. Shouldn't the following code trigger a serial interrupt?

void main ( void ) {

REN_0 = 1;
TB8_0 = 1;
SM0_0 = 1;
SM1_0 = 0;
TI_0 = 0;
TH1 = -3;
ES = 1;
EA = 1;

while (1) {
SBUF = 0x88;
} }

Basically, I feel that it should enter an interrupt whenever SBUF is
written to, right? Because the T1 flag should get set. My interrupt
is named like this:

void serial_isr (void) interrupt 1

I tested if the T1 flag gets set by doing:
while (1) {
SBUF = 0x88;
if (T1 == 1) serial_isr();
}

and it worked! (I removed the "interrupt 1" sign next to the second function). So I'm not sure what I didn't set.

Thanks in advance for any help.

Parents
  • hey, I think the issue was the naming of the interrupt function. I changed it to interrupt 4 using 1 and it worked. I was actually wondering if that was the problem (I based the "interrupt 1" off an example I saw here, as the book I have doesn't mention C programming much).

    Thanks!

Reply
  • hey, I think the issue was the naming of the interrupt function. I changed it to interrupt 4 using 1 and it worked. I was actually wondering if that was the problem (I based the "interrupt 1" off an example I saw here, as the book I have doesn't mention C programming much).

    Thanks!

Children
  • Hey, didn't want to start a new thread, but I'm having some problems! I'm trying to read from the serial port, and it just gives me gibberish, so I wrote out a program from a textbook I have, it goes like this:

    #include <reg51.h>
    #include <stdio.h>

    sbit AccMSB = ACC^7;

    void OUTCHR (void)
    { CY = P;
    CY = !CY;
    AccMSB = CY;
    while (TI != 1);
    TI = 0;
    SBUF = ACC;
    AccMSB = 0;
    }

    void INCHAR (void)
    { while (RI != 1);
    RI = 0;
    ACC = SBUF;
    CY = P;
    CY = !CY;
    AccMSB = 0;
    }

    main ()
    { SCON = 0x52;
    TMOD = 0x20;
    TH1 = -13;
    TR1 = 1;

    while (1)
    { INCHAR();
    OUTCHR();
    } }

    Whenever I type a key, it should echo it back, right? Well, all it gives me are strange characters; unfortunately, I can't copy it from the Terminal Window, its not letting me (I'm using the Terminal window in the TI downloader).

    I know its kind of hard without the output, but has this happened to anyone else?

    Actually, I just went through Word, and was able to find the Unicode representations:

    0 - two characters, 8+ 00FE (latin small letter thorn)
    1 - 00C6 (latin capital AE)
    2 - same as 0
    3 - same as 1
    4 - > (yes, the greater than symbol)
    5 - two characters, 00FE+00FE (latin small letter thorn)
    6 - same as 4
    7 - same as 5
    8 - same as 0
    9 - same as 1

    Thanks in advance for any help or advice

  • ... to the instructions on how to post source code:
    www.danlhenry.com/.../keil_code.png

    Note that TABs don't work (well) - use spaces instead,

    and don't forget to check it in the 'Preview'...

  • You most certainly do not want to be fiddling directly with ACC in a 'C' program!

    Note that it is customary to reserve UPPERCASE names for #defines.

    "Whenever I type a key, it should echo it back, right? "

    rather unlikely I'm afraid - you're relying on the received character being in ACC after INCHAR returns, and still being in ACC by the time you've called OUTCHR.
    You might just possibly be lucky in this trivial case, but you certainly can not rely upon it in any general way at all!!

    You need to get a proper 'C' textbook, and study how to pass parameters to functions, and return values from functions.

  • Or just write the program in assembler, since there doesn't seem to be a scrap of C in it (other than function declarations).

  • As they say, "a Real Programmer can write FOTRAN in any language"

    presumably, it also applies to assembler...?

    ;-)