void SystemSetup(void) { IORegSetup(); // Setup.c #if defined(USE_TIMER) TimerRegSetup(); // Setup.c TimerSetup(); // Setup.c #endif #if (defined(USE_UART) || defined(USE_MU)) UartRegSetup(); // Setup.c UartSetup(); // Uart.c #endif #if defined(USE_EXINT) ExintRegSetup(); // Setup.c #endif #if defined(USE_PCINT) PcintRegSetup(); // Setup.c #endif #if defined(USE_EXINT) ExintSetup(); #endif #if defined(USE_PCINT) PcintSetup(); #endif #if defined(USE_ENCODER) EncoderSetup(); // Encoder.c #endif #if defined(USE_MU) MuSetup(); // Mu.c #endif #if defined(USE_MOTOR) MotorSetup(); // Motor.c #endif #if defined(USE_SERVO) ServoSetup(); // Servo.c #endif #if defined(USE_SAFETY) SafetySetup(); // Safety.c #endif }
void main(void) { // WDT ~350ms, ACLK=1.5kHz, interval timer WDTCTL = WDT_ADLY_16; // Enable WDT interrupt IE1 |= WDTIE; SLAVE_SELECT_PORT_SET; SLAVE_SELECT_HIGH; ENABLE_PORT_SET; ENABLE_TRF; // wait until TRF7970A system clock started McuDelayMillisecond(2); // settings for communication with TRF7970A Trf7970CommunicationSetup(); // Set Clock Frequency and Modulation Trf7970InitialSettings(); // set the DCO to 8 MHz McuOscSel(1); // Re-configure the USART with this external clock Trf7970ReConfig(); // Configure UART UartSetup(); /************ Smart Medical NFC Scanner Project ************/ McuDelayMillisecond(5); UartSendCString("[INFO] NFC Reader ENABLED."); UartPutCrlf(); McuDelayMillisecond(2); P1SEL &= ~0x08; // Select Port 1 P1.3 (push button) P1DIR &= ~0x08; // Port 1 P1.3 (push button) as input, 0 is input P1REN |= 0x08; // Enable Port P1.3 (push button) pull-up resistor P1IE |= 0x08; // Port 1 Interrupt Enable P1.3 (push button) P1IFG &= ~0x08; // Clear interrupt flag /************ Smart Medical NFC Scanner Project ************/ // General enable interrupts __bis_SR_register(GIE); // indicates that setting are done enable = 1; // stand alone mode stand_alone_flag = 1; // launchpad LED1 P1DIR |= BIT0; //init function for the patient array init_patient(); P1IN&=BIT3; ///< Port 1.3 (left button) as input as mode switch while(1) { Tag_Count = 0; IRQ_OFF; DISABLE_TRF; // Enter LPM3 __bis_SR_register(LPM3_bits); // launchpad LED1 - Toggle (heartbeat) P1OUT ^= BIT0; // Clear IRQ Flags before enabling TRF7970A IRQ_CLR; IRQ_ON; ENABLE_TRF; /************ Smart Medical NFC Scanner Project ************/ // Must wait at least 4.8 ms to allow TRF7970A to initialize. __delay_cycles(40000); #ifdef ENABLE15693 found_tag_ISO15693 = Iso15693FindTag( edit_mode ); ///< Scan for 15693 tags #endif #ifdef ENABLE14443A found_tag_ISO14443a = Iso14443aFindTag( edit_mode ); ///< Scan for 14443A tags #endif /* We are not using 14443B type tag #ifdef ENABLE14443B //Iso14443bFindTag(); // Scan for 14443B tags #endif */ /** * Write total number of tags read to UART */ if(Tag_Count > 0){ Tag_Count = UartNibble2Ascii(Tag_Count & 0x0F); ///< convert to ASCII UartSendCString("[INFO] Tags Found: "); UartPutChar(Tag_Count); UartPutCrlf(); UartPutCrlf(); } /** * If either type of tag is found: * reset empty scan counter, * reset delay factor, * delay MCU to prevent duplicate scan, * reset tag found counter for both types of tag. * */ if( ( found_tag_ISO15693 == 1 ) || ( found_tag_ISO14443a == 1 ) ) { empty_scan_cnt = 0; delay_factor = 0; McuDelayMillisecond( SCAN_DELAY_INIT_MS ); found_tag_ISO15693 = 0; found_tag_ISO14443a = 0; } /** * If edit mode is disabled: * delay MCU by an increasing amount of time based on * delay_factor and initial delay, * increase empty scan counter. * */ if( edit_mode == 0 ) { //Dynamic delay for power saving McuDelayMillisecond( delay_factor*SCAN_DELAY_INIT_MS ); //increment empty scan counter empty_scan_cnt++; } /** * If debug mode is enabled: * print out empty scan count. * */ if( DEBUG_MODE == 1 ) { char buf[20]; sprintf( buf, "[DEBUG] Scan#%d\r", empty_scan_cnt ); UartSendCString( buf ); } /** * After 20 consecutive empty scan: * reset empty scan counter, * increment of delay counter if it's under threshold, * print out message for additional delay occurrence. * */ if( empty_scan_cnt >= 20 ) { empty_scan_cnt = 0; if( delay_factor < 4 ) { delay_factor++; UartSendCString( "[DEBUG] No TAG in range, additional 500ms delay added\n" ); } } /************ Smart Medical NFC Scanner Project ************/ } }