#include <16f628a.h>
#fuses INTRC_IO, NOWDT, BROWNOUT, NOLVP
#use delay(internal=4MHz)
#define LED PIN_B4
#define IR PIN_B3
#define RELAY1 PIN_A2
#define RELAY2 PIN_A3
#define RELAY3 PIN_B1
#define RELAY4 PIN_B2
/* TIMER0 configuration */
#define TIMER0_CONFIG RTCC_INTERNAL | RTCC_DIV_1
/* Interrupt rate: */
/* 4/4000000*65536*1 = 0.256 ms */
/* */
/* Start: 3.0 ms (ignored) */
/* "1": 1.8 ms (225) */
/* "0": 1.2 ms (150) */
/*
*/
#define ONE_MIN 190
#define ONE_MAX 400
#define ZERO_MIN 10
#define ZERO_MAX 185
short rly1,rly2,rly3,rly4,state;
/* irframes[0] (start) will be garbage, ignore it... */
int16 irframes[13];
int8 ircount = 0;
int1 irdone = FALSE;
#int_ccp1
void ext_ccp1() {
if (irdone) return;
irframes[ircount++] = get_timer0();
if (ircount >= 13)
irdone = TRUE;
set_timer0(0);
enable_interrupts(INT_TIMER0);
//#output_bit(LED,1);delay_ms(1);output_bit(LED,0);delay_ms(1);
}
#int_timer0
void timer0_isr() {
disable_interrupts(INT_TIMER0);
}
#separate
int1 decode_ir(int8 &addr, int8 &cmd) {
int8 i;
int8 mask;
int8 bits[13];
addr = 0;
cmd = 0;
for (i=1; i<=12; i++) {
if ((ONE_MIN <= irframes[i]) && (irframes[i] <= ONE_MAX))
bits[i] = 0x01;
else
if ((ZERO_MIN <= irframes[i]) && (irframes[i] <= ZERO_MAX))
bits[i] = 0x00;
else // Error
return FALSE;
}
mask = 0x01;
for (i=1; i<=7; i++) {
if (bits[i])
cmd = cmd | mask;
mask <<= 1;
}
mask = 0x01;
for (i=8; i<=12; i++) {
if (bits[i])
addr = addr | mask;
mask <<= 1;
}
return TRUE;
}
void start_ir() {
memset(irframes, 0x00, sizeof(irframes));
ircount = 0;
irdone = FALSE;
}
void led_blink(int i)
{
int j;
for (j=0;j>
Tuesday, November 22, 2011
Code Dump: Remote Controlled 4 Channel Relay
Labels:
CCP1,
microchip,
pic16f628,
relay control,
Sony Remote,
state
Saturday, November 19, 2011
MSP430 : Hello World LED Blink program
This is my first program to blink all LEDs connected on PORT3 of MSP430 onboard TI MSP430FR5739 experimenters board.
/******************************************************************
* This is my first project on my MSP430FR5739 experimenter board.
* In this project I will attempt to blink all onboard LEDs which
* are connected to Port 3.
* Pseudo code as follows
* 1. Initialise port 3 as an output port.
* 2. Set Port 3 to digital low.
* 3. Initialise Loop
* 4. Set Port 3 to Digital High
* 5. Delay (Hold State).
* 6. Set Port 3 to Digital Low
* 7. Delay (Hold State).
* 8. Loop End
*******************************************************************/
#include "msp430fr5739.h"
#include "FR_EXP.h"
void delay(void);
void main(void) {
WDTCTL = WDTPW + WDTHOLD;
P3DIR = 0xFF; // initialize Port 3 as output by ensuring bit 0 is 0.
for (;;) { // Initialise loop
P3OUT=0xff;
__delay_cycles(100000); // SW Delay of 10000 cycles at 1Mhz
P3OUT=0x00;
__delay_cycles(100000); // SW Delay of 10000 cycles at 1Mhz
}//for loop
} // main
void delay(void) {
int i;
for (i=0; i<0xFF; i++) {
}
} // delay
Subscribe to:
Posts (Atom)