| main.c |
#include "macrodriver.h"
#include "system.h"
#include "ad.h"
#include "int.h"
#include "port.h"
#include "timer.h"
#include "watchdogtimer.h"
#include "serial.h"
#include "lvi.h"
void main( void )
{
/* TODO. add user code */
SetIORBit(ASIM6, 0x80); /*受信許可*/
SetIORBit(ASIM6, 0x20); /*受信許可*/
TM00_Start();
TMH1_Start();
while(1){
;
}
}
|
| timer.h |
#ifndef _MDTIMER_ #define _MDTIMER_ #define TM_TM00_CLOCK 0x0 #define TM_TM00_INTERVALVALUE 0x1f3f #define TM_TM00_SQUAREWIDTH 0x1f3f #define TM_TM00_PPGCYCLE 0x1f3f #define TM_TM00_PPGWIDTH 0x00 #define TM_TM00_ONESHOTCYCLE 0x1f3f #define TM_TM00_ONEPULSEDELAY 0x00 #define TM_TM80_CLOCK 0x0 #define TM_TM80_INTERVALVALUE 0x00 #define TM_TMH1_CLOCK 0x4 #define TM_TMH1_INTERVALVALUE 0x1D /*0x1D = 29*/ #define TM_TMH1_SQUAREWIDTH 0x1D /*0x1D = 29*/ #define TM_TMH1_PWMCYCLE 0x1D /*0x1D = 29*/ #define TM_TMH1_PWMDELAY 0x02 /* timer00, 80, H1 configurator initiation */ void TM00_Init( void ); void TMH1_Init( void ); /* timer start */ void TM00_Start( void ); void TMH1_Start( void ); /* timer stop */ void TM00_Stop( void ); void TMH1_Stop( void ); MD_STATUS TM00_ChangeTimerCondition( USHORT* array_reg, USHORT array_num ); MD_STATUS TMH1_ChangeTimerCondition( UCHAR* array_reg, UCHAR array_num ); __interrupt void MD_INTTM000( ); #endif /* _MDTIMER_*/ |
| TIMER_user.c |
#pragma sfr
#pragma interrupt INTTM000 MD_INTTM000
#include "macrodriver.h"
#include "timer.h"
int jyusin = 0x00;
__interrupt void MD_INTTM000( )
{
/* TODO */
/*受信モード*/
if(RXB6 != jyusin){ /*受信したキャラクターコードが前のコードと違うなら*/
jyusin = RXB6;
switch(jyusin){ /*受信したキャラクタコード*/
case 'm' : /*前進 (m)*/
/* P3 = 0xFF;
P4 = 0xFF;*/
ClrIORBit(P3, 0x01);
ClrIORBit(P4, 0x01);
P13 = 0xFF; /*デバック用LED*/
break;
case 0x73 : /*止まる (s)*/
/* P3 = 0xFE;
P4 = 0xFE;*/
SetIORBit(P3, 0x01);
SetIORBit(P4, 0x01);
P13 = 0xFF; /*デバック用LED*/
break;
case 0x72 : /*右回転 (r)*/
/* P3 = 0xFF;
P4 = 0xFE;*/
ClrIORBit(P3, 0x01);
SetIORBit(P4, 0x01);
P13 = 0xFF; /*デバック用LED*/
break;
case 0x6C : /*左回転 (l)*/
/* P3 = 0xFE;
P4 = 0xFF;*/
SetIORBit(P3, 0x01);
ClrIORBit(P4, 0x01);
P13 = 0xFF; /*デバック用LED*/
break;
case 0x70 : /*+-0° (p)*/
TMH1_Stop();
ClrIORBit(P4, 0x04); /*P4をPWM出力用へ*/
/* ClrIORBit(CMP11, 0xFF);
SetIORBit(CMP11, 0x02);*/
CMP11 = 0x02;
TMH1_Start();
P13 = 0xFF; /*デバック用LED*/
break;
case 0x75 : /*+60° (u)*/
TMH1_Stop();
ClrIORBit(P4, 0x04); /*P4をPWM出力用へ*/
/* ClrIORBit(CMP11, 0xFF);
SetIORBit(CMP11, 0x01);*/
CMP11 = 0x01;
TMH1_Start();
P13 = 0xFF; /*デバック用LED*/
break;
case 0x64 : /*-60° (d)*/
TMH1_Stop();
ClrIORBit(P4, 0x04); /*P4をPWM出力用へ*/
/* ClrIORBit(CMP11, 0xFF);
SetIORBit(CMP11, 0x03);*/
CMP11 = 0x03;
TMH1_Start();
P13 = 0xFF; /*デバック用LED*/
break;
default:
P13 = 0xFE; /*デバック用LED*/
}
}else{
; /*受信データーに変更がないときにはなにもしない*/
}
}
|