View previous topic :: View next topic |
Author |
Message |
trento
Joined: 14 Oct 2005 Posts: 26
|
port utilize |
Posted: Tue Nov 22, 2005 8:51 am |
|
|
How I can use 18 port pins of the PIC16F877A and what is the setup should I do to work as outuput pin to generate square wave togathar
I could programed to and I got the signal from 16 pins which are port b and port d but when I traid to utilize othar two pin from any port the output did not come out from all pin I just use delay funcation and if statment ,while statment and switch statment |
|
![](templates/subSilver/images/spacer.gif) |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Tue Nov 22, 2005 5:08 pm |
|
|
Post a short program that shows the problem.
Also post your compiler version. |
|
![](templates/subSilver/images/spacer.gif) |
trento
Joined: 14 Oct 2005 Posts: 26
|
|
Posted: Tue Nov 22, 2005 8:07 pm |
|
|
This sample from my program I use PCW C compailer IDE MAY 2003 Code: | #include <16F877A.h>
#FUSES HS,NOWDT,NOPROTECT,NOPUT,NOLVP
#USE DELAY( CLOCK=20000000 )
#USE FAST_IO(B)
#USE FAST_IO(C)
#USE FAST_IO(D)
#byte port_b=6
#byte port_c=7
#byte port_d=8
static byte CONST UP_MAP0[8] = { 0xe1,0xc3,0x87,0x0f,0x1e,0x3c,0x78,0xf0 };
main(){
char cnt=0;char tnt=0;
set_tris_b(0);
set_tris_c(0xcf);
set_tris_d(0);
port_b = 0xf0,
port_c = 0x00,
port_d = 0xf0;
for(;;) { if(tnt%2)
port_c =0x10;port_c=0x20;
while(cnt<=3) {
switch (cnt) {
case 0:
port_b = UP_MAP0[0];
delay_us(1146);
break;
case 1:
port_b = UP_MAP0[1];
delay_us(999);
break;
case 2:
port_b = UP_MAP0[2];
delay_us(951);
break;
case 3:
port_b = UP_MAP0[3];
delay_us(3076);
break; }cnt++;
} cnt=0;
while(cnt<=3) {
switch (cnt) {
case 0:
port_d = UP_MAP0[0];
delay_us(951);
break;
case 1:
port_d = UP_MAP0[1];
delay_us(999);
break;
case 2:
port_d = UP_MAP0[2];
delay_us(1146);
break;
case 3:
port_d = UP_MAP0[3];
delay_us(366);
break;} cnt++;
}if(tnt%2)
port_c =0x30;port_c=0x00 ;delay_us(366);cnt=4;tnt++; |
|
|
![](templates/subSilver/images/spacer.gif) |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Wed Nov 23, 2005 12:27 am |
|
|
What device or components are connected to the PIC pins ?
If you have several high current devices (possibly LEDs) connected
to several pins and you add a few more, the total current used can
exceed the maximum limit for your PIC. For the 16F877A, the
limit is 200 ma. I have never tried to drive that much current in
a PIC, so I'm not sure what the effect will be, but I think it could
cause the PIC to stop working. |
|
![](templates/subSilver/images/spacer.gif) |
trento
Joined: 14 Oct 2005 Posts: 26
|
|
Posted: Wed Nov 23, 2005 12:58 am |
|
|
switchs specifically MOSFET and I will drive I thik each one will draw 2uA so totally it will be 18X2uA I think I will not exceed that limit furthermore I did not connect any load with the PIC I just measure by oscilloscope which mean there is no drawing current .when I measure with out make port c work which is mean just 16 pin it work nicly but when I the other two pins the strange result comeout furthermore when Itraid to use RA0 and RA1 the strange result apear in RD0 and RD1 and RD4and RD5 and when I traid to use two pin from port C the strange result comeout in RD2 and RD3 and RD6and RD7
so I think there is some setup I have to do to make work nice |
|
![](templates/subSilver/images/spacer.gif) |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Wed Nov 23, 2005 1:19 am |
|
|
Do you have the PIC pins connected directly to the gates of the MOSFETs ?
This appnote calculates the peak gate drive current for a MOSFET to
be 2.0 Amps. (Although it's for a short time). Because of this,
they recommend using MOSFET driver chips to drive the gates
instead of driving them directly from the PIC.
http://ww1.microchip.com/downloads/en/AppNotes/00786a.pdf
The following thread on the Microchip forum talks about driving MOSFETs
from a PIC. They suggest using series resistors to limit the current.
http://forum.microchip.com/tm.asp?m=88398&mpage=1&anchor#100543
I have used a Logic Level FET (IRF7306) in one project, and I didn't use a
MOSFET driver chip. I put a 47 ohm series resistor between the PIC pin
and the gate pin of the FET.
If you drive the FETs directly from the PIC, make sure you use the
series resistors. |
|
![](templates/subSilver/images/spacer.gif) |
trento
Joined: 14 Oct 2005 Posts: 26
|
|
Posted: Wed Nov 23, 2005 1:49 am |
|
|
thank you for this information I know all what you have talked about yes I use IR2110 as a mosfet gate drive and I use sereis resistor with the MOSFET.I know but the problem now with the PIC I can not get the 18 signal from even with out drawing any current this is mean open circuit test so just i wanna solve programing problem not any other and i also tested my circuit by use 8 signal from PIC and it work niclly just I want to know what the problem with the program and how i can use 18 bin and which ![Question](images/smiles/icon_question.gif) |
|
![](templates/subSilver/images/spacer.gif) |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Wed Nov 23, 2005 1:56 am |
|
|
What is the exact version of your compiler ?
To find the version, look at the .LST file for your project. This file is
in the folder (directory) for your PIC project. The compiler version
is given at the top of the file. It will be a number like 2.734 or 3.191, etc. |
|
![](templates/subSilver/images/spacer.gif) |
trento
Joined: 14 Oct 2005 Posts: 26
|
|
Posted: Wed Nov 23, 2005 2:13 am |
|
|
Thank you for your care the version of the copailer is 3.232d,11660
![Crying or Very sad](images/smiles/icon_cry.gif) |
|
![](templates/subSilver/images/spacer.gif) |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Wed Nov 23, 2005 1:03 pm |
|
|
I think your problem is just a coding error. At the bottom of your code
you have this statement:
In two places in your code, you are doing this test:
Because you have set cnt = 4, most of your code never runs.
I did a test, and just changed it to "cnt=0" at the end of the program,
and the program started working. |
|
![](templates/subSilver/images/spacer.gif) |
trento
Joined: 14 Oct 2005 Posts: 26
|
|
Posted: Wed Nov 23, 2005 7:23 pm |
|
|
Thank you for ur response but this is just sample of my code and the following code is full one .I made alot of review and I think my code will not have problem like this Code: |
#include <16F877A.h>
#FUSES HS,NOWDT,NOPROTECT,NOPUT,NOLVP
#USE DELAY( CLOCK=20000000 )
#USE FAST_IO(B)
#USE FAST_IO(A)
#USE FAST_IO(D)
#byte port_b=6
#byte port_a=5
#byte port_d=8
static byte CONST UP_MAP0[8] = { 0xe1,0xc3,0x87,0x0f,0x1e,0x3c,0x78,0xf0 };
main(){
char cnt=0;char tnt=0;
set_tris_b(0);
set_tris_a(0xfc);
set_tris_d(0);
port_b = 0xf0,
port_a = 0x00,
port_d = 0xf0;
for(;;) { if (tnt==40) tnt=0; if(tnt%2)
port_a =0x01;else port_a=0x02;
while(cnt<=3) {
switch (cnt) {
case 0:
port_b = UP_MAP0[0];
delay_us(1146);
break;
case 1:
port_b = UP_MAP0[1];
delay_us(999);
break;
case 2:
port_b = UP_MAP0[2];
delay_us(951);
break;
case 3:
port_b = UP_MAP0[3];
delay_us(3076);
break; }cnt++;
} cnt=0;
while(cnt<=3) {
switch (cnt) {
case 0:
port_d = UP_MAP0[0];
delay_us(951);
break;
case 1:
port_d = UP_MAP0[1];
delay_us(999);
break;
case 2:
port_d = UP_MAP0[2];
delay_us(1146);
break;
case 3:
port_d = UP_MAP0[3];
delay_us(366);
break;} cnt++;
}if(tnt%2)
port_a =0x03;else port_a=0x00 ;delay_us(366);cnt=4;tnt++;
while(cnt<=7) {
switch (cnt) {
case 4:
port_b = UP_MAP0[4];
delay_us(1146);
break;
case 5:
port_b = UP_MAP0[5];
delay_us(999);
break;
case 6:
port_b = UP_MAP0[6];
delay_us(951);
break;
case 7:
port_b = UP_MAP0[7];
delay_us(3076);
break;
} cnt++;
}cnt=4;
while(cnt<=7) {
switch (cnt) {
case 4:
port_d = UP_MAP0[4];
delay_us(951);
break;
case 5:
port_d = UP_MAP0[5];
delay_us(999);
break;
case 6:
port_d = UP_MAP0[6];
delay_us(1146);
break;
case 7:
port_d = UP_MAP0[7];
delay_us(366);
break; } cnt++;
} delay_us(366); cnt=0; } }
| ![Crying or Very sad](images/smiles/icon_cry.gif) |
|
![](templates/subSilver/images/spacer.gif) |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Wed Nov 23, 2005 8:42 pm |
|
|
Quote: | |
I like to solve problems where people are "stuck" on their
projects and to help them get their project moving again.
I did that in your case, and I don't want to write your
program for you. You must write the program. |
|
![](templates/subSilver/images/spacer.gif) |
trento
Joined: 14 Oct 2005 Posts: 26
|
|
Posted: Wed Nov 23, 2005 9:10 pm |
|
|
PCM programmer wrote: | Quote: | |
I like to solve problems where people are "stuck" on their
projects and to help them get their project moving again.
I did that in your case, and I don't want to write your
program for you. You must write the program. |
I do not know what you mean I did not ask you to write it for me I just ask how to use 18 pin and I wrote programe to do so but just I get 16 pin as I explain before and you said send me short one so I send sample for you and now I send all and I answer you for all question you ask s |
|
![](templates/subSilver/images/spacer.gif) |
dyeatman
Joined: 06 Sep 2003 Posts: 1924 Location: Norman, OK
|
|
Posted: Thu Nov 24, 2005 3:05 pm |
|
|
I put your last code in my test board and it worked fine except for B6 and B7 which cannot be used since they are the programming pins. Outputs A0-1, B0-5 and D0-7 (16 pins) all worked with no problems.
I would assume you are including B6/7 to make 18 which you can't do if you use ICSP.
Just for test I changed your last version of code to enable port c and toggle all the pins. They all (C0-7) worked properly as well. This would give you 24 outputs. What this means basically is that the CCS code is working properly and you must have external hardware problems.
I would recommend only enabling one piece of code for a particular port at a time and get that working (hardware and software) then add the next until you get all the pins you want working.
FWIW, Your coding style is somewhat disorganized and this makes things worse for you. It would be easier if you organize it so you can better spot problems. You need to avoid using multistatement lines, standardize your indenting and put things in proper order(e.g. setup code for ports A,B,C and D in order rather than scrambled). |
|
![](templates/subSilver/images/spacer.gif) |
|