|
|
View previous topic :: View next topic |
Author |
Message |
No_Fear Guest
|
877 Newbie |
Posted: Thu May 29, 2003 3:05 pm |
|
|
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 :
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)
___________________________
This message was ported from CCS's old forum
Original Post ID: 144514865 |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
Re: 877 Newbie |
Posted: Thu May 29, 2003 3:29 pm |
|
|
:=Even led connected to Pic-Pin38 didn't turn on.
-----------------------------------------------------
The first thing to do is to simplify the program. Only test
one thing at a time. Get rid of the separate .h file. Make
it all be one program, so you can see everything at once.
Here is a program to try. Drop it into MPLAB or PCW and
compile it. The fuse settings are especially important.
I've turned off the WDT and the LVP. Both of those could
have been causing you problems.
This file only toggles the LED on pin B5. Once you get
this program working, then add the other features that
you need (one at a time).
<PRE>
#include <16F877A.h>
#use delay(clock=4000000)
#fuses XT, NOWDT, NOPROTECT, BROWNOUT, PUT, NOLVP
<BR>
void main()
{
<BR>
while(1)
{
output_high(PIN_B5);
delay_ms(500);
output_low(PIN_B5);
delay_ms(500);
}
}
<PRE>
___________________________
This message was ported from CCS's old forum
Original Post ID: 144514867 |
|
|
Neutone
Joined: 08 Sep 2003 Posts: 839 Location: Houston
|
Re: 877 Newbie |
Posted: Thu May 29, 2003 3:33 pm |
|
|
Your circuit sounds like the one used on the PICDEM 2 board made by Microchip. If you wish to verify your circuit you can check it aginst this.
<a href="http://www.microchip.com/download/tools/picmicro/icds/mplabicd2/51275a.pdf" TARGET="_blank">http://www.microchip.com/download/tools/picmicro/icds/mplabicd2/51275a.pdf</a>
___________________________
This message was ported from CCS's old forum
Original Post ID: 144514868 |
|
|
No_Fear Guest
|
Re: 877 Newbie |
Posted: Fri May 30, 2003 1:55 am |
|
|
:=:=Even led connected to Pic-Pin38 didn't turn on.
:=-----------------------------------------------------
:=The first thing to do is to simplify the program. Only test
:=one thing at a time. Get rid of the separate .h file. Make
:=it all be one program, so you can see everything at once.
:=
:=Here is a program to try. Drop it into MPLAB or PCW and
:=compile it. The fuse settings are especially important.
:=I've turned off the WDT and the LVP. Both of those could
:=have been causing you problems.
:=
:=This file only toggles the LED on pin B5. Once you get
:=this program working, then add the other features that
:=you need (one at a time).
:=
:=<PRE>
:=#include <16F877A.h>
:=#use delay(clock=4000000)
:=#fuses XT, NOWDT, NOPROTECT, BROWNOUT, PUT, NOLVP
:=<BR>
:=void main()
:={
:=<BR>
:=while(1)
:= {
:= output_high(PIN_B5);
:= delay_ms(500);
:= output_low(PIN_B5);
:= delay_ms(500);
:= }
:=}
:=<PRE>
Thanks for your reply but my project stil does not work :( I think my basic configuration has some faults and i heard from my friend if he does not connect RB2 to GND the 16F877A does not work.Is it true?Let me describe my new circuit now. Led anode connected to Pic-Pin38 and cathode connected to 180 ohm res and the other pin of res connected to GND.A 4 MHz xtall connected between Pic-Pin13 and Pic-Pin14.22pf cap connected between Pic-Pin13 and GND.Another 22pf cap connected between Pic-Pin14 and GND.Pic-Pin11,32 connected to +5V.Pic-Pin12,31 connected to GND.I fully compiled and load your basic progam to it and it does not work?? What is wrong with it?
No_Fear
___________________________
This message was ported from CCS's old forum
Original Post ID: 144514880 |
|
|
R.J.Hamlett Guest
|
Re: 877 Newbie |
Posted: Fri May 30, 2003 2:11 am |
|
|
:=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 <img src="http://www.ccsinfo.com/pix/forum/sad.gif" border="0">( So what is wrong with this? Code is shown below :
:=
:=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)
One obvious comment. You are enabling the chips watchdog (the 'WDT' entry in the #fuses line), but nowhere are you resetting this in your code. The watchog will time out after typically 18mSec, resetting your chip, and starting again. Your code has a 100mSec delay in the loop, before the LED is turned on, so will never get to the point where the AD value is read, or the LED is turned on...
Either disable the watchdog, or change the #use delay line to read:
#use delay (clock=4000000,RESTART_WDT)
Best Wishes
___________________________
This message was ported from CCS's old forum
Original Post ID: 144514881 |
|
|
sar
Joined: 08 Sep 2003 Posts: 36
|
Re: 877 Newbie |
Posted: Fri May 30, 2003 9:28 am |
|
|
877 Newbie
First: (Led anode connected to Pic-Pin38 and cathode connected to 180 ohm res).
180 ohm resistor!!! to small!! you probably blew your port. Use at least a 330 ohm resistor to be safe. The microchip Pic Dem2 board uses 470 ohm resistors. You should look at the Pic Dem2 pdf that neutone suggested.
Connect the resistor to your Pic port and other end to led anode. Cathode to gnd.
Try again but now use a different port. Change your code to that port.
Read the data sheet >>> very important ...and read everything on examples you find.
good luck SAR
___________________________
This message was ported from CCS's old forum
Original Post ID: 144514885 |
|
|
R.J.Hamlett Guest
|
Re: 877 Newbie |
Posted: Fri May 30, 2003 9:38 am |
|
|
:=877 Newbie
:=
:=First: (Led anode connected to Pic-Pin38 and cathode connected to 180 ohm res).
:=180 ohm resistor!!! to small!! you probably blew your port. Use at least a 330 ohm resistor to be safe. The microchip Pic Dem2 board uses 470 ohm resistors. You should look at the Pic Dem2 pdf that neutone suggested.
:=Connect the resistor to your Pic port and other end to led anode. Cathode to gnd.
:=Try again but now use a different port. Change your code to that port.
:=Read the data sheet >>> very important ...and read everything on examples you find.
:=
:=good luck SAR
No, The LED would be very bright, but would not blow the port on 180ohms.
The normal 'lowest' Vf for red LED's, is in the order of 1.9v at the full drive current. The output drive voltage, is a minimum of Vdd-0.7v, and should be perhaps Vdd-0.6 'worst case' at this sort of current. The resistor is then only dropping 2.5v. This gives a current of about 14mA. The ports are rated to deliver 25mA max on any single pin.
You only need a couple of mA, to give a good brightness on a typical LED, but 14mA, will not be a problem. You could (just!), get away, with driving a 180ohm resistor connected directly to ground, without damaging the chip!...
Best Wishes
___________________________
This message was ported from CCS's old forum
Original Post ID: 144514886 |
|
|
sar
Joined: 08 Sep 2003 Posts: 36
|
Re: 877 Newbie |
Posted: Fri May 30, 2003 9:52 am |
|
|
Thanks for setting me it straight R.J
___________________________
This message was ported from CCS's old forum
Original Post ID: 144514887 |
|
|
No_Fear Guest
|
Re: 877 Newbie |
Posted: Fri May 30, 2003 12:59 pm |
|
|
:=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 <img src="http://www.ccsinfo.com/pix/forum/sad.gif" border="0">( So what is wrong with this? Code is shown below :
:=
:=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)
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
___________________________
This message was ported from CCS's old forum
Original Post ID: 144514897 |
|
|
No_Fear Guest
|
Re: 877 Newbie |
Posted: Fri May 30, 2003 1:02 pm |
|
|
:=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 <img src="http://www.ccsinfo.com/pix/forum/sad.gif" border="0">( So what is wrong with this? Code is shown below :
:=
:=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)
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
___________________________
This message was ported from CCS's old forum
Original Post ID: 144514899 |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
Re: 877 Newbie |
Posted: Fri May 30, 2003 2:13 pm |
|
|
:=Thanks for your reply but my project stil does not work
----------------------------------------------------------
It's possible that you may have a hardware problem.
I'm trying to search the web and find schematics of a 16F877
schematic. (16F877A should work the same). Here are some:
This shows the MAX232 connections, and the crystal, etc.
(His resistor value on MCLR is too large.) He's got an LED
and a resistor on Pin B0.
<a href="http://liquid-nexus.net/fanctrl/images/FanCtrlSchematic.gif" TARGET="_blank">http://liquid-nexus.net/fanctrl/images/FanCtrlSchematic.gif</a>
Here's another circuit that might be a little better, because
it's more simple. (Except that it doesn't show the LED circuit). <a href="http://web.ukonline.co.uk/j.winpenny/pic/rs232ex.pdf" TARGET="_blank">http://web.ukonline.co.uk/j.winpenny/pic/rs232ex.pdf</a>
Carefully check your circuit and make sure it has the essential
connections, as shown in the schematics above. Your verbal
description of your circuit sounds OK, but maybe there is a
broken connection somewhere ?
Also, since nothing runs at all, how do you know that the
16F877A is really being programmed ? What programmer are
you using ?
___________________________
This message was ported from CCS's old forum
Original Post ID: 144514900 |
|
|
No_Fear Guest
|
Re: 877 Newbie |
Posted: Fri May 30, 2003 2:37 pm |
|
|
:=:=Thanks for your reply but my project stil does not work
:=----------------------------------------------------------
:=
:=It's possible that you may have a hardware problem.
:=
:=I'm trying to search the web and find schematics of a 16F877
:=schematic. (16F877A should work the same). Here are some:
:=
:=This shows the MAX232 connections, and the crystal, etc.
:=(His resistor value on MCLR is too large.) He's got an LED
:=and a resistor on Pin B0.
:= <a href="http://liquid-nexus.net/fanctrl/images/FanCtrlSchematic.gif" TARGET="_blank"> <a href="http://liquid-nexus.net/fanctrl/images/FanCtrlSchematic.gif" TARGET="_blank">http://liquid-nexus.net/fanctrl/images/FanCtrlSchematic.gif</a></a>
:=
:=Here's another circuit that might be a little better, because
:=it's more simple. (Except that it doesn't show the LED circuit). <a href="http://web.ukonline.co.uk/j.winpenny/pic/rs232ex.pdf" TARGET="_blank"> <a href="http://web.ukonline.co.uk/j.winpenny/pic/rs232ex.pdf" TARGET="_blank">http://web.ukonline.co.uk/j.winpenny/pic/rs232ex.pdf</a></a>
:=
:=Carefully check your circuit and make sure it has the essential
:=connections, as shown in the schematics above. Your verbal
:=description of your circuit sounds OK, but maybe there is a
:=broken connection somewhere ?
:=
:=Also, since nothing runs at all, how do you know that the
:=16F877A is really being programmed ? What programmer are
:=you using ?
Ok, i will check my connections and i built my own programmer <a href="http://www.chez.com/silicium31/Electronique/PIC/fullpic.pdf" TARGET="_blank">http://www.chez.com/silicium31/Electronique/PIC/fullpic.pdf</a>
I use www.ic-prog.com icprog with it.It writes program i can see it.I close program and run+read it again.It seems fine.
No_Fear
___________________________
This message was ported from CCS's old forum
Original Post ID: 144514901 |
|
|
R.J.Hamlett Guest
|
Re: 877 Newbie |
Posted: Fri May 30, 2003 2:45 pm |
|
|
:=Thanks for setting me it straight R.J
It was a worthwhile thought.
I happen to have 'looked into' the drive limits, for driving LED's at high power.
I must admit now, that it is looking more and more like some deeper problem. My immediate 'suspicion', would be that perhaps the home built programmer (what code is being used?), is not setting the configuration bits properly, or not programming the chip. The current described code/hardware, should work.
Best Wishes
___________________________
This message was ported from CCS's old forum
Original Post ID: 144514902 |
|
|
westy Guest
|
Re: 877 Newbie |
Posted: Sun Jun 01, 2003 6:21 am |
|
|
:=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
Hi, I think you need to step back a bit, as 'it does not work' sounds a bit fundamental. Check your circuit/ hardware. Your description does not match the diagram (led). Also you should use a series resistor in the xtal circuit (a 3 term resonator is easier for breadboard development purposes). If no-one else has said so on this thread, write some code which just switches the LED. If 'it doesn't work' then the hardware and software debugging will be much less, and if it does work you will have a known good point from which to begin. I recently moved a project from 16f84 to 16f628. Took ages before I found that 'it doesn't work' in my case was due to the fact that port A in 16f628 was not ttl. In fact a web site recommending changing to 628 from 84 and giving info. on requirements to do so, was wrong on a couple of items.
Best wishes,
Ray
___________________________
This message was ported from CCS's old forum
Original Post ID: 144514924 |
|
|
|
|
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
|