/*=== TV Remote Controler (IO-data ) ===*/
#include "mcc_generated_files/mcc.h"
#define MARK() __delay_us(562)
#define SPACE_1() __delay_us(1686)
#define SPACE_0() __delay_us(562)
#define LEADER_1() __delay_us(8992)
#define LEADER_0() __delay_us(4496)
#define GYAP_0() __delay_ms(43)
#define DSM_1() (MD1CON0bits.MD1BIT = 1)
#define DSM_0() (MD1CON0bits.MD1BIT = 0)
#define IO_CUSTOM 0xE880
/*---------- ----------*/
uint8_t IO[][8] ={{0x80,0xE8,0x84,0x7B,
0x80,0xE8,0x10,0xCF},
{0x80,0xE8,0x84,0x7B,
0x80,0xE8,0x20,0xCF},
{0x80,0xE8,0x84,0x7B,
0x80,0xE8,0x30,0xCF}};
uint16_t IO2[] = {0x1084,0x2084,0x3084};
uint8_t sft;
uint16_t wsft;
/*---- Send Ir_Leader ---*/
void Ir_Leader(){
DSM_1(); // send Leader
LEADER_1();
DSM_0();
LEADER_0();
}
/*---- Send Ir_Stop ---*/
void Ir_Stop(){
DSM_1();
MARK(); // send stop
DSM_0();
}
/*--- Send strings of IRcode -----*/
void Ir_Send(uint8_t *dt,uint8_t x){
for (int j=0;j < x;j++){
sft = 0x01;
for(int i=0;i<8;i++){
DSM_1();
MARK();
DSM_0();
if(dt[j] & sft) SPACE_1();
else SPACE_0();
sft <<= 1;
}
}
}
/*------- Send IOdata code -------*/
void IO_DATA(uint8_t c){
Ir_Leader(); // Leader Start
Ir_Send(&IO[c][0],4); // Send Data1
Ir_Stop(); // Stop
GYAP_0(); // Gyap time
Ir_Leader(); // Leader Start
Ir_Send(&IO[c][4],4); // Send Datae2
Ir_Stop(); // Stop
}
/*-------- Send word of IRcode ------*/
void Ir_Send2(uint16_t wd){
wsft = 0x0001;
for(int i=0;i<16;i++){
DSM_1();
MARK();
DSM_0();
if(wd & wsft) SPACE_1();
else SPACE_0();
wsft <<= 1;
}
}
/*-------- Send IOdata2 IRcode ----*/
void IO_DATA2(uint8_t c){
uint16_t w = IO2[c];
uint16_t wLo = (w & 0x00FF)
| ((~w << 8) & 0xFF00);
uint16_t wHi = ((w >> 8) & 0x00FF)
| (~w & 0xFF00);
Ir_Leader(); // Leader Start
Ir_Send2(IO_CUSTOM); // Send Custom
Ir_Send2(wLo); // Send Data1
Ir_Stop(); // stop
GYAP_0(); // Gyap time
Ir_Leader(); // Leader Start
Ir_Send2(IO_CUSTOM); // Send Custom
Ir_Send2(wHi); // Send Data2
Ir_Stop(); // stop
}
/* ===== Main application ====== */
void main(void)
{
SYSTEM_Initialize();
while (1){
if(PORTCbits.RC0 == 0){
IO_DATA(0);
}else if(PORTCbits.RC1 == 0){
IO_DATA2(1);
}else if(PORTCbits.RC2 == 0){
IO_DATA2(2);
}
__delay_ms(500);
}
}
/**==== End of File ====*/
|