I would replace PORTB.0 = 1 : PORTB.1 = 1 : PORTB.3 = 0 with a single write to the whole
port to help reduce my chances of read-modify-write.
You can make your code a lot smaller/faster also by adjusting a few simple routines.
Below are just a few suggestions.
I don't know which PIC you're using, but I would also check to make sure RA4 and RA5 areCode:PORTB = %00000111 ' setting port latches "before" tris avoids pin glitches TRISA = %11111111 TRISB = %11110000 'PORTB.0 = 1 ' done above 'PORTB.1 = 1 ' Note: this can cause read-modify-write problems 'PORTB.2 = 1 'PORTB.3 = 0 'BNK1 = 0 ' taken care of below 'BNK2 = 0 'DUR = 0 MAIN: DUR = 0 ' PORTB.3 = 0 ' taken care of at POR and end of Flash routine BNK1 = 0 BNK2 = 0 ADCIN 0, BNK1 ADCIN 1, BNK2 ' IF PORTB.4 = 1 then ' DUR = 8 ' endif ' IF PORTB.5 = 1 THEN ' DUR = 4 ' endif ' IF PORTB.6 = 1 THEN ' DUR = 2 ' endif ' IF PORTB.7 = 1 THEN ' DUR = 1 ' endif ' reverse how DIP switch assigns 8,4,2,1 with ' IF RB7 = 1 DUR = 8 ' IF RB6 = 1 DUR = 4 ' IF RB5 = 1 DUR = 2 ' IF RB4 = 1 DUR = 1 ' now just shift upper 4-bits read from DIP switch ' AND make sure upper 4-bits of result in DUR are clear. DUR = (PORTB >> 4) & $0F ' returns 8, 4, 2 or 1 in DUR if "ONLY 1" of RB7, RB6, RB5 or RB4 are set. IF (BNK1 => 466) OR (BNK2 => 466) THEN FLASH goto MAIN FLASH: IF (PORTA.4=1) OR (PORTA.5=0) THEN ' PORTB.0 = 0 : PORTB.1 = 0 : PORTB.3 = 1 PORTB = %00001100 ' avoids read-modify-write endif ' IF DUR = 1 THEN ' PAUSE 1 ' endif ' IF DUR = 2 THEN ' PAUSE 2 ' endif ' IF DUR = 4 THEN ' PAUSE 4 ' endif ' IF DUR = 8 THEN ' PAUSE 8 ' endif PAUSE DUR ' DUR already holds the PAUSE time. This saves a lot of code. ' PORTB.0 = 1 : PORTB.1 = 1 : PORTB.3 = 0 PORTB = %00000111 ' avoids read-modify-write GOTO MAIN END
both set to digital "analog disabled" for these pins so they don't return the wrong value
when being tested.




Bookmarks