Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Questions about 16F877A (problematic code provided)

Status
Not open for further replies.

ergen

Junior Member level 3
Joined
May 31, 2002
Messages
28
Helped
1
Reputation
2
Reaction score
1
Trophy points
1,283
Activity points
194
877 Newbie

Hi there,

I just upgrade my mcu's from 16F628 to 16F877A and i have lots of problems now.I even don't have an idea how to use it.Let me describe my project.It is so simple but i cant do it.I have a 16F877, max232, 2 leds, 4 caps (1uf), 2 ceramic caps (22 pf), an xtall (4mhz), 3 resistor (10Kohm, 2 * 220 ohm).I want to measure 0-5V voltages via pic and send them to computer.Let me to describe my circuit. I connected 10K res between Pin1 and +5V.I connected pin11,pin32 to +5V.I connected pin12,pin31 to GND.I connected green led (+)pin to pin38, (-)pin to res 220 ohm and other pin of res 220 ohm to gnd.I connected xtall between pin12 and pin13.I connected 22pf to xtall pin1 and other 22 pf cap to xtall pin 2, the other pins of caps to GND.I connected (+) red led pin to +5V, (-) pin to other res 220 ohm and other pin of res to GND.I connected a 1 uf cap between max-pin1(+) and max-pin 3(-).Another 1 uf cap between max-pin4(+) and max-pin5(-) and 1 uf cap between max-pin16(-) and max-pin2(+).1 uf cap between max-pin6(-) and max-pin15(+).I connected Max-pin(16) to +5V and Max-pin(15) to GND.Then i loaded this program to pic16F877A and i gave voltage and nothing happened.Even led connected to Pic-Pin38 didn't turn on :(( So what is wrong with this? Code is shown below (i use ccs c compiler 3.155):

project.c :

#include "C:\WORK\Project.h"


void main() {

int value;
setup_adc_ports(A_ANALOG);
setup_adc(ADC_CLOCK_INTERNAL);
setup_psp(PSP_DISABLED);
setup_spi(FALSE);
setup_counters(RTCC_INTERNAL,WDT_18MS);
setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DISABLED,0,1);
setup_comparator(NC_NC_NC_NC);
setup_vref(FALSE);


printf("Sampling:");

set_adc_channel( 0 );

do {
delay_ms(100);
value = Read_ADC();
printf("\n\rValue: %2X ",value);
output_high(PIN_B5);
} while (TRUE);


}

project.h :

#include <16F877A.h>
#device adc=8
#use delay(clock=4000000)
#fuses HS,WDT
#use rs232( baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8 )
 

I see 4 problems here:
the XTAL has to be connected between pin 13 and 14 and not between pin 12 and 13.

Where do you initialize TRISB for Porb Bit5 to be an output?
After reset all ports are inputs!!

You program the WDT fuse but do not clear the watchdog periodically.
So your programm will be reset all 18 mS by the watchdog.

You must also program DEBUG fuse otherwise your program will never be able to operate.
It is also a good idea to program the BOREN (brownout reset) fuse.

hope this helps, best regards
 

Hi,

I replace the port where whe led is connected.I connected it to PORTD7 and i changed my code to this :

#include <16F877A.h>
#use delay(clock=4000000)
#fuses XT, NOWDT, NOPROTECT, BROWNOUT, PUT, NOLVP

void main()
{

while(1)
{
output_high(PIN_D7);
delay_ms(500);
output_low(PIN_D7);
delay_ms(500);
}
}

I connected xtall betw. pin13-14.I connected 22 pf cap between pin13 and GND.I connected 22 pf cap between pin14 and GND.I connected led+ to pin30, led- to res 330ohm and other pin of res330ohm to GND.Last of all i connected res 4.7Kohm between +5V and pin1.I compiled and wrote to pic and let it work but it does not work!! What is wrong again, i can't understand :(

Here is my schematic that i use now :



Ergen.
 

have you tried a simple program, turn one LED on/off? just to make sure program is working properly? i had a similar problem with 16F877 running @20MHz. load program, but nothing works... then i changed the 2 capacitors around my Xtal from 33pF to 10pF each.

then it worked.

btw - running 4MHz Xtal with 2 x 33pF caps works. but 20Mhz and same caps does not.

Mr.Cool
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top