タイマ割り込み

PSoCEval1用のサンプルプログラムです。

Eval1は秋月で売ってます。
http://akizukidenshi.com/catalog/items2.php?q=%22M-02483%22&s=score&p=1&r=1&page=80



1秒おきにlcdの値が増えます。
1秒ごとに(P10に接続)LEDが点灯/消灯します。

#include <m8c.h>        // part specific constants and macros
#include "PSoCAPI.h"    // PSoC API definitions for all User Modules

unsigned int data=0;

#pragma interrupt_handler tintISR
void tintISR(void){
	data++;
	LCD_Position(0,0);
	LCD_PrHexInt(data);
	if(data & 1)
		LED_On();
	else
		LED_Off();

}

void main()
{
    LCD_Start();
    Timer16_WritePeriod(9999);         //Drives the LED for 1s
    Timer16_EnableInt();  
    M8C_EnableGInt;//Enable Global Interrupt
    Timer16_Start();

    while(1){
    }	
}

↑ソースはこれだけなので、お手軽ですが、、、。

割り込み関数は「tintISR」という関数です。
しかし、実際に割り込みで呼び出されるのは別の箇所なので、この関数を呼び出す下準備が必要です。

libフォルダの「Timer16INT.asm」にある
次の部分を書き換えます。

_Timer16_ISR:

   ;@PSoC_UserCode_BODY@ (Do not change this line.)
   ;---------------------------------------------------
   ; Insert your custom code below this banner
   ;---------------------------------------------------
   ;   NOTE: interrupt service routines must preserve
   ;   the values of the A and X CPU registers.

	ljmp _tintISR  ;********ここに追記!!! 

   ;---------------------------------------------------
   ; Insert your custom code above this banner
   ;---------------------------------------------------
   ;@PSoC_UserCode_END@ (Do not change this line.)

   reti

アセンブラレベルでソースを書き換えないといけないあたりが、、、なんというか、。


タイマの周期の設定はソースコード内にはありません。

VC1/VC2/VC3の分周比設定です。
clock(24MHz)
↓÷3
VC1(8MHz)
↓÷8
VC2(1MHz)
↓÷100
VC3(10kHz)
これで、VC3というカウンタが10kHzの周期でカウントされていきます。


ユーザーモジュールTimer16のプロパティ設定。
VC3が9999+1でカウント終了となり割り込みが発生
これで、1秒で割り込みが発生するようです。

ややこしいです。
プロジェクトファイル(timer.zip)を置いておきます。
http://briefcase.yahoo.co.jp/bc/takuyamatsubara/lst?.dir=/d959&.src=bc&.view=