/* * * DOORKING TRANSMITTER CLONE v1.0 * * This code will duplicate the digital output sequence for doorking transmitters * http://www.pagemac.com/azure/doorking.php * * Uses PIC12F629 * * Made by Daniel Smith and Kevin Martin, 2012 * */ #include "pic.h" #include #include //__CONFIG(INTIO & WDTDIS & PWRTEN & MCLREN & BORDIS & UNPROTECT); // for MCC18 __CONFIG(FOSC_INTRCIO & WDTE_OFF & PWRTE_OFF & MCLRE_ON & BOREN_OFF & CP_OFF & CPD_OFF); // for XC8 volatile char intflag; // output a baseband bit void outputbit(char in) { // set timer for ~1ms TMR1H=0xfc; TMR1L=0x67; //fc69 intflag=0; GPIO5=in; // set output pin T1CON=0x01; //enable timer while (!intflag) ; T1CON=0x00; //disable timer // set timer for ~2ms TMR1H=0xf8; TMR1L=0x75; // f877 intflag=0; GPIO5=0; // clear output pin T1CON=0x01; //enable timer while (!intflag) ; T1CON=0x00; //disable timer } int main(void) { // configure the facility code and serial number here unsigned char fc=5; unsigned short sn=5555; unsigned char cbit; // set up the device TRISIO2=0; TRISIO4=1; TRISIO5=0; WPU=0; T1CON=0x00; INTCON=0xc8; // enable IoC and timer interrupts IOCbits.IOCB4=1; // enable interrupt on change for GPIO4 (button) GPIE=1; TMR1IE=1; while (1) { unsigned char outbyte; // check if button is pressed (active low) if (GPIO4) { // button not pressed GPIO2=0; //turn off led SLEEP(); // sleep to save power NOP(); NOP(); NOP(); } else // button is pressed { GPIO2=1; // turn on led // the output sequence is 24 manchester-encoded bits // the sequence has a start bit (1), 6 bit facility code, 14 bit serial num, and stop sequence (101) // a manchester 0 is 10, a manchester 1 is 01 // data is sent MSB first // start bit outputbit(1); // facility code: 6 bits outbyte=fc<<2; for (cbit=6; cbit; cbit--) { if (outbyte & 0x80) { outputbit(0); outputbit(1); } else { outputbit(1); outputbit(0); } outbyte<<=1; } // serial number: 14 bits outbyte=sn>>6; for (cbit=8; cbit; cbit--) { if (outbyte & 0x80) { outputbit(0); outputbit(1); } else { outputbit(1); outputbit(0); } outbyte<<=1; } outbyte=(sn<<2)&0xff; for (cbit=6; cbit; cbit--) { if (outbyte & 0x80) { outputbit(0); outputbit(1); } else { outputbit(1); outputbit(0); } outbyte<<=1; } // stop sequence (manchester encoded: 010) outputbit(1); outputbit(0); outputbit(0); outputbit(1); outputbit(1); outputbit(0); // pause for 12ms (VERY IMPORTANT) // the gap between sequences is critical! TMR1H=0xd8; TMR1L=0x7d; //fc69 intflag=0; T1CON=0x01; //enable timer while (!intflag) ; T1CON=0x00; //disable timer } } return 0; } // interrupt vector void interrupt isr(void) { if (TMR1IF) { // timer interrupt TMR1IF=0; intflag=1; } else if (GPIF) { // button press interrupt GPIO4; GPIO5 = 0; GPIF=0; } }