J_norrie
- 2nd October 2007, 11:15
Hi there everyone, I have a problem setting up the external oscillator on the following pics
16f876a and the 18f2220
I have programmed both with the same simple counter led display program.
i wanted it to run faster to give me some processing time so i thought all i would need was a faster crystal which didn't work on the 16f876a so I thought I would try a 18f2220 with the original 4mh crystal or higher frequency. when i tried the program in the faster chip it ran dead slow 1 count per sec instead of the 100 per sec with the 16f876a with 4mhz crystal.
Am I using the internal osc?
what registers do i need to change?
here is the code used for both pic's
PICBASIC PRO program to demonstrate 7-segment LED display. Schematic
' can be found at http://melabs.com/resources/articles/ledart.htm (fig 6).
DEFINE OSC 4
Segments Var PORTB
Digits Var PORTC
i Var Byte
n Var Byte
Value Var Word
TRISB = $80 ' Set segment pins to output
TRISC = $f0 ' Set digit pins to output
mainloop:
For Value = 0 To 9999
GoSub display ' Display the value
Next Value
GoTo mainloop ' Do it forever
' Subroutine to send the number (0 - 9999) in Value to LEDs
display:
For i = 0 To 3 ' Loop through 4 digits
n = Value Dig i ' Get digit to display
GoSub display1 ' Display the digit
Pause 1 ' Leave it on 1 millisecond
Next i ' Do next digit
Return
' Surboutine to display one digit on LED
' i = digit number
' n = number to display
display1:
Digits = $ff ' All digits off to prevent ghosting
' Convert binary number in n to segments for LED
Lookup n, [$40, $79, $24, $30, $19, $12, $02, $78, $00, $18], Segments
' Set digit pin i to 0 (on) and the rest of the pins to 1 (off)
Digits = ~Dcd i
Return
thanks in advance John
16f876a and the 18f2220
I have programmed both with the same simple counter led display program.
i wanted it to run faster to give me some processing time so i thought all i would need was a faster crystal which didn't work on the 16f876a so I thought I would try a 18f2220 with the original 4mh crystal or higher frequency. when i tried the program in the faster chip it ran dead slow 1 count per sec instead of the 100 per sec with the 16f876a with 4mhz crystal.
Am I using the internal osc?
what registers do i need to change?
here is the code used for both pic's
PICBASIC PRO program to demonstrate 7-segment LED display. Schematic
' can be found at http://melabs.com/resources/articles/ledart.htm (fig 6).
DEFINE OSC 4
Segments Var PORTB
Digits Var PORTC
i Var Byte
n Var Byte
Value Var Word
TRISB = $80 ' Set segment pins to output
TRISC = $f0 ' Set digit pins to output
mainloop:
For Value = 0 To 9999
GoSub display ' Display the value
Next Value
GoTo mainloop ' Do it forever
' Subroutine to send the number (0 - 9999) in Value to LEDs
display:
For i = 0 To 3 ' Loop through 4 digits
n = Value Dig i ' Get digit to display
GoSub display1 ' Display the digit
Pause 1 ' Leave it on 1 millisecond
Next i ' Do next digit
Return
' Surboutine to display one digit on LED
' i = digit number
' n = number to display
display1:
Digits = $ff ' All digits off to prevent ghosting
' Convert binary number in n to segments for LED
Lookup n, [$40, $79, $24, $30, $19, $12, $02, $78, $00, $18], Segments
' Set digit pin i to 0 (on) and the rest of the pins to 1 (off)
Digits = ~Dcd i
Return
thanks in advance John