View previous topic :: View next topic |
Author |
Message |
louwi_138
Joined: 17 Nov 2012 Posts: 23
|
pic 16f628 | picc v4.110 PCB | use of two pins RA6 and RA7 |
Posted: Thu Jan 24, 2013 1:46 am |
|
|
Hello,
I want to use the two pins RA6 and RA7 as outputs so I configured the internal oscillator, but the two pins didn't configure as outputs.
This is my code:
Code: |
#include <16f628.h>
#FUSES NOWDT
#FUSES INTRC_IO
#FUSES NOMCLR
#FUSES NOLVP
#FUSES ER_IO
#use delay(clock=4000000)
#byte porta = 0xF05
#byte portb = 0xF06
#byte trisa = 0xF85
#byte trisb = 0xF86
void main(){
//76543210
trisa=0b00100001; //1:in ; 0:out
//76543210
trisb=0b00000000;
portb=0;
porta=0;
while(1){
}
}
|
|
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19541
|
|
Posted: Thu Jan 24, 2013 2:48 am |
|
|
I'm surprised it runs at all. You have _two_ oscillators selected. INTRC_IO, and ER_IO. The ER_IO selection uses pin RA7, expecting an RC oscillator on here.....
Get rid of this.
Best Wishes |
|
|
louwi_138
Joined: 17 Nov 2012 Posts: 23
|
|
Posted: Thu Jan 24, 2013 3:09 am |
|
|
Ttelmah wrote: | I'm surprised it runs at all. You have _two_ oscillators selected. INTRC_IO, and ER_IO. The ER_IO selection uses pin RA7, expecting an RC oscillator on here.....
Get rid of this.
Best Wishes |
I deleted the ER_IO . and it still the same problem.
I'm doing simulation on Isis. |
|
|
RF_Developer
Joined: 07 Feb 2011 Posts: 839
|
|
Posted: Thu Jan 24, 2013 4:10 am |
|
|
Of course they won't: with your code all IOs will remain as inputs. In CCS C by default, the compiler sets IO direction: so called standard I/O mode. You are manually setting IO direction using TRIS. This won't work unless you use fast I/O mode on the ports.
The best thing for most CCS C programs is to forget setting the IO direction and use standard IO which sets it for you. Then you can forget tris.
Read the compiler manual to find out about the compiler's different I/O modes.
Is there any pressing need to manually set IO direction in this application? Or is it habit, or possibly because you were taught to use it?
RF Developer |
|
|
louwi_138
Joined: 17 Nov 2012 Posts: 23
|
|
Posted: Thu Jan 24, 2013 4:39 am |
|
|
RF_Developer wrote: | Of course they won't: with your code all IOs will remain as inputs. In CCS C by default, the compiler sets IO direction: so called standard I/O mode. You are manually setting IO direction using TRIS. This won't work unless you use fast I/O mode on the ports.
The best thing for most CCS C programs is to forget setting the IO direction and use standard IO which sets it for you. Then you can forget tris.
Read the compiler manual to find out about the compiler's different I/O modes.
Is there any pressing need to manually set IO direction in this application? Or is it habit, or possibly because you were taught to use it?
RF Developer |
I'm taught to use it. and I still don't know what should I do to run it ? |
|
|
RF_Developer
Joined: 07 Feb 2011 Posts: 839
|
|
Posted: Thu Jan 24, 2013 5:25 am |
|
|
louwi_138 wrote: | I'm taught to use it. and I still don't know what should I do to run it ? |
Read the CCS manual. Look up I/O modes. In other words do your own research. Then get your teacher/lecturer/whatever to do the same!
RF Developer |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9244 Location: Greensville,Ontario
|
|
Posted: Thu Jan 24, 2013 6:33 am |
|
|
Of course it won't work...
arrgh ISIS ( aka Proteus ) is in 2nd post,last line.
This 'simulator' is very well known for lots of BUGS, faulty DRCs, and other errors.
I do know that a real 16F628 runs fine on the internal oscillator doing al sorts of interesting 'things'. |
|
|
Gabriel
Joined: 03 Aug 2009 Posts: 1067 Location: Panama
|
|
|
Gabriel
Joined: 03 Aug 2009 Posts: 1067 Location: Panama
|
|
Posted: Thu Jan 24, 2013 6:36 am |
|
|
Temtronic... you beat me to it by maybe a second! _________________ CCS PCM 5.078 & CCS PCH 5.093 |
|
|
ckielstra
Joined: 18 Mar 2004 Posts: 3680 Location: The Netherlands
|
|
Posted: Thu Jan 24, 2013 7:30 am |
|
|
One known problem is that ISIS/Proteus doesn't look at your Fuse configuration. You have to configure the properties like clock speed inside ISIS, I don't remember the procedure but I expect to right click the processor and select 'Properties'.
Now about your program:
As RF_Developer already mentioned, in CCS there is for most programs no need to set the TRIS registers yourself, the compiler will do it for you on every I/O operation. This is called standard_io mode and unless you select another mode the compiler will change your TRIS settings. Do more reading in the CCS manual for the '#USE STANDARD_IO' command.
Then the other ugly thing is the hard coding of addresses. For many other compilers this is the only way to program the PIC but it has the disadvantage that you have to define these addresses (more typing) and when you go to another chip you have to change these values again.
In CCS your whole program can be as short as this: Code: | #include <16f628.h>
#FUSES NOWDT
#FUSES INTRC_IO
#FUSES NOMCLR
#FUSES NOLVP
#use delay(clock=4MHz)
void main() {
output_a(0);
output_b(0);
while(1) {
output_toggle(PIN_A6);
delay_ms(500);
}
} |
|
|
|
|