送信プログラム #include <mes2.h> #include <h8/reg3067.h> #include "cooler_pon.h" #include "cooler_poff.h" //#include "tv_pon.h"
#define DUMMY (*(volatile unsigned char *)0x500000) #define TCNT0_16 *(volatile unsigned short *)0xffff88
void irtrans(unsigned short *);
int main(){ PADR = 0x00; PADDR = 0x44; // A6 ,A2 - outout
irtrans(&toff_value[0]); sleep(10 * 1000); irtrans(&ton_value[0]); sleep(30 * 60 * 1000); irtrans(&toff_value[0]);
sleep(30 * 60 * 1000); irtrans(&ton_value[0]); sleep(30 * 60 * 1000); irtrans(&toff_value[0]);
sleep(30 * 60 * 1000); irtrans(&ton_value[0]); sleep(30 * 60 * 1000); irtrans(&toff_value[0]);
sleep(30 * 60 * 1000); irtrans(&ton_value[0]); sleep(30 * 60 * 1000); irtrans(&toff_value[0]);
sleep(30 * 60 * 1000); irtrans(&ton_value[0]); sleep(30 * 60 * 1000); irtrans(&toff_value[0]);
sleep(30 * 60 * 1000); irtrans(&ton_value[0]); sleep(30 * 60 * 1000); irtrans(&toff_value[0]);
}
void irtrans(unsigned short *t_value){ volatile unsigned char c; char signal =0; int_disable();
while(*t_value != 0){ TCR0_8 =0; TCR1_8 =0; TCNT0_16 = 0; TCR0_8 =0x4;// clock is 8TCNT1 OverFlow TCR1_8 =0x2;// clock / 64 if(signal ==0){ while(TCNT0_16 < *t_value){ /* IrLED On */ PADR =0x44; c =DUMMY; /* IrLED Off */ PADR =0x00; char value =8; while(--value >0){ c =DUMMY; } }
}else{ while(TCNT0_16 < *t_value){} } t_value++; signal ^= 1; }
/* IrLED Off */ PADR =0x00; int_enable();
}
|
[cooler_pon.h] 送信プログラムに必要
static unsigned short ton_value[] ={ 93, 49843, 99, 19451, 90, 略 189, 0 };
|
受信プログラム リモコンのパルスの時間をprintfするだけのものです。
#include <mes2.h> #include <h8/reg3067.h>
#define TCNT0_16 *(volatile unsigned short *)0xffff88 //#define DATASIZE 10 #define DATASIZE 600
void init_timer0(void); int t_value[DATASIZE];
int main(){ int sdata; int t =0; char signal; int_disable(); TCR0_8 =0; TCR1_8 =0; TCNT0_16 = 0;
while((P7DR & 0x80)!=0){} TCR0_8 =0x4;// clock is 8TCNT1 OverFlow TCR1_8 =0x2;// clock / 64 // TCR1_8 =0x3;// clock / 8192 signal =0;
while(t <DATASIZE){ /* Wait for signal go down */ if(signal ==1){ while((P7DR & 0x80)!=0){} t_value[t++] =TCNT0_16; signal =0; TCR0_8 =0; TCR1_8 =0; TCNT0_16 = 0; TCR0_8 =0x4;// clock is 8TCNT1 OverFlow TCR1_8 =0x2;// clock / 64 // TCR1_8 =0x3;// clock / 8192 }else{ /* Wait for signal go up */ while((P7DR & 0x80)==0){} t_value[t++] =TCNT0_16; signal =1; TCR0_8 =0; TCR1_8 =0; TCNT0_16 = 0; TCR0_8 =0x4;// clock is 8TCNT1 OverFlow TCR1_8 =0x2;// clock / 64 // TCR1_8 =0x3;// clock / 8192 } } int_enable(); printf("t =%d\r",t); t =0; signal =0; while(t <DATASIZE){ printf("%d,\r",t_value[t++]); // printf("%d ,%d\r",signal,t_value[t++]); // printf("%d ,%d\r",signal^1,0); signal ^= 1; }
}
void init_timer0(void){ TCR0_8 =0; TCR1_8 =0; TCNT0_16 = 0; } |