Multisim and Ultiboard

cancel
Showing results for 
Search instead for 
Did you mean: 

interrupt timer 8051 in C

Highlighted

Hi

 

I'm trying out internal interrupts using the MCU 8051 simulator in Multisim. I have read through the Hitech C51 lite compiler manual and I've come up with the following code to interrupt an LED every 50ms so that it flashes.

 

When it's compiled it comes up with an error on line 16 'expecting ";" '(which is already there).

 

Any ideas?

 

1.  #include<htc.h>

2.  #define ON 0
3.  #define OFF 1
4.  #define led_1 P10
5.  #define led_2 P20

6.

7.  interrupt void     //taken from the manual
8.  timer0(void)
9. {
10. led_1=!led_1;
11. TH0 = 0x3C;          //Reload 3CAF = 15535 in hex (65535-15535 = 50,000) which is a count of 50ms
12. TL0 = 0xAF;
13. }

14. void main()
15. {
16. static unsigned char EA @ 0xAF;    //taken from the manual
17. EA=1;                                               //taken from the manual
18. TMOD = 0x01;     //Timer 0 mode 1 - 16 bit counter
19. TH0 = 0x3C;       //3CAF = 15535 in hex (65535-15535 = 50,000) which is a count of 50ms
20. TL0 = 0xAF;
21. TR0 = 1;
22. while(1);
}

0 Kudos
Message 1 of 4
(140 Views)
Highlighted

Hi JasonTurner52,

 

We're unable to advise on C programming and syntax specifically since this is not our area of expertise. We can however provide help for Multisim.

 

Have you also seen this MultiMCU Microcontroller Co-simulation Manual? It consists of a few C tutorials.

Specifically, Tutorial 1 is an example of how we can control an LED to flash/blink with the MCU 8051.

 

Hope this helps!

 

Ellin A.

NI Technical Support Engineer.

0 Kudos
Message 2 of 4
(68 Views)
Highlighted

Cheers for that. It was more about using interrupts in C coding. I can't seem to get them to work using the C compiler in Multisim.

0 Kudos
Message 3 of 4
(54 Views)
Highlighted

Hi JasonTurner52,

 

In that case, I found a few resources that might be of further help.

 

Here's an in-depth tutorial explaining the usage of interrupts on the 8051. A few of the examples incorporate LEDs.

 

Here's another tutorial on interrupts. This one focuses more on explaining the different types of interrupts and the flags/registers/bits etc. There is also an example of controlling an LED right at the bottom.

 

Ellin A.

NI Technical Support Engineer.

0 Kudos
Message 4 of 4
(41 Views)