Chapter 3
Microcomputer Basics 1
■Example program
/************************************************************************/
/* | CHECK Program for The count of the rising edge | */ | |||
/* | which used event count | */ | |||
/************************************************************************/ | |||||
/* | Setting of Main Peripheral |
| */ | ||
/* | Port 0 : Unused |
|
| */ | |
/* | Port 1 : Unused |
|
| */ | |
/* | Port 2 : Unused |
|
| */ | |
/* | Port 3 : Used as Timer 1 input |
| */ | ||
/* | Port 4 : Used as output port |
| */ | ||
/* | Port 5 : Unused |
|
| */ | |
/* | Port 6 : Unused |
|
| */ | |
/* | Port 7 : Unused |
|
| */ | |
/* | Port 8 : Unused |
|
| */ | |
/* | Timer 0 : Unused |
|
| */ | |
/* | Timer 1 : Used as Event count operation | */ | |||
/* | Timer 2 : Unused |
|
| */ | |
/* | Timer 3 : Unused |
|
| */ | |
/* | Timer 8 : Unused |
|
| */ | |
/* | Timer 11 : Unused |
| */ | ||
/* |
| */ | |||
/* | Serial interface communication 2 : Unused | */ | |||
/* |
| */ | |||
/* |
|
|
|
| */ |
/* | Interrupt : External interrupt | Unused | */ | ||
/* |
|
|
|
| */ |
/* | 2004/09 | Rev 0.1 |
| */ | |
/************************************************************************/ | |||||
#include "sr103s92.h" |
|
| |||
#include "int.h" |
|
|
| ||
/****************************/ |
|
| |||
/* | Declaration of function */ |
|
| ||
/****************************/ |
|
| |||
void main(void); |
|
|
| ||
void initialize(void); |
|
| |||
/* | |||||
| |||||
| control is shifted to this main routine. |
| |||
*/ |
| ||||
|
| ||||
{ | initialize(); |
| /* Initial Job */ |
| |
|
|
| |||
| TM1MD | = 0x00; |
| /* Stop the counter */ |
|
|
| ||||
|
|
|
| */ |
|
| P4OUT = 0x00; |
| /* Set P44 Low(VSS level) */ |
| |
| P4DIR = 0x10; |
| /* Set P44 output */ |
| |
|
| ||||
|
|
|
| */ |
|
| P3MD | = 0x02; |
| /* Set TM1IO port */ |
|
| P3DIR = 0x00; |
| /* Set P31 input */ |
| |
| |||||
|
| ||||
| TM1BR | = 0x04; |
| /* Set the base register */ |
|
| TM1MD | = TM1MD 0x07; | /* Select the clock source to TMIN1 pin input */ | ||
| TM1MD | = TM1MD 0x40; | /* Initial timer */ |
| |
| TM1MD | = TM1MD & 0xBF; | /* Set normal operation */ |
| |
| G4ICR = 0x0200; |
| /* Set an interrupt level */ |
| |
|
|
|
| /* Enable the interrupt */ |
|
| asm (" | or | 0x0F00,PSW\n"); /* Enable the interrupt, Interrupt level 7 */ |
III−42