Timers and Interrupts


Closed Thread
Results 1 to 3 of 3
  1. #1
    senior project1's Avatar
    senior project1 Guest

    Question Timers and Interrupts

    Hi
    I have a code that should write on Port B on the P18F452. It should write on the first timer's interrupt four states on Port B and then wait for the next interrupt. What happens is that it doesn't write the right sequence, can any one figure out why?

    My code:
    -----------------------------

    #include <p18f452.h>
    #include <timers.h>
    #include <delays.h>

    /* Set configuration bits
    * - set RC oscillator
    * - disable watchdog timer
    * - disable low voltage programming
    * - disable brownout reset
    * - enable master clear
    */

    #pragma config OSC = HS
    #pragma config WDT = OFF
    #pragma config LVP = OFF
    #pragma config BOR = OFF
    //#pragma config MCLRE = ON

    unsigned int count=0;

    void MyHighInt(void); // prototypes for the interrupt
    #pragma interrupt MyHighInt // MyHighInt is an interrupt
    #pragma code high_vector=0x08 // high_vector is at 0x0008

    void high_vector(void) // the high prioity vector
    {
    _asm GOTO MyHighInt _endasm // goto high software
    }
    #pragma code // start code here
    void MyHighInt(void)
    {
    char myarry[16]={0x60,0x65,0x66,0x6B,0x60,0x64,0x66,0x6A,0x62,0x6 3,0x68,0x69,0x61,0x67,0x68,0x69};
    char arry[16]={0x20,0x25,0x26,0x2B,0x20,0x24,0x26,0x2A,0x22,0x2 3,0x28,0x29,0x21,0x27,0x28,0x29};
    int j,i;
    TRISB=0x00;
    INTCONbits.TMR0IF=0;
    for(i=0;i<16;i++)
    {
    PORTB=arry[i];
    }

    for(j=count;j<count+4;j++)
    {
    PORTB=myarry[j];
    if(j==15)
    count=0;
    }

    count=count+4;
    }

    // main program
    void main (void)
    {

    INTCON2bits.TMR0IP=1;
    INTCONbits.TMR0IF=0;
    INTCONbits.TMR0IE=1;
    T0CONbits.TMR0ON=1;

    OpenTimer0 (TIMER_INT_ON & T0_8BIT & T0_SOURCE_INT & T0_PS_1_8);
    RCONbits.IPEN = 1; // IPEN = 1 to enable priority interrupts
    INTCONbits.PEIE=1;
    INTCONbits.GIEH = 1; // enable high priority interrupt

    while(1);
    }

  2. #2
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,521


    Did you find this post helpful? Yes | No

    Default

    Hi,
    I'm sure someone will be able to figure it out but the chance of getting hold of that someone is much bigger if you post the question on the forum for your particular compiler. This forum is targeting PicBASIC and PicBASICPRO from MicroEngineeringLabs and you are obviously using some flavour of C.

    Good luck!
    /Henrik.

  3. #3
    Join Date
    Jul 2003
    Posts
    2,405


    Did you find this post helpful? Yes | No

    Default

    You want the Microchip C18 compiler forum here: http://forum.microchip.com/
    Regards,

    -Bruce
    tech at rentron.com
    http://www.rentron.com

Similar Threads

  1. 18F2420, instant interrupts, and TMR0
    By dhickman in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 11th March 2009, 18:33
  2. Clock using Instant Interrupts
    By PICpocket in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 16th February 2009, 21:43
  3. Timers !
    By n qwerty in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 22nd August 2007, 11:39
  4. Handeling multiple Interrupts
    By BobSpencerr in forum General
    Replies: 15
    Last Post: - 1st March 2007, 01:12
  5. Interrupts on 18F2525
    By Tom Gonser in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 26th March 2005, 02:37

Members who have read this thread : 1

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts