PIC Help !!

Status
Not open for further replies.

cucamunga

New Member
PIC Help, don't know how to start it !!

I finally write a program into the 16F877A, but now i don't know how to use it :-(

When i connect the PIC(already with a program into) to Vss and Vdd it should start right after i plug it? or i need to do anything after/before?

Also i don't understand the Fuses... can anyone can explant it to me ?....i'm using IC-Prog.
Thanks a lot.
 
Last edited:
The fuses set various options, detailed in the datasheet - the most important one is the oscillator type - if it's set to RC and you have a crystal connected to it, it's not going to run!.

To see the minimum connections you need to run a PIC, try looking at my tutorial hardware.
 
I download this program to the PIC:
__________________________________________________________

void main() {

PORTB = 0;
TRISB = 0xFE;

while (1) {
PORTB = 0x01;
Delay_ms(1000);
PORTB = 0x00;
Delay_ms(1000);
}

}

_______________________________________________________

and when is downloaded....nothing happens
should i do anythinf after download the program into the PIC?
 
You don't have any fuse settings in that code - where are you setting them, and what are they set to?.
 



Have you actually assembled the above code, and declared what the PIC is, along with the register settings for oscillator type, watchdog timer etc?

If you simply load the above C code, the pic will just sit there and do precisely nothing!!!!


=====
Shax.
=====
 
cucamunga said:
void main() {

PORTB = 0;
TRISB = 0xFE;

while (1) {
PORTB = 0x01;
Delay_ms(1000);
PORTB = 0x00;
Delay_ms(1000);
}

}

What compiler/IDE are you using? (please tell me you're using a compiler and not trying to program the '.c' file instead of a hex, or something like that...)
 
I notice this trend of new coders using veterian PICs like the 16F877 as their first attemps. Even if you were lucky to get this to compile there are such a large number of configuration tasks that are required to get big chips like F877 to work like you want to.

You still need to turn off analog and comparator lines not being used else the code will go haywire. You still need to setup clock sources and speeds, timers, banks, usart, ram and the like. Else trouble shooting even the simplest toggling of a single I/O line will drive you mad.

To hell with the C code and more to the electrical side. How are you varifying the toggle of the port pins? Using a resistor-led load? Using an O-scope? Is the resistor value too high? Is the led reverse biased? Is the Vdd and Vss reversed? Is the supply voltage clean, rippled, or below 2v? Is the test load tied to the correct Port pin (RB1)? Is the 16F877 orientated correctly?

You "C" what I am talking about.
 
Last edited:
cucamunga said:
I'm using MikroC... and i choose the fuses in the program...i assume that that is enought...or not?

Presumably so, but as you haven't shown us what you're setting them to, how are we supposed to know?. You also haven't mentioned what type of oscillator you're using?.
 
cucamunga said:
what about the fuses....?? i still don't know for what are they for

They set the various options for the PIC, such as the oscilator type, code protection etc, they are fully documented in the datasheet.
 
cucamunga said:
should i also put the fuse information in the C code too??

It's really best if it's in the code, and it's SERIOUSLY advised by MicroChip - because it means you can simply transfer the HEX file to a PIC with no need to know what the fuses need setting to. My programmer software WinPicProg warns you if you load a file without the fuses being set.
 
Nigel Goodwin said:
The instructions with your C compiler should tell you?.

and speaking of which, isn't there some example code for your compiler that you can use to get started, instead of leaving everyone guessing?
 
I mean an example of configuration fuses .in my code.
Is't necessary add hte confiuration fuses in the C code with MikroC ?.Because i already downloaded the .hex in the PIC and nothing happens.
 
cucamunga said:
Because i already downloaded the .hex in the PIC and nothing happens.

Which is a great sign that your configuration fuses are totally wrong. I would suggest you go look in your compiler documentation to find out how to specify the fuses in your C code, using a #PRAGMA or similar. As everyone says, it's good practice.

Even if you don't do it that way, CHECK the fuses in your actual programming software before programming, to make sure they're actually correct.
 
cucamunga said:
Can anyone give me an example of how do this?


Here is a proton basic example ripped straight from some code I used to read analog data from an accelerometer...

===================================================

Device=16F676 'define processor
Set OSCCAL
Config INTRC_OSC_NOCLKOUT, MCLRE_OFF, WDT_OFF, BODEN_OFF
' internal 4mhz osc, MCLR internal, watchdog timer off, brown out off '-
'--------------------------------------------------------------
' setup ports -
TRISA = %00000001 'port a.0 = AD input
TRISC = %00000000 ' define port pin assignments
ADCON0 = %10000001 ' make reference voltage = VDD
ADCON1 = %01110000 ' Make AN0 analog input,
ANSEL = %00000001
CMCON = %00000111
'--------------------------------------
ADIN_RES = 10 '10 bit ad conversion
'ADIN_TAD = frc ' internal RC osc
ADIN_STIME = 100 ' AD sample time 100us
'--------------------------------------
'this bit sets up 4 wire LCD on PORTC
Declare LCD_INTERFACE 4
Declare LCD_DTPIN PORTC.0
Declare LCD_LINES 2
Declare LCD_ENPIN PORTC.4
Declare LCD_RSPIN PORTC.5
'connect R/W pin to ground!!

====================================================

The above code defines the pic, sets the relevant fuses, configures the registers, sets up the A/D resolution and sample time and sets up portC to use a 4 wire parallel LCD... Simple stuff!!!
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…