📄 main.lst
字号:
.................... //
....................
.................... void Remote( void);
....................
....................
.................... //
.................... // MAIN
.................... //
.................... // Main program loop, I/O polling and timing
.................... //
....................
.................... void main ()
.................... {
0004: CLRF 04
0005: MOVLW 1F
0006: ANDWF 03,F
....................
.................... // init
.................... ADCON1 = 0x7; // disable analog inputs
0007: MOVLW 07
0008: BSF 03.5
0009: MOVWF 1F
.................... TRISA = MASKPA; // set i/o config.
000A: MOVLW FF
000B: MOVWF 05
.................... TRISB = MASKPB;
000C: MOVLW C0
000D: MOVWF 06
.................... TRISC = MASKPC;
000E: MOVLW FF
000F: MOVWF 07
.................... PORTA = 0; // init all outputs
0010: BCF 03.5
0011: CLRF 05
.................... PORTB = 0;
0012: CLRF 06
.................... PORTC = 0;
0013: CLRF 07
.................... OPTION = 0x8f; // prescaler assigned to WDT,
0014: MOVLW 8F
0015: BSF 03.5
0016: MOVWF 01
.................... // TMR0 clock/4, no pull ups
....................
....................
.................... CTLearn = 0; // Learn debounce
0017: BCF 03.5
0018: CLRF 31
.................... CLearn = 0; // Learn timer
0019: CLRF 30
.................... COut = 0; // output timer
001A: CLRF 34
.................... CFlash = 0; // flash counter
001B: CLRF 32
.................... CTFlash = 0; // flash timer
001C: CLRF 33
.................... FLearn = FALSE; // start in normal mode
001D: BCF 2E.2
.................... F2Chance = FALSE; // no resynchronization required
001E: BCF 2E.3
....................
.................... // InitReceiver(); // enable and init the receiver state machine
....................
.................... // main loop
.................... while ( TRUE)
.................... { /*
.................... if ( RFFull) // buffer contains a message
.................... Remote();
....................
.................... // loop waiting 512* period = 72ms
.................... if ( XTMR < 512)
.................... continue; // main loop
....................
.................... // once every 72ms
.................... XTMR=0;
....................
.................... // re-init fundamental registers
.................... ADCON1 = 0x7; // disable analog inputs
.................... TRISA = MASKPA; // set i/o config.
.................... TRISB = MASKPB;
.................... TRISC = MASKPC;
.................... OPTION = 0x0f; // prescaler assigned to WDT, TMR0 clock/4, pull up
.................... T0IE = 1;
.................... GIE = 1;
....................
.................... // poll learn
.................... if ( !Learn) // low -> button pressed
.................... {
.................... CLearn++;
....................
.................... // pressing Learn button for more than 10s -> ERASE ALL
.................... if (CLearn == 128) // 128 * 72 ms = 10s
.................... {
.................... Led = OFF; // switch off Learn Led
.................... while( !Learn); // wait for button release
.................... Led = ON; // signal Led on
.................... ClearMem(); // erase all comand!
.................... COut = TOUT; // single lomg flash pulse time
.................... // timer will switch off Led
.................... CLearn = 0; // reset learn debounce
.................... FLearn = FALSE; // exit learn mode
.................... }
....................
.................... // normal Learn button debounce
.................... if (CLearn == 4) // 250ms debounce
.................... {
.................... FLearn = TRUE; // enter learn mode comand!
.................... CTLearn = TLEARN; // load timout value
.................... Led = ON; // turn Led on
.................... }
.................... }
.................... else CLearn=0; // reset counter
....................
.................... // outputs timing
.................... if ( COut > 0) // if timer running
.................... {
.................... COut--;
.................... if ( COut == 0) // when it reach 0
.................... {
.................... Led = OFF; // all outputs off
.................... Out0 = OFF;
.................... Out1 = OFF;
.................... Out2 = OFF;
.................... Out3 = OFF;
.................... Vlow = OFF;
.................... }
.................... }
....................
.................... // Learn Mode timout after 18s (TLEARN * 72ms)
.................... if ( CTLearn > 0)
.................... {
.................... CTLearn--; // count down
.................... if ( CTLearn == 0) // if timed out
.................... {
.................... Led = OFF; // exit Learn mode
.................... FLearn = FALSE;
.................... }
.................... }
....................
.................... // Led Flashing
.................... if ( CFlash > 0)
.................... {
.................... CTFlash--; // count down
.................... if ( CTFlash == 0) // if timed out
.................... {
.................... CTFlash = TFLASH; // reload timer
.................... CFlash--; // count one flash
.................... Led = OFF; // toggle Led
.................... if ( CFlash & 1)
.................... Led = ON;
.................... }
.................... }
....................
.................... */ } // main loop
001F: GOTO 01F
....................
.................... } // main
....................
....................
.................... //
.................... // Remote Routine
.................... //
.................... // Decrypts and interprets receive codes
.................... // Does Normal Operation and Learn Mode
.................... //
.................... // INPUT: Buffer contains the received code word
.................... //
.................... // OUTPUT: S0..S3 and LearnOut
.................... //
....................
.................... void Remote()
.................... {
0020: SLEEP
.................... /*
.................... // a frame was received and is stored in the receive buffer
.................... // move it to decryption Buffer, and restart receiving
.................... memcpy( Buffer, B, 9);
.................... RFFull = FALSE; // ready to receive a new frame
....................
.................... // decoding
.................... NormalKeyGen(); // compute the decryption key
.................... Decrypt(); // decrypt the hopping code portion
....................
.................... if ( DecCHK() == FALSE) // decription failed
.................... return;
....................
.................... if ( FLearn)
.................... {
.................... // Learn Mode
....................
.................... if ( Find()== FALSE)
.................... // could not find the Serial Number in memory
.................... {
.................... if ( !Insert()) // look for new space
.................... return; // fail if no memory available
.................... }
....................
.................... // ASSERT Ind is pointing to a valid memory location
.................... IDWrite(); // write Serial Number in memory
.................... FHopOK = TRUE; // enable updating Hopping Code
.................... HopUpdate(); // Write Hoping code in memory
....................
.................... CFlash = 32; // request Led flashing
.................... CTFlash = TFLASH; // load period timer
.................... Led = TRUE; // start with Led on
.................... FLearn = FALSE; // terminate successfully Learn
.................... } // Learn
....................
.................... else // Normal Mode of operation
.................... {
.................... if ( Find()== FALSE)
.................... return;
.................... if ( !HopCHK()) // check Hopping code integrity
.................... return;
....................
.................... if ( FSame) // identified same code as last memorized
.................... {
.................... if ( COut >0) // if output is still active
.................... COut = TOUT; // reload timer to keep active
.................... else
.................... return; // else discard
.................... }
....................
.................... else // hopping code incrementing properly
.................... {
.................... HopUpdate(); // update memory
....................
....................
.................... // set outputs according to function code
.................... if ( BIT_TEST(Buffer[3],S0))
.................... Out0 = ON;
.................... if ( BIT_TEST(Buffer[3],S1))
.................... Out1 = ON;
.................... if ( BIT_TEST(Buffer[3],S2))
.................... Out2 = ON;
.................... if ( BIT_TEST(Buffer[3],S3))
.................... Out3 = ON;
....................
.................... // set low battery flag if necessary
.................... if ( BIT_TEST(Buffer[8],VFlag))
.................... Vlow = ON;
....................
.................... // check against learned function code
.................... if ( (( Buffer[7] ^ FCode) & 0xf0) == 0)
.................... Led = ON;
....................
.................... // init output timer
.................... COut = TOUT;
.................... }// recognized
.................... } // normal mode
.................... */
.................... } // remote
....................
....................
....................
....................
....................
....................
....................
Configuration Fuses:
Word 1: 3FFB RC NOWDT NOPUT NOPROTECT BROWNOUT
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -