make function for ir command
This commit is contained in:
parent
f52cb857ab
commit
adef642b5b
95
main.c
95
main.c
|
|
@ -19,19 +19,26 @@
|
|||
#include "main.h"
|
||||
char STATE;
|
||||
char btnState;
|
||||
char addr[] = {0x20,0xDF};
|
||||
char vol_up[] = {0x40,0xBF};
|
||||
char vol_down[] = {0xC0,0x3F};
|
||||
char input_select[] = {0xD0,0x2F};
|
||||
char ok[] = {0x22,0xdd};
|
||||
char power[] = {0x10,0xEF};
|
||||
char ir_command[4];
|
||||
|
||||
void __interrupt() handleInterrupt(void)
|
||||
void __interrupt() handle_interrupt(void)
|
||||
{
|
||||
clear_bit(INTCON, 7);
|
||||
|
||||
if(test_bit(INTCON, 0))
|
||||
{
|
||||
handleIOC();
|
||||
handle_IOC();
|
||||
}
|
||||
|
||||
if(test_bit(PIR1, 0))
|
||||
{
|
||||
handleTMR1();
|
||||
handle_TMR1();
|
||||
}
|
||||
|
||||
set_bit(INTCON, 7);
|
||||
|
|
@ -64,37 +71,38 @@ static inline void init()
|
|||
IOC = INPUT_PINS; //IOC enable for 0,1,3,4,5 pins
|
||||
|
||||
//Configure Timer 1
|
||||
TMR1 = 0; //Clear timer 1 value
|
||||
T1CONbits.TMR1ON = 0; //Turn timer 1 Off
|
||||
T1CONbits.T1CKPS0 = 1; //Set prescale 1:8
|
||||
T1CONbits.T1CKPS1 = 1;
|
||||
PIE1bits.TMR1IE = 1; //Enable timer 1 overflow interrupt
|
||||
INTCONbits.PEIE = 1; //Enable peripheral interrupt
|
||||
|
||||
//Set default state
|
||||
STATE = 0;
|
||||
//TMR1 = 0; //Clear timer 1 value
|
||||
//T1CONbits.TMR1ON = 0; //Turn timer 1 Off
|
||||
//T1CONbits.T1CKPS0 = 1; //Set prescale 1:8
|
||||
//T1CONbits.T1CKPS1 = 1;
|
||||
//PIE1bits.TMR1IE = 1; //Enable timer 1 overflow interrupt
|
||||
//INTCONbits.PEIE = 1; //Enable peripheral interrupt
|
||||
}
|
||||
|
||||
static inline void handleTMR1()
|
||||
static inline void handle_TMR1()
|
||||
{
|
||||
flip_bit(GPIO, 2);
|
||||
TMR1 = 0;
|
||||
clear_bit(PIR1, 0);
|
||||
}
|
||||
|
||||
static inline void handleIOC()
|
||||
static inline void handle_IOC()
|
||||
{
|
||||
|
||||
handleButtons(0);
|
||||
handleButtons(1);
|
||||
handleButtons(3);
|
||||
handleButtons(4);
|
||||
handleButtons(5);
|
||||
handle_buttons(0);
|
||||
handle_buttons(1);
|
||||
handle_buttons(3);
|
||||
handle_buttons(4);
|
||||
handle_buttons(5);
|
||||
if(test_bit(btnState, 5))
|
||||
{
|
||||
STATE = STATE == 0 ? 1 : 0;
|
||||
TMR1 = 0;
|
||||
clear_bit(PIR1, 0);
|
||||
ir_command[0] = addr[0];
|
||||
ir_command[1] = addr[1];
|
||||
ir_command[2] = vol_up[0];
|
||||
ir_command[3] = vol_up[1];
|
||||
|
||||
while(!GP5)
|
||||
send_command(ir_command);
|
||||
}
|
||||
|
||||
clear_bit(INTCON, 0);
|
||||
|
|
@ -103,11 +111,11 @@ static inline void handleIOC()
|
|||
static inline void sleep()
|
||||
{
|
||||
//prepare and go to sleep
|
||||
clear_bit(GPIO, 2); //Turn off led
|
||||
GP2 = 0; //Turn off led
|
||||
SLEEP();
|
||||
}
|
||||
|
||||
static inline void handleButtons(char bit)
|
||||
static inline void handle_buttons(char bit)
|
||||
{
|
||||
clear_bit(btnState, bit);
|
||||
if(!test_bit(GPIO, bit))
|
||||
|
|
@ -119,3 +127,42 @@ static inline void handleButtons(char bit)
|
|||
set_bit(btnState, bit);
|
||||
}
|
||||
}
|
||||
static inline void send_command(char *command)
|
||||
{
|
||||
send(183);
|
||||
__delay_us(4400);
|
||||
GP2 = 0;
|
||||
send_byte(command[0]);
|
||||
send_byte(command[1]);
|
||||
send_byte(command[2]);
|
||||
send_byte(command[3]);
|
||||
send(9);
|
||||
__delay_ms(200);
|
||||
}
|
||||
|
||||
static inline void send_byte(char byte)
|
||||
{
|
||||
char mask = 0b10000000;
|
||||
for(char k=0; k<8; k++)
|
||||
{
|
||||
send(13);
|
||||
if((byte & (mask >> k)) == 0)
|
||||
{
|
||||
__delay_us(400);
|
||||
}
|
||||
else
|
||||
{
|
||||
__delay_us(1500);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static inline void send(int x)
|
||||
{
|
||||
for(int i = 0; i < x; i++)
|
||||
{
|
||||
GP2=1;
|
||||
__delay_us(26);
|
||||
GP2=0;
|
||||
}
|
||||
}
|
||||
9
main.h
9
main.h
|
|
@ -1,5 +1,8 @@
|
|||
static inline void sleep();
|
||||
static inline void init();
|
||||
static inline void handleButtons(char bit);
|
||||
static inline void handleIOC();
|
||||
static inline void handleTMR1();
|
||||
static inline void handle_buttons(char bit);
|
||||
static inline void handle_IOC();
|
||||
static inline void handle_TMR1();
|
||||
static inline void send_command(char *command);
|
||||
static inline void send_byte(char byte);
|
||||
static inline void send(int x);
|
||||
|
|
@ -1,11 +1,11 @@
|
|||
#
|
||||
#Sun Mar 17 17:44:34 MSK 2024
|
||||
#Mon Mar 18 06:01:25 MSK 2024
|
||||
default.languagetoolchain.version=2.45
|
||||
default.Pack.dfplocation=C\:\\Program Files\\Microchip\\MPLABX\\v6.15\\packs\\Microchip\\PIC10-12Fxxx_DFP\\1.6.174
|
||||
conf.ids=default
|
||||
default.languagetoolchain.dir=C\:\\Program Files\\Microchip\\xc8\\v2.45\\bin
|
||||
host.id=1jna-tnj5-7f
|
||||
configurations-xml=07975d7e7282e550ac8decaaea8a2cd7
|
||||
configurations-xml=215034e96a2f762c825b7c03119c12d4
|
||||
default.com-microchip-mplab-mdbcore-PICKit3Tool-PICkit3DbgToolManager.md5=50072f33d27b72924000ca2dca4b7622
|
||||
com-microchip-mplab-nbide-embedded-makeproject-MakeProject.md5=e62346c0c0ecee2637e613b49cb7b7fa
|
||||
default.com-microchip-mplab-nbide-toolchain-xc8-XC8LanguageToolchain.md5=486b02ed36e5bdffb1f797e38fa058e5
|
||||
|
|
|
|||
|
|
@ -183,7 +183,7 @@
|
|||
<property key="programoptions.preservedataflash" value="false"/>
|
||||
<property key="programoptions.preservedataflash.ranges"
|
||||
value="${programoptions.preservedataflash.ranges}"/>
|
||||
<property key="programoptions.preserveeeprom" value="true"/>
|
||||
<property key="programoptions.preserveeeprom" value="false"/>
|
||||
<property key="programoptions.preserveeeprom.ranges" value="0-7f"/>
|
||||
<property key="programoptions.preserveprogram.ranges" value=""/>
|
||||
<property key="programoptions.preserveprogramrange" value="false"/>
|
||||
|
|
@ -230,7 +230,7 @@
|
|||
<property key="programoptions.preservedataflash" value="false"/>
|
||||
<property key="programoptions.preservedataflash.ranges"
|
||||
value="${programoptions.preservedataflash.ranges}"/>
|
||||
<property key="programoptions.preserveeeprom" value="true"/>
|
||||
<property key="programoptions.preserveeeprom" value="false"/>
|
||||
<property key="programoptions.preserveeeprom.ranges" value="0-7f"/>
|
||||
<property key="programoptions.preserveprogram.ranges" value=""/>
|
||||
<property key="programoptions.preserveprogramrange" value="false"/>
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user