Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

18F25k22

Status
Not open for further replies.

be80be

Well-Known Member
Trying to figure what I'm missing swordfish set's pins to digital but when I blank the 8 x8 leds there all off
I blink A0 C0 led and A6 C2 toggles with it.
A-1316.jpg
 
Do they come on together as you say in the post or one after the other as you say in the diagram.

Post code.

Mike.
 
I loaded the whole port LATC = %00000001 LATA = %11111110 that fixed the problem
I first tried high PORTC.0 and low PORTA.0 when i set them back to off the led at A6 and C2 would light

Ian it's hooked up as in the pic col to portc with 1 k resistors and rows to porta to sink
It works ok if I write a whole port.
jerry said it's a RWM problem with the 18f25k22
 
Yes the 18f25k22 has a some what rwm problem with swordfish I guess.
Jerry wrote the new swordfish module that sets the pin to digital when you use setalldigital
The problem is with SLRCON = 0
which should set the pins to normal slew rate. If you leave SLRCON set to its default the port pins are really slow to transition and that makes it worse.
Just changing a bit it happens
LATC.0 =1
LATA.0 = 0
same problem
LATC= %xxxxxxxx
LATA=%xxxxxxxxx
no problem
 
I agree with Ian... bit operations on the LATx shouldn't cause RMW problems, and the Swordfish 'high(PORTx)' and 'low(PORTx)' statements actually use the LAT register automatically for you. The slew rate control setting should only cause issues with the PORT register.

Maybe there's another PORT statement in there somewhere causing the problem?
It would have to be on the right-hand side of an expression since Swordfish will read from the PORT and do all the writes to the LAT register.
Code:
PORTA = PORTB       // read PORTB and write LATA
PORTA = LATB        // read LATB and write LATA
 
OK
Swordfish will read from the PORT and do all the writes to the LAT register.
I guess you don't no Jerry too He's probably wrote half of swordfish.
Swordfish handles using LAT for you But with this chip something going on because There no fancy code I was just testing the 8x8
led module out and setting bit's doesn't work with it where as a port write does
disassemble
Code:
;-----------------------------------
;PIC DISASSEMBLER LISTING
;Label  Instruction
;-----------------------------------
    GOTO L1
    NOP
    NOP
    CLRF 0x005,A
L11:    MOVWF 0x004,A
L3:    MOVLW 0xFF
    ADDWF 0x004,F,A
    BTFSS STATUS,C,A
    ADDWF 0x005,F,A
    NOP
    BTFSS STATUS,C,A
    RETURN
    MOVLW 0x03
    MOVWF 0x001,A
    MOVLW 0xE7
    RCALL L2
    BRA L3
    CLRF 0x001,A
L2:    ADDLW 0xFE
    MOVWF 0x000,A
L8:    NOP
    BRA L4
L4:    BRA L5
L5:    CLRF WREG,A
    SUBWFB 0x001,F,A
    BTFSS STATUS,C,A
    RETURN
    DECF 0x000,F,A
    BRA L6
L6:    BRA L7
L7:    BRA L8
L1:    BSF 0x018,6,A
    BRA L9
L10:    MOVLB 0x0F
    CLRF 0x38,BANKED
    CLRF 0x39,BANKED
    CLRF 0x3A,BANKED
    MOVLW 0x08
    MOVWF CM1CON0,A
    MOVLW 0x08
    MOVWF CM2CON0,A
    CLRF 0x41,BANKED
    CLRF SLRCON,A
    MOVLB 0x00
    RETURN
L9:    MOVLW 0x7C
    MOVWF OSCCON,A
    BSF OSCTUNE,PLLEN,A
    RCALL L10
    CLRF TRISC,A
    CLRF TRISA,A
