📄 main.lst
字号:
....................
.................... #pragma int_rtcc // install as interrupt handler (comment for HiTech!)
.................... interrupt
.................... rxi()
.................... {
.................... // this routine gets called every time TMR0 overflows
.................... RFBit = RFIn; // sampling RF pin verify!!!
.................... TMR0 -= PERIOD; // reload
.................... T0IF = 0;
....................
.................... XTMR++; // extended 16 long timer update
....................
.................... if (RFFull) // avoid overrun
.................... return;
....................
.................... switch( RFstate) // state machine main switch
.................... {
....................
.................... case TRFUNO:
.................... if ( RFBit == 0)
.................... { // falling edge detected ----+
.................... // |
.................... // +----
.................... RFstate= TRFZERO;
.................... }
.................... else
.................... { // while high
.................... RFcount--;
.................... if ( RFcount < HIGH_TO)
.................... RFstate = TRFreset; // reset if too long
.................... }
.................... break;
....................
.................... case TRFZERO:
.................... if ( RFBit)
.................... { // rising edge detected +----
.................... // |
.................... // ----+
.................... RFstate= TRFUNO;
.................... B[Bptr] >>= 1; // rotate
.................... if ( RFcount >= 0)
.................... {
.................... B[Bptr]+=0x80; // shift in bit
.................... }
.................... RFcount = 0; // reset length counter
....................
.................... if ( ( ++BitCount & 7) == 0) //receiver gradation
.................... Bptr++; // advance one byte
.................... if (BitCount == NBIT)
.................... {
.................... RFstate = TRFreset; // finished receiving
.................... RFFull = TRUE;
.................... }
.................... }
.................... else
.................... { // still low
.................... RFcount++;
.................... if ( RFcount >= LOW_TO) // too long low
.................... {
.................... RFstate = TRFSYNC; // fall back into RFSYNC state
.................... Bptr = 0; // reset pointers, while keep counting on
.................... BitCount = 0;
.................... }
.................... }
.................... break;
....................
.................... case TRFSYNC:
.................... if ( RFBit)
.................... { // rising edge detected +---+ +---..
.................... // | | <-Theader-> |
.................... // +----------------+
.................... if ( ( RFcount < SHORT_HEAD) || ( RFcount >= LONG_HEAD))
.................... {
.................... RFstate = TRFreset;
.................... break; // too short/long, no header
.................... }
.................... else
.................... {
.................... RFcount =0; // restart counter
.................... RFstate= TRFUNO;
.................... }
.................... }
.................... else
.................... { // still low
.................... RFcount++;
.................... }
.................... break;
....................
.................... case TRFreset:
.................... default:
.................... RFstate = TRFSYNC; // reset state machine in all other cases
.................... RFcount = 0;
.................... Bptr = 0;
.................... BitCount = 0;
.................... break;
....................
.................... } // switch
....................
....................
.................... } // rxi
....................
....................
.................... void InitReceiver()
.................... {
.................... T0IF = 0;
.................... T0IE = 1; // TMR0 overflow interrupt
.................... GIE = 1; // enable interrupts
.................... RFstate = TRFreset; // reset state machine in all other cases
.................... RFFull = 0; // start with buffer empty
.................... XTMR = 0; // start extended timer
.................... } */
....................
....................
....................
....................
....................
....................
....................
....................
....................
.................... //
.................... // external modules
.................... //
.................... #include "mem-87x.c" // EEPROM I2C routines
.................... // *********************************************************************
.................... // Filename: mem-87x.c
.................... // *********************************************************************
.................... // Author: skywang
.................... // Company: cjae Technology
.................... // Revision: Rev 1.00
.................... // Date: 08/07/07
.................... //
.................... // Interrupt based receive routine
.................... //
.................... // Compiled using HiTech PIC C compiler v.7.93
.................... // Compiled using CCS PIC C compiler v.2.535
.................... // *********************************************************************
.................... /*
.................... void RDword(word Ind)
.................... {
.................... Dato = EEPROM_READ( Ind);
.................... Dato += (word) EEPROM_READ( Ind+1) <<8;
.................... }
....................
.................... void RDnext()
.................... {
.................... // continue reading
.................... EEADR++; // NOTE generate no carry
.................... Dato = ((RD=1), EEDATA);
.................... EEADR++;
.................... Dato += ((RD=1), EEDATA)<<8;
.................... }
....................
.................... void WRword(word Ind)
.................... {
.................... EEPROM_WRITE( Ind, Dato); GIE = 1; // write and re-enable interrupt
.................... EEPROM_WRITE( Ind+1, Dato>>8); GIE = 1;
.................... }*/
....................
....................
....................
.................... #include "table.c" // TABLE management
....................
....................
.................... // *********************************************************************
.................... // Filename: TABLE.c
.................... // *********************************************************************
.................... // Author: skywang
.................... // Company: cjae Technology
.................... // Revision: Rev 1.00
.................... // Date: 08/07/07
.................... //
.................... // EEPROM TABLE Management routines
.................... // simple "linear list" management method
.................... //
.................... // Compiled using HiTech PIC C compiler v.7.93
.................... // Compiled using CCS PIC C compiler v.2.535
.................... // ********************************************************************/
.................... /*
.................... #define MAX_USER 8 // max number of TX that can be learned
.................... #define EL_SIZE 8 // single record size in bytes
....................
....................
.................... // ------------------------------------------------------------
.................... //Table structure definition:
.................... //
.................... // the EEPROM is filled with an array of MAX_USER user records
.................... // starting at address 0000
.................... // each record is EL_SIZE byte large and contains the following fields:
.................... // EEPROM access is in 16 bit words for efficiency
.................... //
.................... // DatoHi DatoLo offset
.................... // +-------+-------+
.................... // | FCode | IDLo | 0 XF contains the function codes (buttons) used during learning
.................... // +-------+-------+ and the top 4 bit of Serial Number
.................... // | IDHi | IDMi | +2 IDHi IDMi IDLo contain the 24 lsb of the Serial Number
.................... // +-------+-------+
.................... // | HopHi | HopLo | +4 sync counter
.................... // +-------+-------+
.................... // | HopHi2| HopLo2| +6 second copy of sync counter for integrity checking
.................... // +-------+-------+
.................... //
.................... // NOTE a function code of 0f0 (seed transmission) is considered
.................... // invalid during learning and is used here to a mark location free
.................... //
.................... // -----------------------------------------------------------
.................... // FIND Routine
.................... //
.................... // search through the whole table the given a record whose ID match
.................... //
.................... // INPUT:
.................... // IDHi, IDMi, IDLo, serial number to search
.................... //
.................... // OUTPUT:
.................... // Ind address of record (if found)
.................... // EHop sync counter value
.................... // ETemp second copy of sync counter
.................... // RETURN: TRUE if matching record found
.................... //
.................... byte Find()
.................... {
.................... byte Found;
.................... Found = FALSE; // init to not found
....................
.................... for (Ind=0; Ind < (EL_SIZE * MAX_USER); Ind+=EL_SIZE)
.................... {
.................... RDword( Ind); // read first Word
.................... FCode = (Dato>>8);
.................... // check if 1111xxxx
.................... if ( (FCode & 0xf0) == 0xf0)
.................... continue; // empty
....................
.................... if (IDLo != (Dato & 0xff))
.................... continue; // fails match
....................
.................... RDnext(); // read next word
.................... if ( ( (Dato & 0xff) == IDMi) && ( (Dato>>8) == IDHi))
.................... {
.................... Found = TRUE; // match
.................... break;
.................... }
.................... } // for
....................
.................... if (Found == TRUE)
.................... {
.................... RDnext(); // read HopHi/Lo
.................... EHop = Dato;
.................... RDnext(); // read HopHi2/Lo2
.................... ETemp= Dato;
.................... }
....................
.................... return Found;
.................... }
....................
.................... // -----------------------------------------------------------
.................... //INSERT Routine
.................... //
.................... //search through the whole table for an empty space
.................... //
.................... //INPUT:
.................... // IDHi, IDMi, IDLo, serial number to insert
.................... //
.................... //OUTPUT:
.................... // Ind address of empty record
.................... //
.................... //RETURN: FALSE if no empty space found
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -