caramoan tour package

caramoan tour package

Author Topic: help in MikcroC interrupt syntax  (Read 466 times)

Offline romel_emperado

  • Size C Battery
  • *****
  • Posts: 237
  • Pogi/Ganda Points: 3
help in MikcroC interrupt syntax
« on: March 16, 2011, 04:06:43 PM »
guys i have a big problem I usually sue KEIL in programming 8051 but i found it easier inm mikroc thats y I move to mikroc..

now my problem is i dont know how to declare timer0 as interrupt using mikrco-C compiler?

this is my code in keil but i dont know how to do it in mikroC for 8051.


Quote
void timer0() interrupt 1  // Function to generate clock of frequency 500KHZ using Timer 0 interrupt.
{
clk=~clk;
}


void main()
{

  TMOD =  0x22;  //timer0 setting for generating clock of 500KHz using interrupt enable mode.
  TH0  =  0xFD;
  IE   =  0x82;
  TR0  =  1;
  while(1);
}

Philippine Electronics Forum

help in MikcroC interrupt syntax
« on: March 16, 2011, 04:06:43 PM »

Offline RiDdLeR???

  • Hydroelectric
  • ***
  • Posts: 3033
  • Pogi/Ganda Points: 208
Re: help in MikcroC interrupt syntax
« Reply #1 on: March 16, 2011, 05:05:32 PM »
This might help but its for timer1 on a  AT89S8253  ...  you only need change the corresponding interrupt vector name.
Just a cut and paste from MikroC samples folder.
Code: [Select]
//-------------- Interrupt handler routine
void Timer1InterruptHandler() org IVT_ADDR_ET1{

  EA_bit = 0;        // Clear global interrupt enable flag

  TR1_bit = 0;       // Stop Timer1
  TH1 = 0x00;        // Reset Timer1 high byte
  TL1 = 0x00;        // Reset Timer1 low byte
   
  P0 = ~P0;          // Toggle PORT0

  EA_bit = 1;        // Set global interrupt enable flag
  TR1_bit = 1;       // Run Timer1
}

void main() {
 
  P0  = 0;           // Initialize PORT0

  TF1_bit = 0;       // Ensure that Timer1 interrupt flag is cleared
  ET1_bit = 1;       // Enable Timer1 interrupt
  EA_bit  = 1;       // Set global interrupt enable

  GATE1_bit = 0;     // Clear this flag to enable Timer1 whenever TR1 bit is set.
  C_T1_bit  = 0;     // Set Timer operation: Timer1 counts the divided-down systam clock.
  M11_bit   = 0;     // M11_M01 = 01    =>   Mode 1(16-bit Timer/Counter)
  M01_bit   = 1;

  TR1_bit = 0;       // Turn off Timer1
  TH1 = 0x00;        // Set Timer1 high byte
  TL1 = 0x00;        // Set Timer1 low byte
  TR1_bit = 1;       // Run Timer1

}

Philippine Electronics Forum

Re: help in MikcroC interrupt syntax
« Reply #1 on: March 16, 2011, 05:05:32 PM »

 

Privacy Policy

Contact Us: elabph@yahoo.com