Quantcast
Channel: MEL PICBASIC Forum
Viewing all articles
Browse latest Browse all 4790

PIC 18F2431 PORTB.6 and 7 - strange behavior on restart after a few hours "rest"

$
0
0
Hello everyone,

I have made a little circuit based on a 18F2431; it's un circling dot on a 8x8 LED matrix.

My code below works well BUT when I restart my circuit after a few hours "rest" (= no power on the circuit), both PORTB.6 and PORTB.7 seem not to work as outputs anymore. I can see it because the dot doesn't light up when those two PORTs are used.

If I reprogram the chip, it will work fine again. Even after two hours with no power on the circuit, it will still work. But after maybe 5 or 6 hours, the problems occurs.

I'm not sure what is wrong but I might have to set something in the CONFIG fuses I couldn't find up to now. I'm beginning with 18F PIcs....

Anyone an idea what I'm missing?

Code:

' ====== FUSES =====================================================================================
' PIC 18F2431

' INTernal oscillator
@ __CONFIG _CONFIG1H, _OSC_HS_1H '& _FCMEN_ON_1H & _IESO_OFF_1H

@ __CONFIG _CONFIG2L, _PWRTEN_OFF_2L & _BOREN_OFF_2L & _BORV_45_2L
@ __CONFIG _CONFIG2H, _WDTEN_OFF_2H & _WINEN_OFF_2H & _WDPS_1_2H
@ __CONFIG _CONFIG3L, _T1OSCMX_OFF_3L & _HPOL_LOW_3L & _LPOL_LOW_3L & _PWMPIN_OFF_3L
@ __CONFIG _CONFIG3H, _MCLRE_OFF_3H
@ __CONFIG _CONFIG4L, _STVREN_OFF_4L & _LVP_OFF_4L & _DEBUG_OFF_4L
@ __CONFIG _CONFIG5L, _CP0_OFF_5L & _CP1_OFF_5L
@ __CONFIG _CONFIG5H, _CPB_OFF_5H & _CPD_OFF_5H
@ __CONFIG _CONFIG6L, _WRT0_OFF_6L & _WRT1_OFF_6L
@ __CONFIG _CONFIG6H, _WRTB_OFF_6H & _WRTC_OFF_6H & _WRTD_OFF_6H
@ __CONFIG _CONFIG7L, _EBTR0_OFF_7L & _EBTR1_OFF_7L
@ __CONFIG _CONFIG7H, _EBTRB_OFF_7H

' ====== REGISTERS =================================================================================
'          76543210
OSCCON  = %01110000 'set INTRC to 8 MHZ
OSCTUNE = %00000000 'OSCILLATOR TUNING REGISTER
ADCON0  = %00000000 'A/D CONTROL REGISTER 0
ADCON1  = %00000000 'A/D CONTROL REGISTER 1
ADCON2  = %00000000 'A/D CONTROL REGISTER 2
ANSEL0  = %00000000 'Analog Select Register 0
INTCON  = %00000000 'INTERRUPT CONTROL REGISTER, Enable global interrupts, enable overflow flag
INTCON2 = %00000000 'INTERRUPT CONTROL REGISTER 2
INTCON3 = %00000000 'INTERRUPT CONTROL REGISTER 3
'PORTA  = %00000000 'State High (1) or Low (0)
LATA    = %00000000 'State High (1) or Low (0)
TRISA  = %00001111 'Data Direction Control Register (Input/Output)
'PORTB  = %00000000 'State High (1) or Low (0)
LATB    = %00000000 'State High (1) or Low (0)
TRISB  = %00000000 'Data Direction Control Register (Input/Output)
'PORTC  = %00000000 'State High (1) or Low (0)
LATC    = %00000000 'State High (1) or Low (0)
TRISC  = %00000000 'Data Direction Control Register (Input/Output)

' ====== DEFINES ===================================================================================
DEFINE OSC 8

' ====== VARIABLES =================================================================================
Counter_A  VAR BYTE
Cycles      VAR BYTE
Row_Port    VAR LATC ' this is ROW
Col_Port    VAR LATB ' this is COLUMN
Row_State  VAR BYTE(30)
Col_State  VAR BYTE(30)
Cycle_Speed VAR BYTE

' ====== ALIASES =================================================================================

' ====== INITIALIZE ================================================================================
Counter_A  = 0
Cycles      = 3
Row_Port    = %11111111
Col_Port    = %00000000
Cycle_Speed = 50

' For ROW, 0 is ACTIVE
Row_State(1)  = %11111110
Row_State(2)  = %11111110
Row_State(3)  = %11111110
Row_State(4)  = %11111110
Row_State(5)  = %11111110
Row_State(6)  = %11111110
Row_State(7)  = %11111110
Row_State(8)  = %11111110
Row_State(9)  = %11111101
Row_State(10) = %11111011
Row_State(11) = %11110111
Row_State(12) = %11101111
Row_State(13) = %11011111
Row_State(14) = %10111111
Row_State(15) = %01111111
Row_State(16) = %01111111
Row_State(17) = %01111111
Row_State(18) = %01111111
Row_State(19) = %01111111
Row_State(20) = %01111111
Row_State(21) = %01111111
Row_State(22) = %01111111
Row_State(23) = %10111111
Row_State(24) = %11011111
Row_State(25) = %11101111
Row_State(26) = %11110111
Row_State(27) = %11111011
Row_State(28) = %11111101
Row_State(29) = %00000000 ' all ON
Row_State(30) = %11111111 ' all OFF

' For COL, 1 is ACTIVE
Col_State(1)  = %00000001
Col_State(2)  = %00000010
Col_State(3)  = %00000100
Col_State(4)  = %00001000
Col_State(5)  = %00010000
Col_State(6)  = %00100000
Col_State(7)  = %01000000
Col_State(8)  = %10000000
Col_State(9)  = %10000000
Col_State(10) = %10000000
Col_State(11) = %10000000
Col_State(12) = %10000000
Col_State(13) = %10000000
Col_State(14) = %10000000
Col_State(15) = %10000000
Col_State(16) = %01000000
Col_State(17) = %00100000
Col_State(18) = %00010000
Col_State(19) = %00001000
Col_State(20) = %00000100
Col_State(21) = %00000010
Col_State(22) = %00000001
Col_State(23) = %00000001
Col_State(24) = %00000001
Col_State(25) = %00000001
Col_State(26) = %00000001
Col_State(27) = %00000001
Col_State(28) = %00000001
Col_State(29) = %00000000 ' all OFF
Col_State(30) = %11111111 ' all ON

' ====== PROGRAM TOP ===============================================================================
MAIN:
    FOR Counter_A = 1 TO 28
        Col_Port = Col_State(Counter_A)
        Row_Port = Row_State(Counter_A)
        PAUSE Cycle_Speed
    NEXT Counter_A
    GOTO MAIN                               
END


Viewing all articles
Browse latest Browse all 4790

Trending Articles