void CLASSB_ClockTestTimer (void) { #asm TimerTest: BANKSEL (_CLASSB_timerCount) MOVF BANKMASK(_CLASSB_timerCount)+1,W BANKSEL TMR1H NOP SUBWF TMR1H,W BTFSS STATUS, 0x2 GOTO IncCounter NOP NOP NOP NOP // NOP BANKSEL _CLASSB_timerCount MOVF BANKMASK(_CLASSB_timerCount),W BANKSEL TMR1L SUBWF TMR1L, W BTFSC STATUS, 0x0 GOTO TimerTestEnd IncCounter: BANKSEL (_CLASSB_Clockcount) INCF BANKMASK(_CLASSB_Clockcount),F BTFSC STATUS, 0x2 INCF BANKMASK(_CLASSB_Clockcount)+1,F GOTO TimerTest TimerTestEnd: RETURN #endasm }
void WS2812Write(void) { // The data pin must be low for at least 50uS to reset the LED drivers PIN_WS2812_LATCH = 0; __delay_us(50); // mainDerp=(char*)derp2; //replace 0 with 0 if anything fails to work int var=4; #asm MOVLB HIGH(_tmpData) // select memory bank 12, so we can access the relevant variables MOVLW LED_ARRAY_SIZE // ledCount = total number of leds MOVWF BANKMASK(_ledCount),b LFSR 0, _ledData // initialise the ledData pointer to the start of the array (FSR0 = address of _ledData) byteLoop: MOVF POSTINC0,W,c // get the next byte of ledData and increment the FSR0 pointer MOVWF BANKMASK(_tmpData),b // save it in tmpData MOVLW 0x08; // bitCount = 8; MOVWF BANKMASK(_bitCount),b bitLoop: BSF LATB,0,c // set the output high BTFSS BANKMASK(_tmpData), 7,b // test the m.s. bit of tmpData. BRA writeZero // logic ONE (long HIGH output, followed by short LOW) writeOne: RLNCF BANKMASK(_tmpData),b // shift tmpData left one place NOP NOP NOP NOP NOP NOP NOP BCF LATB,0,c // set the output pin low DECFSZ BANKMASK(_bitCount),b // decrement the bit counter BRA bitLoop // if not zero, process the next bit. BRA endByte // zero - goto the next byte // logic ZERO (short HIGH output, followed by long LOW) writeZero: BCF LATB,0,c // set output low RLNCF BANKMASK(_tmpData),b // shift tmpData left one place NOP NOP NOP NOP NOP NOP DECFSZ BANKMASK(_bitCount),b // decrement the bit counter BRA bitLoop // if not zero process the next bit // Move on to the next byte if any endByte: DECFSZ BANKMASK(_ledCount),b // decrement the byte counter BRA byteLoop // if non-zero, process the next byte // finished #endasm };
/****************************************************************************** * Description : This function implements the March C or March C Minus test. * It is a complete and irredundant test capable of detecting stuck-at faults, * addressing faults, transition faults, and coupling faults. This test is of complexity * 11n (Where n is the number of bits), 10n for March C Minus test. * * This test is a destructive test!!! CLASSB_MarchbufferAddress is used as a an array to save user * memory during the test! * * Input: * CLASSB_MarchstartAddress : pointer to an array declared in user memory for test * CLASSB_MarchLength : value indicating the number of bytes to test * CLASSB_MarchbufferAddress : pointer to location in memory where array will be stored during test * MARCHCMINUS : designates the test is a March C Minus test. * Return Values: * CLASSB_TEST_PASS : return value = 0 * CLASSB_TEST_FAIL : return value = 1 * ******************************************************************************/ CLASSBRESULT CLASSB_RAMMarchCTest() { volatile unsigned char testResult; /****************************************************************************** * Run March C Test on global RAM used by March C test. ******************************************************************************/ if (CLASSB_MarchstartAddress < (char*)0x27) { testResult = MarchCGlobalTest(); if (testResult) { // MarchCFailure(); return CLASSB_TEST_FAIL; } CLASSB_MarchLength -= (0x28 - (char)CLASSB_MarchstartAddress); CLASSB_MarchstartAddress = (char*)0x27; } /****************************************************************************** * Save memory for test in a known location designated by *CLASSB_MarchbufferAddress * The ClassB_March... variables will not be saved. ******************************************************************************/ if (CLASSB_MarchbufferAddress != NULL) { CLASSB_MARCHtempAddress = CLASSB_MarchstartAddress; for (WREG_SHAD = CLASSB_MarchLength; WREG_SHAD != 0; WREG_SHAD--) { *CLASSB_MarchbufferAddress++ = *CLASSB_MARCHtempAddress++; } } /****************************************************************************** * Wr0 - write zero to all memory for test ******************************************************************************/ CLASSB_MARCHtempAddress = CLASSB_MarchstartAddress; for (WREG_SHAD=0; WREG_SHAD<CLASSB_MarchLength; WREG_SHAD++) { *CLASSB_MarchstartAddress=0x00; CLASSB_MarchstartAddress++; } FSR1L_SHAD = 0; /****************************************************************************** * Rd0Wr1 - read zero, write one - ascending ******************************************************************************/ CLASSB_MarchstartAddress = CLASSB_MARCHtempAddress; for (WREG_SHAD=0; WREG_SHAD<CLASSB_MarchLength; WREG_SHAD++) { FSR0H_SHAD = 0x00; for (FSR0L_SHAD=0; FSR0L_SHAD<8; FSR0L_SHAD++) { #asm MOVLB 0x00 MOVF BANKMASK(_CLASSB_MarchstartAddress), W MOVWF FSR1L MOVF INDF1, W MOVLB 0x1F XORWF FSR0H_SHAD, W //read zero MOVLW 0X01 BTFSS STATUS, 0x02 MOVWF FSR1L_SHAD MOVF INDF1, W BSF STATUS, 0x00 RLF FSR0H_SHAD, F //rotate a 1 into bitMask IORWF FSR0H_SHAD, W MOVWF INDF1 //write 1 #endasm if (FSR1L_SHAD) return CLASSB_TEST_FAIL; } CLASSB_MarchstartAddress++; } /****************************************************************************** * Rd1Wr0 - read one, write zero - ascending ******************************************************************************/ CLASSB_MarchstartAddress = CLASSB_MARCHtempAddress; for (WREG_SHAD=0; WREG_SHAD<CLASSB_MarchLength; WREG_SHAD++) { FSR0H_SHAD = 0xFF; for (FSR0L_SHAD=0; FSR0L_SHAD<8; FSR0L_SHAD++) { #asm MOVLB 0x00 MOVF BANKMASK(_CLASSB_MarchstartAddress), W MOVWF FSR1L MOVF INDF1, W MOVLB 0x1F XORWF FSR0H_SHAD, W MOVLW 0X01 BTFSS STATUS, 0x02 MOVWF FSR1L_SHAD MOVF INDF1, W LSLF FSR0H_SHAD, W MOVWF INDF1 LSLF FSR0H_SHAD, F #endasm if (FSR1L_SHAD) return CLASSB_TEST_FAIL; } CLASSB_MarchstartAddress++; } /****************************************************************************** * For March C Minus test this section is skipped * Rd0 - read zero - descending ******************************************************************************/ #ifndef MARCHCMINUS CLASSB_MarchstartAddress = CLASSB_MARCHtempAddress; for (WREG_SHAD=0; WREG_SHAD < CLASSB_MarchLength; WREG_SHAD++) { FSR0H_SHAD = 0x00; for (FSR0L_SHAD=0; FSR0L_SHAD<8; FSR0L_SHAD++) { #asm MOVLB 0x00 MOVF BANKMASK(_CLASSB_MarchstartAddress), W MOVWF FSR1L MOVF INDF1, W MOVLB 0x1F XORWF FSR0H_SHAD, W //Read 0 MOVLW 0x01 BTFSS STATUS, 0x02 MOVWF FSR1L_SHAD #endasm if (FSR1L_SHAD) return CLASSB_TEST_FAIL; } CLASSB_MarchstartAddress++; } #endif /****************************************************************************** * Rd0Wr1 - read zero, write one - descending ******************************************************************************/ CLASSB_MarchstartAddress--; CLASSB_MARCHtempAddress = CLASSB_MarchstartAddress; for (WREG_SHAD=CLASSB_MarchLength; WREG_SHAD>0; WREG_SHAD--) { FSR0H_SHAD = 0x00; for (FSR0L_SHAD=0; FSR0L_SHAD<8; FSR0L_SHAD++) { #asm MOVLB 0x00 MOVF BANKMASK(_CLASSB_MarchstartAddress), W MOVWF FSR1L MOVF INDF1, W MOVLB 0x1F XORWF FSR0H_SHAD, W //Read 0 MOVLW 0x01 BTFSS STATUS, 0x02 MOVWF FSR1L_SHAD MOVF INDF1, W BSF STATUS, 0x00 RRF FSR0H_SHAD, F //rotate a 1 into bitMask IORWF FSR0H_SHAD, W MOVWF INDF1 //write 1 #endasm if (FSR1L_SHAD) return CLASSB_TEST_FAIL; } CLASSB_MarchstartAddress--; } /****************************************************************************** * Rd1Wr0 - read one, write zero - descending ******************************************************************************/ CLASSB_MarchstartAddress = CLASSB_MARCHtempAddress; for (WREG_SHAD=CLASSB_MarchLength; WREG_SHAD>0; WREG_SHAD--) { FSR0H_SHAD = 0xFF; for (FSR0L_SHAD=0; FSR0L_SHAD<8; FSR0L_SHAD++) { #asm MOVLB 0x00 MOVF BANKMASK(_CLASSB_MarchstartAddress), W MOVWF FSR1L MOVF INDF1, W MOVLB 0x1F XORWF FSR0H_SHAD, W MOVLW 0x01 BTFSS STATUS, 0x02 MOVWF FSR1L_SHAD MOVF INDF1, W LSRF FSR0H_SHAD, W MOVWF INDF1 LSRF FSR0H_SHAD, F #endasm if (FSR1L_SHAD) return CLASSB_TEST_FAIL; } CLASSB_MarchstartAddress--; } /****************************************************************************** * Rd0 - read zero - descending ******************************************************************************/ CLASSB_MarchstartAddress = CLASSB_MARCHtempAddress; for (WREG_SHAD=(CLASSB_MarchLength-1); WREG_SHAD>0; WREG_SHAD--) { FSR0H_SHAD = 0x00; for (FSR0L_SHAD=0; FSR0L_SHAD<8; FSR0L_SHAD++) { #asm MOVLB 0x00 MOVF BANKMASK(_CLASSB_MarchstartAddress), W MOVWF FSR1L MOVF INDF1, W MOVLB 0x1F XORWF FSR0H_SHAD, W MOVLW 0x01 BTFSS STATUS, 0x02 MOVWF FSR1L_SHAD #endasm if (FSR1L_SHAD) return 1; } CLASSB_MarchstartAddress--; } /****************************************************************************** * March C (Minus) Test Passed * Restore User data from the buffer. ******************************************************************************/ if (CLASSB_MarchbufferAddress != NULL) { CLASSB_MARCHtempAddress = (CLASSB_MarchbufferAddress - CLASSB_MarchLength); for (WREG_SHAD = CLASSB_MarchLength; WREG_SHAD != 0; WREG_SHAD--) { *CLASSB_MarchstartAddress++ = *CLASSB_MARCHtempAddress++; } } return CLASSB_TEST_PASS; } // End of function