PORTB = 0xFF; //SET PORT B AS INPUT PORT
TRISB = 1; //INITIALISE PORT B AS 0
void interrupt a(void)
{
if (RBIF = 1) ??? RBIF == 1
if(IOCA0 =~ 1)Run_Motor1_cw();
if(IOCB4 =~ 1)Run_Motor2_cw();
if(IOCB4 =~ 1)Run_Motor1_ccw();
if(IOCB6 =~ 1)Run_Motor2_ccw();
void interrupt a(void)
{
static unsigned char this_reading, last_reading = 0;
if(RABIF == 1)
{
this_reading = PORTB; /* reading the port clears the mismatch */
if((last_reading & 0x10) != (this_reading & 0x10)){ /* Has RB4 changed? */
Run_Motor2_cw();
}
else if((last_reading & 0x20) != (this_reading & 0x20)){ /* Has RB5 changed? */
Run_Motor1_ccw();
}
else if((last_reading & 0x40) != (this_reading & 0x40)){ /* Has RB6 changed? */
Run_Motor2_ccw();
}
last_reading = this_reading;
PORTA = 0x02; //SWITCH ON AN LED
__delay_ms(450); //DELAY (AROUND 1SEC)
PORTA = 0x00; //WITCH LED OFF
RABIF = 0;
}
}
unsigned char delay;
if(INTF == 1)
{
delay = 2; /* delay time */
while(delay--){
;
}
if(PORTA.F2 == 0){
motor_change = True;
}
else{
motor_change = False;
}
INTF = 0;
}
/*** HISTORY OF CHANGE *********************************************************
*
* 07.10.2011 Initial Version
*
*
*
*
******************************************************************************/
#include <RC5 IR Remote.h>
#include "types.h"
/* --- RC5 driver configuration --- */
#define RC5_DATA_PIN PIN_A4 /* IR sensor (SFH5110-36) connected to RB1 */
#define RC5_TICKS_PER_MS (1000/32) /* timer increments every 31.25 us */
/* i.e. around 1000 ticks per millisecond */
#define RC5_GetTimer() get_timer0() /* timer0 shall be used for RC5 decoding */
/* --- macros to switch on/off LED --- */
#define Led_On() output_high(PIN_A0)
#define Led_Off() output_low(PIN_A0)
/* RC5 driver include */
#include <RC5_driver.h>
/*******************
//PORT C Register = 0x07
//PORT A Register = 0x05
*********************/
#BIT RL1 = 0x07.0
#BIT RL2 = 0x07.1
#BIT RL3 = 0x07.2
#BIT RL4 = 0x07.3
#BIT RL5 = 0x07.4
#BIT RL6 = 0x07.5
#BIT RL7 = 0x05.1
#BIT RL8 = 0x05.2
/******************************************************************************
Key Codes
*****************************************************************************/
#define RC5_NUMERIC_KEY_0 0x00 /* NUMERIC KEY 0 */
#define RC5_NUMERIC_KEY_1 0x01 /* NUMERIC KEY 1 */
#define RC5_NUMERIC_KEY_2 0x02 /* NUMERIC KEY 2 */
#define RC5_NUMERIC_KEY_3 0x03 /* NUMERIC KEY 3 */
#define RC5_NUMERIC_KEY_4 0x04 /* NUMERIC KEY 4 */
#define RC5_NUMERIC_KEY_5 0x05 /* NUMERIC KEY 5 */
#define RC5_NUMERIC_KEY_6 0x06 /* NUMERIC KEY 6 */
#define RC5_NUMERIC_KEY_7 0x07 /* NUMERIC KEY 7 */
#define RC5_NUMERIC_KEY_8 0x08 /* NUMERIC KEY 8 */
#define RC5_NUMERIC_KEY_9 0x09 /* NUMERIC KEY 9 */
/*****************************************************************************/
/* Interrupt_RA */
/* */
/* Port A change interrupt service routine. */
/* Used to decode RC5 IR signal. */
/*****************************************************************************/
#INT_RA
void Interrupt_RA(void)
{
Led_On();
RC5_InterruptHandler();
Led_Off();
clear_interrupt(INT_RA4);
}
/*****************************************************************************/
/* main */
/* */
/* Configures timer0 as time base for RC5 decoding and enables port A */
/* interrupt on change. */
/* Main loop checks if a RC5 code has been received and processes the code */
/* in the switch-case statement */
/*****************************************************************************/
/* NOTE: Currently it only works if PIC is reset after programming? */
void main()
{
unsigned int16 rc5code;
unsigned int rc5cmd;
setup_comparator(NC_NC); // All Ports Digital
/* FOSC/4 is timer source */
/* Original Configuration:
/* FOSC = 20MHz => 5MHz, i.e. timer increment every t = 1/(FOSC/4) = 200ns */
/* with prescaler of 128 timer will increment every 25.6us */
// 16F676 Running at Internal 4 Mhz Configuration:
// Timer0 increments every 1 us (4 Mhz/4 = 1 Mhz)
setup_timer_0(RTCC_INTERNAL | RTCC_DIV_32);
// TRIS Ports set by #use fixed_io in RC5 IR Remote.h
/* read port A to clear mismatch condition */
input_a();
/* configure port A interrupt on change */
clear_interrupt(INT_RA); /* clear port A interrupt flag */
enable_interrupts(INT_RA); /* enable RA4 interrupt on change */
/* global interrupt enable */
enable_interrupts(GLOBAL);
// Main Loop
while (1)
{
/* check if new data is available */
if (RC5_CodeReady())
{
/* get code */
rc5code = RC5_GetCode();
// Extract command from RC5 code
rc5cmd = RC5_GetCmd(rc5code);
switch (rc5cmd)
{
case RC5_NUMERIC_KEY_0:
RL1 = ~RL1;
break;
case RC5_NUMERIC_KEY_1:
RL2 = ~RL2;
break;
case RC5_NUMERIC_KEY_2:
RL3 = ~RL3;
break;
case RC5_NUMERIC_KEY_3:
RL4 = ~RL4;
break;
case RC5_NUMERIC_KEY_4:
RL5 = ~RL5;
break;
case RC5_NUMERIC_KEY_5:
RL6 = ~RL6;
break;
case RC5_NUMERIC_KEY_6:
RL7 = ~RL7;
break;
case RC5_NUMERIC_KEY_7:
RL8 = ~RL8;
break;
case RC5_NUMERIC_KEY_8:
RL1 = 1;
RL2 = 1;
RL3 = 1;
RL4 = 1;
RL5 = 1;
RL6 = 1;
RL7 = 1;
RL8 = 1;
break;
case RC5_NUMERIC_KEY_9:
RL1 = 0;
RL2 = 0;
RL3 = 0;
RL4 = 0;
RL5 = 0;
RL6 = 0;
RL7 = 0;
RL8 = 0;
break;
}
}
/* this function increments the RC5 timeout timer */
/* NOTE: Decoding will also work without calling this function, but */
/* it could happen that RC5 codes are sometimes not getting */
/* recognized because of decoding state machine stucks due */
/* to erroneous RC5 signal. */
RC5_TimeoutIncrement();
}
}
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?