/***********************************************************************/ /* */ /* FILE :H83694F0005.c */ /* DATE :Sun, Dec 16, 2012 */ /* DESCRIPTION :Main Program */ /* CPU TYPE :H8/3694F */ /* */ /* This file is generated by Renesas Project Generator (Ver.4.16). */ /* */ /***********************************************************************/ #include "stdio.h" #include "typedefine.h" #include "iodefine.h" void init_pwm(void); int main() { // ************************* // 1.Intialized Segment // ************************* // (1)Initialized PWM init_pwm(); // ************************* // 2.Program Main // ************************* // (1)Output PWM TW.GRB = 75 ; TW.GRC = 50 ; TW.GRD = 25 ; while(1); } //**************************************************************************** // Function Name : init_pwm // Title : Initialized PWM // Input : // Output : //**************************************************************************** void init_pwm(){ // ************************************************* // 1.Set TMRW(Timer Mode Register W) register // ************************************************* // TMRW(7);Counter start bit ==> 0:Stop / 1:start // TMRW(6);Reserve ==> 1 // TMRW(5);Buffer B ==> 0:I/O compare / 1:GRB // TMRW(4);Buffer A ==> 0:I/O compare / 1:GRB // TMRW(3);Reserve ==> 1 // TMRW(2);PWMD ==> 0:I/O compare / 1:PWM // TMRW(1);PWMC ==> 0:I/O compare / 1:PWM // TMRW(0);PWMB ==> 0:I/O compare / 1:PWM // TW.TMRW.BYTE=0x4F; /* 0x49;0b0100,1111 */ // ************************************************ // 2.Set TCRW(Timer Control Register W) register // ************************************************ // TCRW(7);Counter start bit ==> 1:Compare much clear / 0:Free counter // TCRW(6-4);Clock select // 000/001/010/011 ==> 1 - 1/8 Clock // 1** ==> FTCI // TCRW(3);Timer level set D ==> Out 0/1 // TCRW(2);Timer level set C ==> Out 0/1 // TCRW(1);Timer level set B ==> Out 0/1 // TCRW(0);Timer level set A ==> Out 0/1 // TW.TCRW.BYTE=0xBF; /* 0xB2;0b1011,1111 */ // ************************************************ // 3.Set TIERW(Timer Inturupt enable Register W) register // ************************************************ // TIERW(7);OVIE Inturupt // TIERW(6-4);Reserve ==> 1 // TIERW(3);IMIED // TIERW(2);IMIEC // TIERW(1);IMIEB // TIERW(0);IMIEA // TW.TIERW.BYTE=0x70; /* 0x70;0b0111,0000 */ // TW.TCNT=0; // ******************************************* // 4.Set 16bit General Register A - D (GRA-GRD) // Compared TCNT(16bit) // ******************************************* TW.GRA = 100 ; TW.GRB = 0 ; TW.GRC = 0 ; TW.GRD = 0 ; // ******************************************* // 5.Start PWM // ******************************************* TW.TMRW.BYTE = TW.TMRW.BYTE | 0x80; }