CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

help getting started (16F648A)

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
elder



Joined: 16 Mar 2005
Posts: 19

View user's profile Send private message

help getting started (16F648A)
PostPosted: Wed Mar 16, 2005 8:20 pm     Reply with quote

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
PostPosted: Wed Mar 16, 2005 11:59 pm     Reply with quote

Elder:

Does it work if you use the external clock?
elder



Joined: 16 Mar 2005
Posts: 19

View user's profile Send private message

PostPosted: Thu Mar 17, 2005 1:25 am     Reply with quote

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







PostPosted: Thu Mar 17, 2005 3:15 am     Reply with quote

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

View user's profile Send private message

PostPosted: Thu Mar 17, 2005 3:34 am     Reply with quote

thanks Ttelmah! very helpfull! hopefully all goes well once i get my hands back on the programmer Smile
elder



Joined: 16 Mar 2005
Posts: 19

View user's profile Send private message

PostPosted: Thu Mar 17, 2005 5:03 pm     Reply with quote

Ok i changed it how you said, i'm still getting nothing Confused 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

View user's profile Send private message

PostPosted: Thu Mar 17, 2005 5:18 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Thu Mar 17, 2005 5:23 pm     Reply with quote

3.218
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Mar 17, 2005 5:50 pm     Reply with quote

What is the Vdd voltage for the PIC ? Is it +5v or is it +3.3v ?
elder



Joined: 16 Mar 2005
Posts: 19

View user's profile Send private message

PostPosted: Thu Mar 17, 2005 6:06 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Thu Mar 17, 2005 6:28 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Thu Mar 17, 2005 6:38 pm     Reply with quote

Thanks heaps! LEDs are flashing Very Happy
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
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