Thanks I've tried that but I'm still not having any luck.
This is my code.

#include <stdint.h>

#define CLK_DIVR    (*(volatile uint8_t *)0x50C6)

#define TIM1_CR1    (*(volatile uint8_t *)0x5250)
#define TIM1_IER    (*(volatile uint8_t *)0x5254)
#define TIM1_SR1    (*(volatile uint8_t *)0x5255)
#define TIM1_CNTRH    (*(volatile uint8_t *)0x525E)
#define TIM1_CNTRL    (*(volatile uint8_t *)0x525F)
#define TIM1_PSCRH    (*(volatile uint8_t *)0x5260)
#define TIM1_PSCRL    (*(volatile uint8_t *)0x5261)

#define PD_ODR    (*(volatile uint8_t *)0x500f)
#define PD_DDR    (*(volatile uint8_t *)0x5011)
#define PD_CR1    (*(volatile uint8_t *)0x5012)

void main(void)
{
    CLK_DIVR = 0x00; // Set the frequency to 16 MHz

    TIM1_PSCRH = 0x00; // Configure timer
    TIM1_PSCRL = 0x80;

    TIM1_CR1 = 0x01; //Enable timer
    TIM1_IER = 0x01; //Enable interrupt - update event

    PD_DDR = 1<<3;
    PD_CR1 = 1<<3;


    while(1){
    }
}

void TIM1_overflow_Handler() __interrupt(11)
{
    TIM1_SR1 &= ~1; //reset interrupt
    PD_ODR ^= 1 << 3; //toggle LED
}


On 23/01/17 10:37, Травкин Роман wrote:
Typical interrupt is "void HandlerName() __interrupt(n)", where n -- interrupt number according to chip datasheet. Handler name could be anything you want. For trap interrupt use "void HandlerName() _trap".
void TIM4_OVF_handler() __interrupt(23)
{
  TIM4->SR1 &= ~TIM4_SR1_UIF;   // Reset flag as RM0016 states
    ms_cnt++;
}
void TIM1_OVF_UPD_TRG_handler() __interrupt(11)
{
    TIM1->SR1 &= ~TIM1_SR1_UIF; // Reset flag as RM0016 states
  tim1_ovf_num++;
}
void TIM2_OVF_UPD_handler() __interrupt(13)
{
    TIM2->SR1 &= ~TIM2_SR1_UIF; // Reset flag as RM0016 states
  tim2_ovf_num++;
}
22.01.2017, 14:56, "aarrgghh.co.uk" <aarrg...@aarrgghh.co.uk>:

Are there any concise SDCC examples of interrupt handling for the STM8?
I'm particularly interested in the STM8003F3 however anything for that
family of processors will help.

There are excellent general examples on colecovision that have all the
code in a single file which makes understanding what is going on very
clear.
http://www.colecovision.eu/stm8/

These have helped me get going but none of them cover an interrupt and I
am struggling to get a basic timer 1 interrupt call working or even
compiling as I don't know if the error is in incorrect use of registers
or general SDCC syntax or my C coding.
I don't really want to flood the place with derpy Questions if I can
avoid it.

Regards
Russ

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, SlashDot.org! http://sdm.link/slashdot
_______________________________________________
Sdcc-user mailing list
Sdcc-user@lists.sourceforge.net <mailto:Sdcc-user@lists.sourceforge.net>
https://lists.sourceforge.net/lists/listinfo/sdcc-user



------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, SlashDot.org! http://sdm.link/slashdot


_______________________________________________
Sdcc-user mailing list
Sdcc-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/sdcc-user

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, SlashDot.org! http://sdm.link/slashdot
_______________________________________________
Sdcc-user mailing list
Sdcc-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/sdcc-user

Reply via email to