View Full Version : PIC16F1824, problem with oscillator and RA3,RA4,RA5
billys7
- 5th May 2014, 14:32
I don't know what is wrong.
I made the following code and i have 2 problems.
-Pause 500 is not 0.5 second, it comes about 2 seconds
When i replace RA0,RA1,RA2 with RA3,RA4,RA5
-I can't make RA3,4,5 to work as an input.
What is wrong ?
@DEVICEINTOSC 'Internal oscillator: I/O function on CLKIN pin
@DEVICELVP_OFF 'Low-voltage programming. Not used
@DEVICEWDT_OFF 'Watchdog timer software-controlled. Not used
@DEVICEPWRT_OFF 'Enable the power-up timer. Not used
@DEVICECPD_OFF 'Data code protection
@DEVICECP_OFF 'Code protection
@DEVICEMCLR_OFF 'Use MCLR pin as MCLR. Not used
@DEVICEBOD_OFF 'Disable Brown-out reset
@DEVICEFCMEN_OFF 'Enables internal oscillator on external death. Not Used
@IESO_OFF 'Two-speed start-up. Not used
DEFINE OSC 4
TRISA = 1 'All inputs
TRISC = 0 'All outputs
ANSELA = 0 'Digital in-out
ANSELC = 0 'Digital in-out
GOTO START
START:
IF PORTA.0 = 1 THEN
GOTO LOOP1
ELSE
GOTO LOOP2
ENDIF
GOTO START
END
LOOP1:
IF PORTA.1 = 1 THEN
PORTC.0 = 1
ELSE
PORTC.0 = 0
pause 500
PORTC.0 = 1
pause 500
PORTC.0 = 0
ENDIF
GOTO START
END
LOOP2:
IF PORTA.2 = 1 THEN
PORTC.0 = 1
ELSE
PORTC.0 = 0
ENDIF
GOTO START
End
gunayburak
- 5th May 2014, 15:21
For the Oscillator problem , you need to configure OSCCON register ...
The default upon reset osc freq. is 500 khz for that PIC mcu .. (That's what datasheet refers on Page 71) . To operate @ 4MHZ you must add the command line below
OSCCON=%01101000
Have a nice day
billys7
- 5th May 2014, 15:22
Thank you, I will try it.
billys7
- 5th May 2014, 23:04
Ok, with the oscillator, but the problem with RA3,RA4 and RA5 continue.
I replace the pic with another 1824 with no better result.
Demon
- 6th May 2014, 00:17
Is this the read-modify-write issue?
(I never remember the details)
I would try turn on 1 second, off 1 second, goto start (keep it simple blinker to start).
Robert
gunayburak
- 6th May 2014, 10:04
As datasheet explains ,simply , inserting the lines below gotta be sufficient to configure RA<5:3> as inputs
BANKSEL PORTA ;
CLRF PORTA ;Init PORTA
BANKSEL LATA ;Data Latch
CLRF LATA ;
BANKSEL ANSELA ;
CLRF ANSELA ;digital I/O
BANKSEL TRISA ;
MOVLW B'00111000' ;Set RA<5:3> as inputs
MOVWF TRISA ;and set RA<2:0> as outputs
Since the way you define your Fuse settings are a bit different than the way I do with my PBP version , the problem might have got to do with yours .. So If you make certain of your "device" declarations , try removing the "end" lines from your code ...
If it still doesn't help , we'll try to figure out an another solution ..
Have a nice day ..
billys7
- 6th May 2014, 10:09
Thank you for your reply, I will try it.
But the mystery is that RA0,RA1,RA2 working.
I will try it with simpler code.
billys7
- 6th May 2014, 10:27
Thank you gunayburak for your answer.
I add it to the code and i will try it.
I also focus the problem in fuse settings.
How will you define the fuse settings ?
gunayburak
- 6th May 2014, 10:42
RA<2:0> MUST WORK ! Because you still use PORTA.0 , PORTA.1 , PORTA.2 declarations in your If conditions ... not PORTA.3 , PORTA4 , PORTA.5 instead ...
gunayburak
- 6th May 2014, 10:44
'************************************************* ***************
'* Name : UNTITLED.BAS *
'* Author : BURAK GÜNAY *
'* Notice : Copyright (c) 2014 [select VIEW...EDITOR OPTIONS] *
'* : All Rights Reserved *
'* Date : 6.5.2014 *
'* Version : 1.0 *
'* Notes : 16F1824 RA<5:3> input mode *
'* : *
'************************************************* ***************
#header
errorlevel -303 ; suppress Program word too large
#ENDHEADER
#config
__CONFIG _CONFIG1, _FOSC_INTOSC & _WDTE_OFF & _PWRTE_ON & _MCLRE_OFF & _CP_OFF & _CPD_OFF & _BOREN_OFF & _CLKOUTEN_OFF & _IESO_OFF & _FCMEN_OFF
__CONFIG _CONFIG2, _WRT_OFF & _PLLEN_OFF & _STVREN_OFF & _BORV_19 & _LVP_OFF
#ENDCONFIG
'---------------------------------------------------------------------
DEFINE OSC 4
PORTA=%000000 : ANSELA=%00000 : TRISA=%111000
PORTC=%00000000 : ANSELC=%0000000 : TRISC=%00000000
START:
IF PORTA.3=1 THEN
GOTO LOOP1
ELSE
GOTO LOOP2
ENDIF
GOTO START
LOOP1:
IF PORTA.4=1 THEN
PORTC.0=1
ELSE
PORTC.0=0
pause 500
PORTC.0= 1
pause 500
PORTC.0= 0
ENDIF
GOTO START
LOOP2:
IF PORTA.5 = 1 THEN
PORTC.0 = 1
ELSE
PORTC.0 = 0
ENDIF
GOTO START
This is the code you should be using ..
gunayburak
- 6th May 2014, 11:08
Since the spaces are gone in previous post , the compiler may display errors on compile .. Here is the code again .
'************************************************* ***************
'* Name : UNTITLED.BAS *
'* Author : BURAK GÜNAY *
'* Notice : Copyright (c) 2014 [select VIEW...EDITOR OPTIONS] *
'* : All Rights Reserved *
'* Date : 6.5.2014 *
'* Version : 1.0 *
'* Notes : 16F1824 RA<5:3> input mode *
'* : *
'************************************************* ***************
#header
errorlevel -303 ; suppress Program word too large
#ENDHEADER
#config
__CONFIG _CONFIG1, _FOSC_INTOSC & _WDTE_OFF & _PWRTE_ON & _MCLRE_OFF & _CP_OFF & _CPD_OFF & _BOREN_OFF & _CLKOUTEN_OFF & _IESO_OFF & _FCMEN_OFF
__CONFIG _CONFIG2, _WRT_OFF & _PLLEN_OFF & _STVREN_OFF & _BORV_19 & _LVP_OFF
#ENDCONFIG
'---------------------------------------------------------------------
DEFINE OSC 4
PORTA=%000000 : ANSELA=%00000 : TRISA=%111000
PORTC=%00000000 : ANSELC=%0000000 : TRISC=%00000000
START:
IF PORTA.3=1 THEN
GOTO LOOP1
ELSE
GOTO LOOP2
ENDIF
GOTO START
LOOP1:
IF PORTA.4=1 THEN
PORTC.0=1
ELSE
PORTC.0=0
pause 500
PORTC.0= 1
pause 500
PORTC.0= 0
ENDIF
GOTO START
LOOP2:
IF PORTA.5 = 1 THEN
PORTC.0 = 1
ELSE
PORTC.0 = 0
ENDIF
GOTO START
billys7
- 6th May 2014, 11:12
When i compile it, it shows me syntax error in the lines from #header till #ENDCONFIG
billys7
- 6th May 2014, 11:39
Ok. I compile it. According to http://melabs.com/support/config_defaults.htm i change the settings in PBP 16F1824.inc file and i add @ at the beggining of config.
I will inform you for the results.
Thank you!
Acetronics2
- 6th May 2014, 12:07
just wipe off
#header
errorlevel -303 ; suppress Program word too large
#ENDHEADER
as error 303 message is just " a warning " ( no effect on code )
BTW ...
is your compiler up to date ???
I do not have any error message with this processor ...
Alain
gunayburak
- 6th May 2014, 12:20
Yep ..But I get such errors
just wipe off
#header
errorlevel -303 ; suppress Program word too large
#ENDHEADER
as error 303 message is just " a warning " ( no effect on code )
BTW ...
is your compiler up to date ???
I do not have any error message with this processor ...
Alain
billys7
- 6th May 2014, 18:38
Totally solved.
The problem was the way i define the fuse settings.
Gunayburak was right.
Thank you all !!!
Powered by vBulletin® Version 4.1.7 Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.