L12:    MOVLW 0x01
    MOVWF LATC,A
    MOVLW 0xFE
    MOVWF LATA,A
    MOVLW 0x01
    MOVWF 0x005,A
    MOVLW 0xF4
    RCALL L11
    CLRF LATC,A
    CLRF LATA,A
    MOVLW 0x01
    MOVWF 0x005,A
    MOVLW 0xF4
    RCALL L11
    MOVLW 0x02
    MOVWF LATC,A
    MOVLW 0xFE
    MOVWF LATA,A
    MOVLW 0x01
    MOVWF 0x005,A
    MOVLW 0xF4
    RCALL L11
    CLRF LATC,A
    CLRF LATA,A
    MOVLW 0x01
    MOVWF 0x005,A
    MOVLW 0xF4
    RCALL L11
    MOVLW 0x04
    MOVWF LATC,A
    MOVLW 0xFE
    MOVWF LATA,A
    MOVLW 0x01
    MOVWF 0x005,A
    MOVLW 0xF4
    RCALL L11
    CLRF LATC,A
    CLRF LATA,A
    MOVLW 0x01
    MOVWF 0x005,A
    MOVLW 0xF4
    RCALL L11
    MOVLW 0x08
    MOVWF LATC,A
    MOVLW 0xFE
    MOVWF LATA,A
    MOVLW 0x01
    MOVWF 0x005,A
    MOVLW 0xF4
    RCALL L11
    CLRF LATC,A
    CLRF LATA,A
    MOVLW 0x01
    MOVWF 0x005,A
    MOVLW 0xF4
    RCALL L11
    MOVLW 0x10
    MOVWF LATC,A
    MOVLW 0xFE
    MOVWF LATA,A
    MOVLW 0x01
    MOVWF 0x005,A
    MOVLW 0xF4
    RCALL L11
    CLRF LATC,A
    CLRF LATA,A
    MOVLW 0x01
    MOVWF 0x005,A
    MOVLW 0xF4
    RCALL L11
    MOVLW 0x20
    MOVWF LATC,A
    MOVLW 0xFE
    MOVWF LATA,A
    MOVLW 0x01
    MOVWF 0x005,A
    MOVLW 0xF4
    RCALL L11
    CLRF LATC,A
    CLRF LATA,A
    MOVLW 0x01
    MOVWF 0x005,A
    MOVLW 0xF4
    RCALL L11
    MOVLW 0x40
    MOVWF LATC,A
    MOVLW 0xFE
    MOVWF LATA,A
    MOVLW 0x01
    MOVWF 0x005,A
    MOVLW 0xF4
    RCALL L11
    CLRF LATC,A
    CLRF LATA,A
    MOVLW 0x01
    MOVWF 0x005,A
    MOVLW 0xF4
    RCALL L11
    MOVLW 0x80
    MOVWF LATC,A
    MOVLW 0xFE
    MOVWF LATA,A
    MOVLW 0x01
    MOVWF 0x005,A
    MOVLW 0xF4
    RCALL L11
    CLRF LATC,A
    CLRF LATA,A
    MOVLW 0x01
    MOVWF 0x005,A
    MOVLW 0xF4
    RCALL L11
    BRA L12
L13:    SLEEP
    BRA L13
 
If swordfish reads from the ports then that will be the problem. Any overloaded pin or analogue pin will read as zero and get written back as zero.

BTW, I doubt Swordfish reads from the port pins unless it's an input operation.

Mike.
 
This is just toggling A0 C0
Code:
L12:    BTG LATC,0,A
    BCF TRISC,0,A   // why is this here
    BCF LATA,0,A
    BCF TRISA,0,A // and this
    MOVLW 0x01
    MOVWF 0x005,A
    MOVLW 0xF4
    RCALL L11
    BRA L12
L13:    SLEEP
    BRA L13
I don't understand what up with the BCF TRISC.0,A
And the BCF TRISA,0,A
 
Could you post the source code that generated that?

...nevermind.

The TRIS instructions are from using 'toggle(), high(), and low()' commands to change the bits
Code:
?I000000_F000_000001_M000000 ; L#MK TOGGLE(PORTA.0)
    BTG LATA,0
    BCF TRISA,0,0
?I000001_F000_000002_M000000 ; L#MK HIGH(PORTA.0)
    BSF LATA,0,0
    BCF TRISA,0,0
?I000002_F000_000003_M000000 ; L#MK LOW(PORTA.0)
    BCF LATA,0,0
    BCF TRISA,0,0
They're there to make sure the pin is an output.
 
Last edited:
I No that but it's doing it more then once don't see why because I toggle the bit it doing it over I'ts not like that if I change chips
I sim the chip with
Oshonsoft and it's showing the pins as input and set to VDD
But if I do a port write it sets them right. I guess i got some crazy 18f25k22 I like to never figure out how to set the osc has to be something left out of my setalldegital module
I post code but I changed it when I went to
to see what setting ports did.
Code:
Device = 18F25K22      'Automatically brings in device file 18F25K22.bas
 Clock = 64             '64MHz
 Include "IntOSC.bas"
 Include "Utils.bas"

 Dim col1 As PORTC.0
 Dim col2 As PORTC.1
 Dim col3 As PORTC.2
 Dim col4 As PORTC.3
 Dim col5 As PORTC.4
 Dim col6 As PORTC.5
 Dim col7 As PORTC.6
 Dim col8 As PORTC.7
 Dim row1 As PORTA.0 
 Dim row2 As PORTA.1
 Dim row3 As PORTA.2
 Dim row4 As PORTA.3
 Dim row5 As PORTA.4
 Dim row6 As PORTA.5 
 Dim row7 As PORTA.6
 Dim row8 As PORTA.7

 SetAllDigital

 TRISC = %00000000
 TRISA = %00000000
 While true
 LATC = %00000001
 LATA = %11111110
 DelayMS (500)
 LATC = %00000000
 LATA = %00000000
 DelayMS (500)
 LATC = %00000010
 LATA = %11111110
 DelayMS (500)
 LATC = %00000000
 LATA = %00000000
 DelayMS (500)
 LATC = %00000100
 LATA = %11111110
 DelayMS (500)
 LATC = %00000000
 LATA = %00000000
 DelayMS (500)
 LATC = %00001000
 LATA = %11111110
 DelayMS (500)
 LATC = %00000000
 LATA = %00000000
 DelayMS (500)
 LATC = %00010000
 LATA = %11111110
 DelayMS (500)
 LATC = %00000000
 LATA = %00000000
 DelayMS (500)
 LATC = %00100000
 LATA = %11111110
 DelayMS (500)
 LATC = %00000000
 LATA = %00000000
 DelayMS (500)
 LATC = %01000000
 LATA = %11111110
 DelayMS (500)
 LATC = %00000000
 LATA = %00000000
 DelayMS (500)
 LATC = %10000000
 LATA = %11111110
 DelayMS (500)
 LATC = %00000000
 LATA = %00000000
 DelayMS (500)
 Wend
 
but it's doing it more then once don't see why because I toggle the bit it doing it over
It will clear the TRIS bit every time you use a 'toggle()', 'high()' or 'low()' command.
That's the way the command works. It does that to make sure that the pin is an output.
If you don't want it to do that then don't use those commands... set the pin to output mode and control the PORT/LAT directly
Code:
output(PORTA.0)    // clears TRIS bit
LATA.0 = 1
PORTA.0 = 0          // actually writes to LATA register


I sim the chip with Oshonsoft and it's showing the pins as input and set to VDD. But if I do a port write it sets them right.
SetAllDigital() just sets the analog/digital mode of the ports. It doesn't make them outputs.
You have to do that yourself for each one of the pins using one of the pin commands (output, high, low, toggle) or use the TRISx register directly.

never figure out how to set the osc has to be something left out of my setalldegital module
SetAllDigital() has nothing to do with the osc. The osc modes and settings change from chip to chip so it's likely whatever's in your 'IntOSC.bas' file isn't correct for the 25K22. Since that's your file it's hard to say. Post it so we can see it.

I post code but I changed it when I went to to see what setting ports did
Which makes it difficult to say what the original problem was.
 
I know what setalldigital dose
I Know it's got nothing to do with the OSC I was just stating that the OSC is harder to set then some of the chips I used
Whats even worst is the 8x8 led I got 2 of these to play with maybe I should of got more it's bad I tried the second one and it worked fine. Pin 4 has something backward on the 8 x 8
 
Whats even worst is the 8x8 led I got 2 of these to play with maybe I should of got more it's bad I tried the second one and it worked fine. Pin 4 has something backward on the 8 x 8
Arrgghh!!

Blinkered by software!!
 
If I set pin 4 low and toggle the A0 pin
It lights the 2 leds guess the 8x8 has two backward leds
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top