blueroomelectronics
Well-Known Member
I've made a couple of small but significant changes to the Dragonfly kit.
**broken link removed**
Changes are a PIC18F2525 and a 40kHz crystal. The 18F2525 allows for Swordfish BASIC and C18 support and the 40kHz crystal allows for more flexibility with the CCPx module easy to set ms interrupts like shown in the Swordfish program below. The code is not pretty but it works, it'll run as a Minute, Second, 100s second counter and should be easy to convert to a stopwatch. Another project in the works is a frequency counter using the gated TMR0 input (3 pin connector in the upper left of the picture above)
It's an easy mod to existing Dragonfly users, just change the two parts. Digikey sells the 40kHz 12.5pf load crystals for less than $1
**broken link removed**
Changes are a PIC18F2525 and a 40kHz crystal. The 18F2525 allows for Swordfish BASIC and C18 support and the 40kHz crystal allows for more flexibility with the CCPx module easy to set ms interrupts like shown in the Swordfish program below. The code is not pretty but it works, it'll run as a Minute, Second, 100s second counter and should be easy to convert to a stopwatch. Another project in the works is a frequency counter using the gated TMR0 input (3 pin connector in the upper left of the picture above)
Code:
// Dragonfly MKII (PIC18F2525 & 40kHz TMR1 crystal
Device = 18F2525
Clock = 8
Config WDT=OFF, OSC=INTIO67
Dim Digit, Digits(6) As Byte
Dim Loop4 as byte
Const Segments(10) as byte = ($3F,$06,$DB,$CF,$E6,$ED,$BC,$07,$FF,$A7)
// 2.5ms Jiffy clock ideal for 6 digit display refresh ~66.6Hz
Interrupt Jiffy() // 2.5ms Jiffy clock (400Hz)
If Digit > 5 Then
High(PORTC.5) // reset 4022
Digit = 0 // clear digit counter
EndIf
latb = 0 // clearing the segments will eliminate ghosting
lata = 0
// increment (or reset) the CD4022 Johnson counter
Low(PORTC.2) // 4022 clock
Low(PORTC.5)
High(PORTC.2) // 4022 clock low high edge trigger
// display digits(x)
LATB = $3F and Segments(Digits(Digit)) // mask off RB6 & 7
// check for inverted digits and swap segments
if (Digit = 2) or (Digit = 5) then
LATA = $40 and Segments(digits(digit)) // mask off RA0 - RA5
else
LATA = $80 and Segments(digits(digit)) // mask off RA0 - RA5
endif
if Loop4 > 3 then // update clock @ 100Hz
Digits(5) = Digits(5) + 1 // inc 10ms
if Digits(5) > 9 then
Digits(5) = 0
Digits(4) = Digits(4) + 1 // inc 100ms
if Digits(4) > 9 Then
Digits(4) = 0
Digits(3) = Digits(3) + 1 // inc 1s
if Digits(3) > 9 then
Digits(3) = 0
Digits(2) = Digits(2) + 1 // inc 10s
if digits(2) > 5 then
digits(2) = 0
digits(1) = Digits(1) + 1 // inc 1m
if digits(1) > 9 then
digits(1) = 0
digits(0) = Digits(0) + 1 // inc 10m
if digits(0) > 5 then
Digits(0) = 0
endif
endif
endif
endif
endif
endif
Loop4 = 0
endif
Loop4 = Loop4 + 1 // 400 Hz to 100Hz divider
Digit = Digit + 1 // increment digit counter
PIR1.2 = 0 // clear CCP1IF flag
End Interrupt
OSCCON = $72 // 8MHz internal osc
CMCON = $07 // comparators off
adcon1 = %00001110 // RA0 analog, all others digital I/O
CCPR1H = 0 // 40kHz / 100
CCPR1L = 99 // (0 - 99)
T1CON = %01001011 // timer 1 on, 1:1, ext crystal
CCP1CON = $0B // special event trigger
PIE1.2 = 1 // CCP1IE on
Enable(Jiffy)
Low(PORTC.5) // 4022 reset
TRISA = %00011011 // segments G & decimal, CD4022 control
TRISB = %11000000 // segments A-F
Digit = 0 // reset digit count
digits(0) = 0
digits(1) = 0
digits(2) = 0
digits(3) = 0
digits(4) = 0
digits(5) = 0
While true
Wend
End
Attachments
Last edited: