' Name : LED_flasher_07.BAS ' Author : Christopher Good ' Notice : Copyright (c) 2014 ' : All Rights Reserved ' Date : 12 Sep 2014 ' Version : 1.0 ' Notes : Free source code. Compile with Proton IDE Lite (also free). Program your PIC with IC-Prog (also free). ' ' Pin8 = Ground - tie to common, connect to pin 1 via .1MF cap ' Pin7 = GPIO.0 - i/o - control bank 0 of LEDs ' Pin6 = GPIO.1 - i/o - control bank 1 of LEDs ' Pin5 = GPIO.2 - i/o - control bank 2 of LEDs ' Pin4 = GPIO.3 - input only - RC PWM signal - tie to RC signal via 4.7k ohm resistor ' Pin3 = GPIO.4 - i/o - control bank 3 of LEDs ' Pin2 = GPIO.5 - i/o - control bank 4 of LEDs ' Pin1 = Vcc - tie to +5v, connect to pin 8 via .1MF cap ' similar to LED_flasher_02 (which has all on, all blink, alernating blink) ' LED_06 has all off (< 1.05 ms), all on (> 1.95 ms), all blink (1.05 - 1.50 ms), alternating blink (1.50 - 1.95 ms) with one LED on ' made of super bright LEDs (5 banks) on Night Trainer Device 12C508 Config INTRC_OSC, MCLRE_OFF, WDT_OFF, CP_OFF ' set config fuses OPTION_REG.5 = 0 ' clock source internal Dim Pulselen As Byte ' Pulselen can be 0 - 255, 100 = 1 ms, 200 = 2 ms Dim DelayTime As Word ' DelayTime can be 50 - 410 ms Clear ' set all variables = 0 trisio = %00001000 Start: Delaytime = 500 gosub blink gosub blink ReadPWM: Pulselen = PulsIn GPIO.3, High ' pin 4 - read high pulse length, times out after .65535 seconds if pulselen < 50 then goto start If Pulselen < 105 then GPIO = %00000000 ' all off if Pulselen > 195 then gpio = %00110111 ' all on If Pulselen > 104 And Pulselen <151 Then DelayTime = ((Pulselen - 105) * 8) + 50 ' 50 + (0 to 45)*8 = 50 to 410 ms GPIO = %00110110 Delayms Delaytime GPIO = %00110101 Delayms Delaytime GPIO = %00110011 Delayms Delaytime GPIO = %00100111 Delayms Delaytime GPIO = %00010111 EndIf If Pulselen > 149 And Pulselen < 196 Then DelayTime = ((195 - Pulselen) * 8) + 50 ' 50 + (0 to 45)*8 = 50 to 410 ms GPIO = %00000001 Delayms Delaytime GPIO = %00000010 Delayms Delaytime GPIO = %00000100 Delayms Delaytime GPIO = %00010000 Delayms Delaytime GPIO = %00100000 EndIf DelayMs DelayTime GoTo ReadPWM Blink: gpio = %00110111 delayms delaytime gpio = %00000000 delayms delaytime return