fix type and spacing
This commit is contained in:
parent
5758e46a72
commit
c245295cc3
|
@ -36,20 +36,20 @@
|
||||||
|
|
||||||
/* variables */
|
/* variables */
|
||||||
//volatile uint32_t code = 0; // the code to transmit (read from EEPROM)
|
//volatile uint32_t code = 0; // the code to transmit (read from EEPROM)
|
||||||
volatile int8_t transmit = 0; // transmitting (0: do not transmit, 1: transmit, -1: finish transmiting)
|
volatile int8_t transmit = 0; // transmitting (0: do not transmit, 1: transmit, -1: finish transmitting)
|
||||||
volatile uint8_t phase = 0; // the 4 phases of the bit (2ms pause, 1ms pulse, 2ms pause, 1ms pulse. only transmit during one of the two pulse periode depending on the bit value)
|
volatile uint8_t phase = 0; // the 4 phases of the bit (2ms pause, 1ms pulse, 2ms pause, 1ms pulse. only transmit during one of the two pulse period depending on the bit value)
|
||||||
|
|
||||||
/* configuration bits
|
/* configuration bits
|
||||||
* all set (to 1) per default
|
* all set (to 1) per default
|
||||||
* clear (to 0) relevant bits
|
* clear (to 0) relevant bits
|
||||||
*/
|
*/
|
||||||
uint16_t __at(_CONFIG) __CONFIG = _CPD_OFF & // no data code protect
|
uint16_t __at(_CONFIG) __CONFIG = _CPD_OFF & // no data code protect
|
||||||
_CP_OFF & // no code proect
|
_CP_OFF & // no code project
|
||||||
_BODEN_OFF & // no brown out detect
|
_BODEN_OFF & // no brown out detect
|
||||||
_MCLRE_OFF & // disable master clear reset
|
_MCLRE_OFF & // disable master clear reset
|
||||||
_PWRTE_ON & // enable power-up timeout
|
_PWRTE_ON & // enable power-up timeout
|
||||||
_WDTE_OFF & // no watchdog
|
_WDTE_OFF & // no watchdog
|
||||||
_INTRC_OSC_NOCLKOUT; // use internal oscilator and both I/O pins
|
_INTRC_OSC_NOCLKOUT; // use internal oscillator and both I/O pins
|
||||||
|
|
||||||
/* default code to transmit in EEPROM
|
/* default code to transmit in EEPROM
|
||||||
a megacode is 3 bytes long (MSB of byte 1 is 1)
|
a megacode is 3 bytes long (MSB of byte 1 is 1)
|
||||||
|
@ -100,15 +100,15 @@ void megacode (void) {
|
||||||
led_on();
|
led_on();
|
||||||
timer_2ms();
|
timer_2ms();
|
||||||
}
|
}
|
||||||
} else if (bit==24) { // 25th bit is a blank
|
} else if (bit == 24) { // 25th bit is a blank
|
||||||
led_on();
|
led_on();
|
||||||
tx_off();
|
tx_off();
|
||||||
timer_2ms();
|
timer_2ms();
|
||||||
} else { // restart after 25th bit
|
} else { // restart after 25th bit
|
||||||
phase = 0xff; // phase will be 0 after incrementing
|
phase = 0xff; // phase will be 0 after incrementing
|
||||||
if (transmit == -1) { // stop transmiting if requested
|
if (transmit == -1) { // stop transmitting if requested
|
||||||
led_off();
|
led_off();
|
||||||
transmit = 0; // stop transmiting
|
transmit = 0; // stop transmitting
|
||||||
}
|
}
|
||||||
timer_1ms();
|
timer_1ms();
|
||||||
}
|
}
|
||||||
|
@ -116,23 +116,23 @@ void megacode (void) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* initialize micro-conroller */
|
/* initialize micro-controller */
|
||||||
void init (void) {
|
void init (void) {
|
||||||
TRISIO |= SWITCH; // switch is input
|
TRISIO |= SWITCH; // switch is input
|
||||||
WPU |= SWITCH; // enable pull-up on switch
|
WPU |= SWITCH; // enable pull-up on switch
|
||||||
NOT_GPPU = 0; // enable global weak pull-up for inputs
|
NOT_GPPU = 0; // enable global weak pull-up for inputs
|
||||||
TRISIO &= ~(LED_ANODE|LED_CATHODE|TX); // all other are outputs
|
TRISIO &= ~(LED_ANODE | LED_CATHODE | TX); // all other are outputs
|
||||||
GPIO &= ~(LED_ANODE|LED_CATHODE|TX); // clear output
|
GPIO &= ~(LED_ANODE | LED_CATHODE | TX); // clear output
|
||||||
}
|
}
|
||||||
|
|
||||||
// funcion called on interrupts
|
// function called on interrupts
|
||||||
// interrupt 0 is only one on PIC12
|
// interrupt 0 is only one on PIC12
|
||||||
static void interrupt(void) __interrupt 0
|
static void interrupt(void) __interrupt 0
|
||||||
{
|
{
|
||||||
if (GPIF) { // pin state changed
|
if (GPIF) { // pin state changed
|
||||||
if (GPIO&SWITCH) { // switch is released stop transmission
|
if (GPIO & SWITCH) { // switch is released stop transmission
|
||||||
if (transmit == 1) {
|
if (transmit == 1) {
|
||||||
transmit = -1; // stop transmitting after last transmition
|
transmit = -1; // stop transmitting after last transmission
|
||||||
}
|
}
|
||||||
} else { // switch is pressed, start transmission
|
} else { // switch is pressed, start transmission
|
||||||
if (transmit == 0) { // only transmit if code is loaded
|
if (transmit == 0) { // only transmit if code is loaded
|
||||||
|
@ -166,7 +166,7 @@ void main (void)
|
||||||
PIE1 = 1; // enable timer 1 interrupt
|
PIE1 = 1; // enable timer 1 interrupt
|
||||||
PEIE = 1; // enable timer interrupt
|
PEIE = 1; // enable timer interrupt
|
||||||
|
|
||||||
if (read_eeprom(0)&0x80) { // verify if the code is programm (the MSB bit is always 1 for megacode codes)
|
if (read_eeprom(0) & 0x80) { // verify if the code is program (the MSB bit is always 1 for megacode codes)
|
||||||
GIE = 1; // globally enable interrupts
|
GIE = 1; // globally enable interrupts
|
||||||
} else { // show error and got to sleep forever
|
} else { // show error and got to sleep forever
|
||||||
led_on();
|
led_on();
|
||||||
|
|
Loading…
Reference in New Issue