|
|
View previous topic :: View next topic |
Author |
Message |
elder
Joined: 16 Mar 2005 Posts: 19
|
help getting started (16F648A) |
Posted: Wed Mar 16, 2005 8:20 pm |
|
|
hey guys, i'm new to PIC programming, i'm just trying to make a basic program to get things started. I'm yet to get any response from the chip :(
Heres what i have at the moment
Code: |
#include <16F648A.h>
#fuses EC_IO,INTRC_IO, NOPROTECT, PUT, NOWDT, NOMCLR, NOLVP
#use delay(clock=4000000)
void main() {
set_tris_a(0b11111000);
output_high (PIN_A2);
while(1) {
output_high (PIN_A1);
delay_ms(500);
output_low (PIN_A1);
delay_ms(500);
}
}
|
Ok so i'm trying to use the internal clock to toggle PIN_A1's output. However i'm not getting anything on any pin.
Pic programmer verifies succesfully, and then i'm just connecting ground and 3V supply pins, and measuring other pins with multimeter. |
|
|
Guest Guest
|
Help getting started |
Posted: Wed Mar 16, 2005 11:59 pm |
|
|
Elder:
Does it work if you use the external clock? |
|
|
elder
Joined: 16 Mar 2005 Posts: 19
|
|
Posted: Thu Mar 17, 2005 1:25 am |
|
|
Hi, I haven't tried yet, i figured using the internal clock would be the easiest way to start. I'll be using an 11.0592Mhz crystal (with 22pF capacitors), so i suppose the only difference would be putting -
Code: |
#fuses HS, etc....
#use delay(clock=11059200)
|
is this right? (can't try untill tommorow, no access to pic programmer)
Also, i'm guessing this problem can only be a clock problem or a compiler problem (i have 5x 16F648A chips to test with so rule out dead chip, and the pic programmer succesfully verifies the code on the chip). Is clock synchronisation necessary if i'm not using delay functions? (If so i'll make a big counting loop instead of a delay to see if its the clock thats the problem) |
|
|
Ttelmah Guest
|
|
Posted: Thu Mar 17, 2005 3:15 am |
|
|
The reason for asking about the 'external clock', is that your fuses statement, is wrong.
#fuses EC_IO,INTRC_IO, NOPROTECT, PUT, NOWDT, NOMCLR, NOLVP
This is saying 'use external IO' (EC_IO), then says to use the internal clock. You should only ever select one fuse pattern from a particular 'set'. How the processor will behave is open to question, but normally the patterns are 'ORed' together. Hence in this case, EC_IO, is a bit pattern of '011', and INTRC_IO, is a pattern of '100'. ORed together these give '111', which is the pattern for an external RC oscillator, which you do not have connected. Hence the processor won't run....
So change your fuses to:
#fuses INTRC_IO, NOPROTECT, PUT, NOWDT, NOMCLR, NOLVP
and the processor will then probably work.
You should also turn off the comparator module, to use the pins for normal I/O, so add:
setup_comparator(NC_NC_NC_NC);
at the start of your main code.
Final comment. Your TRIS command, effectively does nothing!...
The compiler wakes up using a mode called 'standard_io'. With this, it will modify the TRIS register automatically, whenever you do I/O on a pin. So when you execute the statement 'output_high (PIN_A2)', the TRIS bit for this pin is automatically cleared. The same applies for the A1 pin on it's output statements. Hence your TRIS is being overridden. If you want to control the TRIS yourself, you should add the command #use fast_io(A), in the header for your program, which turns off this behaviour. The advantage of this is speed (there is an extra instruction or two added to every I/O statement by standard_io). However it then means that you have to be confident that you are setting TRIS right. For much simple code, the default behaviour is easier to use.
Best Wishes |
|
|
elder
Joined: 16 Mar 2005 Posts: 19
|
|
Posted: Thu Mar 17, 2005 3:34 am |
|
|
thanks Ttelmah! very helpfull! hopefully all goes well once i get my hands back on the programmer |
|
|
elder
Joined: 16 Mar 2005 Posts: 19
|
|
Posted: Thu Mar 17, 2005 5:03 pm |
|
|
Ok i changed it how you said, i'm still getting nothing heres the code...
Code: |
#include <16F648A.h>
#fuses INTRC_IO, NOPROTECT, PUT, NOWDT, NOMCLR, NOLVP
#use delay(clock=4000000)
void main(){
setup_comparator(NC_NC_NC_NC);
while(1) {
output_high(PIN_A1);
delay_ms(500);
output_low(PIN_A1);
delay_ms(500);
}
}
|
also, i've tried using #fuses HS and delay(11059200) instead with an 11.0592Mhz crystal and still nothing.
Last edited by elder on Thu Mar 17, 2005 5:22 pm; edited 1 time in total |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Thu Mar 17, 2005 5:18 pm |
|
|
Post your compiler version. To find it, look at the top of the .LST
file which is generated after you compile the project. It will be
a number similar to 3.219, 3.221, 3.222, etc. |
|
|
elder
Joined: 16 Mar 2005 Posts: 19
|
|
Posted: Thu Mar 17, 2005 5:23 pm |
|
|
3.218 |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Thu Mar 17, 2005 5:50 pm |
|
|
What is the Vdd voltage for the PIC ? Is it +5v or is it +3.3v ? |
|
|
elder
Joined: 16 Mar 2005 Posts: 19
|
|
Posted: Thu Mar 17, 2005 6:06 pm |
|
|
it says 2 - 5.5 voltage range, i'll be using 3V, but i have tried at 5V too |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Thu Mar 17, 2005 6:28 pm |
|
|
If you're running at 3v with Brownout enabled (and it is enabled
by default) then the PIC will be held in reset.
Add the NOBROWNOUT setting to your #fuses statement and
see if that fixes the problem. |
|
|
elder
Joined: 16 Mar 2005 Posts: 19
|
|
Posted: Thu Mar 17, 2005 6:38 pm |
|
|
Thanks heaps! LEDs are flashing |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|