mikroPic Pro interrupt doesn't works - I need some help

General discussion on mikroPascal PRO for PIC.
Post Reply
Author
Message
Zus
Posts: 3
Joined: 18 Apr 2014 19:17

mikroPic Pro interrupt doesn't works - I need some help

#1 Post by Zus » 18 Apr 2014 19:29

Hi ! I've written a small code for trying an interrupt. I'm not a profi coder yet. So, my code was this:

Code: Select all

program ctcss_encoder02;

{ Declarations section }
const
  ccode: array[1..50] of word = (61890,62010,62140,62260,62370,62480,62585,62690,62790,62885,62980,63050,63120,63200,63285,
                                 63363,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
                                 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
                                 0,64617,64632);
                                 

procedure InitTimer1();
begin                  //Prescaler 1:1; TMR1 Preload = 61805; Actual Interrupt Time : 1,4924 ms
  {T1CON         := 0x01;
  TMR1IF_bit         := 0;
  TMR1H         := 0xF1;
  TMR1L         := 0x6D;
  TMR1IE_bit         := 1;}
  
  T1CON := 1;                  // Timer1 settings
  PIR1.TMR1IF := 0;            // clear TMR1IF
  TMR1H := 0xF1;               // Initialize Timer1 register
  TMR1L := 0x6D;
  PIE1.TMR1IE  := 1;
  INTCON         := 0xC0;
end;

procedure Interrupt();
begin
  if (TMR1IF_bit) then
  begin
    TMR1IF_bit := 0;
    TMR1H         := Hi(ccode[portb]);
    TMR1L         := Lo(ccode[portb]);
    //Enter your code here
    porta.0:=1;
    delay_us(200);
    porta.0:=0;
  end;
end;


begin
  { Main program }
  
  TRISA  := 0;                       // PORTA is output
  PORTA := 0;
  TRISB  := 255;
  //PORTB := 0xFF;
  
  InitTimer1;
  
  while TRUE do
    begin

    end;
end.
This code can do square impulses with a 16F628 (if it works).

My problem is: this code works very well in Proteus simulator. When programming it into a real 16F628, it isn't works. The 16F628 doesn't do the interrupt (otherwise the microcontroller works well). I've written my code based on the Mikroelektronika's Timer calculator. The code seems to be good, just I can't find the error.

What could be the problem ? Thank you for any help.

yo2lio
Posts: 1878
Joined: 19 Sep 2006 12:57
Location: Romania, Arad City
Contact:

Re: mikroPic Pro interrupt doesn't works - I need some help

#2 Post by yo2lio » 22 Apr 2014 19:35

Hi,

By default, for PIC16F628, comparator is ON and use RA0 to RA3 pins.

Turn OFF the comparator: CMCON := 7;

In the same way, take a look at OPTION_REG if you want internal pull-ups resistors for PORTB.

OPTION_REG := %0111111; // enable PORTB internal pull-ups resistors
Best regards, Florin Andrei Medrea.

http://www.microelemente.ro/
http://www.microelemente.ro/produse-si-servicii/
http://www.microelemente.ro/custom-software/

mail : florin@microelemente.ro

User avatar
petar.timotijevic
mikroElektronika team
Posts: 1739
Joined: 19 Feb 2014 13:46
Location: Serbia
Contact:

Re: mikroPic Pro interrupt doesn't works - I need some help

#3 Post by petar.timotijevic » 22 Apr 2014 20:34

Hello Zus and welcome to the MikroE forum, Hello yo2lio,

As yo2lio already said try to turn off comparator.


Best regards,
Peter

hadv
Posts: 116
Joined: 29 Mar 2013 12:55

Re: mikroPic Pro interrupt doesn't works - I need some help

#4 Post by hadv » 23 Apr 2014 13:39

You should set the GIE and PEIE bits in INTCON to make sure interrupts will occur and can be handled.

Post Reply

Return to “mikroPascal PRO for PIC General”