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

I got a problem about my Code. I can not figure out...
Goto page Previous  1, 2
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Need Help
Guest







I got a problem about my Code. I can not figure out...
PostPosted: Mon Sep 01, 2008 2:14 am     Reply with quote

Hello,

Thank you for your reply, ckielstra.

To ckielstra:

My CCS C compiler is v3.222 so does it not work for #fuses?

My reference manual is still have this command so why can it not work?

Because I am a beginner for this, I do not how to processor the clock. I just know that I have to write "#use delay(clock=10000000)" for my USART. Could you tell me how to check it?

I am using the PIC 16f877 not PIC 16F877A. Does it mean that it does not work for my test?
Could you tell me how should I do if I do not change the microcontroller?

Do you have any suggestion for my code? I still can not figure out what happen.



Thank you very much.



Any help will be appreciated.



Sincerely,
ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

PostPosted: Mon Sep 01, 2008 12:45 pm     Reply with quote

Quote:
My CCS C compiler is v3.222 so does it not work for #fuses?
v3.222 is very old, of beginning 2005. Not one of the most stable releases. Just like with the v4 compiler it took CCS some time to get it stable. This was one of the first v3.2xx releases that started to work but still contained some minor bugs.

I don't have this old version but tested with v3.226. If I create a test program without fuses the strange thing is that the compiler generates no default fuse settings like the newer compilers do. This means that I can't predict what settings your first program was using, this depends very much on your programmer.

Quote:
My reference manual is still have this command so why can it not work?
The problem is not in the fuse command not working but in which fuses you set.

Quote:
Because I am a beginner for this, I do not how to processor the clock. I just know that I have to write "#use delay(clock=10000000)" for my USART. Could you tell me how to check it?
If you don't know this, then who has build your electronics?
An RC clock generator is just what the name says: a combination of a Capacitor and a Resistor.
A crystal is a small metal box with two pins and two capacitors next to it.
Check your schematic for which of the two options is used and tell us the result.
Need Help
Guest







I got a problem about my Code. I can not figure out...
PostPosted: Mon Sep 01, 2008 3:58 pm     Reply with quote

Hello,

Thank you for your reply and so many suggestions, ckielstra.

To ckielstra:

If I wanna upgrade my version, is it free or I have to buy a new one?
If I use the new version, does it have any different in command and syntax?

If I can not upgrade my version, does it mean that this problem will be a deadlock?

Actually, I built this circuit by myself. I just download the datasheets about DM74LS47N and 7-segment from the internet and following the datasheet and pull 4 line A,B,C,D to the PIN_D0,PIN_D1,PIN_D2,PIN_D3 with resisters. I do not use anything else. By the way, I am using the 2840 development board and MPLAB v8.0. I do not use or see any crystal, or see any metal box with two capacitor.


To Wayne:

Thank you for offering so many suggestions. I really appreciate it. I changed the "else block" to "9"-->"0"-->"7" , "9"-->"0"-->"8", "9"-->"0"-->"9". I found that the 7-segment will run these block once and finally stop at "9". I think that it mean PIC A do not get "1" from PIC B. As you said, I use
while(1){
printf("1");
printf("2");
}
to show the number. I pretty sure that the PIC B send these two number to PIC A. The Hyper terminal can show the 12121212121212.........and so on but I do not why it does not work to use putc(1).




By the way, I found something weird. I used "a=getc()" and it be supposed to wait the chars come in and implement the following command after get the char. But On the 7-segment, it showed that "9"-->"0"-->"7" ==> "9"-->"0"-->"8" ==>"9"-->"0"-->"9" and finally stop at "9". The problem is if it can show these numbers on the 7-segment, does it mean that it get something in PIC B but not "1". Am I right? Sometimes the communication module do not connect to each other yet but the 7-segment still run these number "9"-->"0"-->"7" ==> "9"-->"0"-->"8" ==>"9"-->"0"-->"9" so does it any logic problem in my code?
Could you guys give me some suggestions?

Any help will be appreciated.

Thank you very much.

Sincerely,
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Sep 01, 2008 4:36 pm     Reply with quote

I compiled the following test program for vs. 3.222 and vs. 4.077.
The code in the .LST files are substantially the same. There's no
real effective difference. A program that uses simple functions
such as putc() and getc() should work with no problem in vs. 3.222.
Upgrading won't solve your problem. You need to add the fuses,
simplify your code greatly, check the hardware connections, and
make it work.
Code:
#include <16F877.H>
#fuses XT, NOWDT, NOPROTECT, BROWNOUT, PUT, NOLVP
#use delay(clock=4000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7, ERRORS)

//======================================
void main()
{
char c;

putc(0x55);

c =getc();

while(1);
}
Need Help
Guest







I got a problem about my Code. I can not figure out...
PostPosted: Tue Sep 02, 2008 2:47 am     Reply with quote

Hello,

Thank you guys' reply and suggestion.

To PCM programmer:

Thank you for your reply and suggestion.
I added the "#fuses XT, NOWDT, NOPROTECT, BROWNOUT, PUT, NOLVP" again but it still can not download the code into my microcontroller. Do you have any suggestion about solving the code download problem? Is it because of my C compiler version? I mean that I can not download the code into my microcontroller. I also check my circuit and it is fine. My circuit can show other number which I made for checking the status of receiving. Is there any logic problem in my code? Because I also met a weird situation which I mention in following message which I wanna give wayne. By the way, I am using PIC 16F877, 2840 development board, Hyper terminal and CCS C compiler v3.222.

Thank you very much.


To ckielstra:

If I wanna upgrade my version, is it free or I have to buy a new one?
If I use the new version, does it have any different in command and syntax?

If I can not upgrade my version, does it mean that this problem will be a deadlock?

Actually, I built this circuit by myself. I just download the datasheets about DM74LS47N and 7-segment from the internet and following the datasheet and pull 4 line A,B,C,D to the PIN_D0,PIN_D1,PIN_D2,PIN_D3 with resisters. I do not use anything else. By the way, I am using the 2840 development board and MPLAB v8.0. I do not use or see any crystal, or see any metal box with two capacitor.


To Wayne:

Thank you for offering so many suggestions. I really appreciate it. I changed the "else block" to "9"-->"0"-->"7" , "9"-->"0"-->"8", "9"-->"0"-->"9". I found that the 7-segment will run these block once and finally stop at "9". I think that it mean PIC A do not get "1" from PIC B. As you said, I use
while(1){
printf("1");
printf("2");
}
to show the number. I pretty sure that the PIC B send these two number to PIC A. The Hyper terminal can show the 12121212121212.........and so on but I do not why it does not work to use putc(1).




By the way, I found something weird. I used "a=getc()" and it be supposed to wait the chars come in and implement the following command after get the char. But On the 7-segment, it showed that "9"-->"0"-->"7" ==> "9"-->"0"-->"8" ==>"9"-->"0"-->"9" and finally stop at "9". The problem is if it can show these numbers on the 7-segment, does it mean that it get something in PIC B but not "1". Am I right? Sometimes the communication module do not connect to each other yet but the 7-segment still run these number "9"-->"0"-->"7" ==> "9"-->"0"-->"8" ==>"9"-->"0"-->"9" so does it any logic problem in my code?
Could you guys give me some suggestions?

Any help will be appreciated.

Thank you guys very much.

Sincerely,
Wayne_



Joined: 10 Oct 2007
Posts: 681

View user's profile Send private message

PostPosted: Tue Sep 02, 2008 2:47 am     Reply with quote

Could you please post your latest code with all the fixes.

Yes, this does imply that PIC B recieves a value other than 1 to start with.
This may be because the data is corrupt, There is noise on the rs232 line or the baud rates do not match.

If you post the latest code we could have a better look at what is happening.

What do you mean by communication module ?
Is there more than just
PIC A <---rs232---> PIC B ?

Is there something in between ?

PIC A <---rs232---> Comms Device <--------Bluetooth/rf/...?-------> Comms Device <---rs232---> PIC B
Need Help
Guest







I got a problem about my Code. I can not figure out...
PostPosted: Tue Sep 02, 2008 2:16 pm     Reply with quote

Hello,

To Wayne:

Thank you for your reply, Wayne.

I tested it yesterday and I changed the code a little bit. I got the different result. The 7-segment showed the "9"-->"0"-->"7" ==>"9"-->"0"-->"8" ==>"9"-->"0"-->"9" ==>"1"-->"0"-->"1" and finally it stop at "1". I think that the PIC B got the "1" from PIC A but it do not get the following number "3". I write the while(1) in PIC A and PIC B. If it do not get the number "3", it suppose to keep show "9"-->"0"-->"7" ==>"9"-->"0"-->"8" ==>"9"-->"0"-->"9"==>"9"-->"0"-->"7" and so on in 7-segment. Why does it just stop at "1"?

Now I am using wireless between PIC A and PIC B. I try to use Zig Bee or bluetooth to communicate to each other over RS232. Now I am using bluetooth first.

PIC A <------bluetooth -------->PIC B

The newest code is following after the all messages.

To PCM programmer:

Thank you for your reply and suggestion.
I added the "#fuses XT, NOWDT, NOPROTECT, BROWNOUT, PUT, NOLVP" again but it still can not download the code into my microcontroller. Do you have any suggestion about solving the code download problem? Is it because of my C compiler version? I mean that I can not download the code into my microcontroller. I also check my circuit and it is fine. My circuit can show other number which I made for checking the status of receiving. Is there any logic problem in my code? Because I also met a weird situation which I mention in following message which I wanna give wayne. By the way, I am using PIC 16F877, 2840 development board, Hyper terminal and CCS C compiler v3.222.

Thank you very much.

To ckielstra:

If I wanna upgrade my version, is it free or I have to buy a new one?
If I use the new version, does it have any different in command and syntax?

If I can not upgrade my version, does it mean that this problem will be a deadlock?

Actually, I built this circuit by myself. I just download the datasheets about DM74LS47N and 7-segment from the internet and following the datasheet and pull 4 line A,B,C,D to the PIN_D0,PIN_D1,PIN_D2,PIN_D3 with resisters. I do not use anything else. By the way, I am using the 2840 development board and MPLAB v8.0. I do not use or see any crystal, or see any metal box with two capacitor.

Any help will be appreciated.



Thank you very much.



Sincerely,
Need Help
Guest







I got a problem about my Code. I can not figure out...
PostPosted: Tue Sep 02, 2008 2:37 pm     Reply with quote

Hello,

I forgot to post the newest code.

I am sorry about that.

The following is the code:

PIC B:

#include<16F877.h>
#use delay(clock=10000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7,ERRORS)

int a,b,e,f,i;



void main()
{
set_tris_b(0xFF);
set_tris_d(0x00);


while(1)
{
if(input(PIN_B4))
{

delay_ms(10);
................................... // ignore
...................................//
...................................//
puts("g!");
delay_ms(100);

while(1)
{
delay_ms(1000);
a=getc();
if(a==1)
{

output_high(PIN_D0);
output_low(PIN_D1);
output_low(PIN_D2);
output_low(PIN_D3);
delay_ms(1000);
output_low(PIN_D0);
output_low(PIN_D1);
output_low(PIN_D2);
output_low(PIN_D3);
delay_ms(1000);
output_high(PIN_D0);
output_low(PIN_D1);
output_low(PIN_D2);
output_low(PIN_D3);
delay_ms(1000);
}
else
{
output_high(PIN_D0);
output_low(PIN_D1);
output_low(PIN_D2);
output_high(PIN_D3);
delay_ms(1000);
output_low(PIN_D0);
output_low(PIN_D1);
output_low(PIN_D2);
output_low(PIN_D3);
delay_ms(1000);
output_high(PIN_D0);
output_high(PIN_D1);
output_high(PIN_D2);
output_low(PIN_D3);
delay_ms(1000);
}



b=a+1;

putc(b);
delay_ms(100);
e=getc();
if(e==3)
{

output_high(PIN_D0);
output_high(PIN_D1);
output_low(PIN_D2);
output_low(PIN_D3);
delay_ms(1000);
output_low(PIN_D0);
output_low(PIN_D1);
output_low(PIN_D2);
output_low(PIN_D3);
delay_ms(1000);
output_high(PIN_D0);
output_high(PIN_D1);
output_low(PIN_D2);
output_low(PIN_D3);
delay_ms(1000);
}
else
{
output_high(PIN_D0);
output_low(PIN_D1);
output_low(PIN_D2);
output_high(PIN_D3);
delay_ms(1000);
output_low(PIN_D0);
output_low(PIN_D1);
output_low(PIN_D2);
output_low(PIN_D3);
delay_ms(1000);
output_low(PIN_D0);
output_low(PIN_D1);
output_low(PIN_D2);
output_high(PIN_D3);
delay_ms(1000);

}


f=e+1;

putc(f);

i=getc();
if(i==5)
{

output_high(PIN_D0);
output_low(PIN_D1);
output_high(PIN_D2);
output_low(PIN_D3);
delay_ms(1000);
output_low(PIN_D0);
output_low(PIN_D1);
output_low(PIN_D2);
output_low(PIN_D3);
delay_ms(1000);
output_high(PIN_D0);
output_low(PIN_D1);
output_high(PIN_D2);
output_low(PIN_D3);
delay_ms(1000);
}
else
{
output_high(PIN_D0);
output_low(PIN_D1);
output_low(PIN_D2);
output_high(PIN_D3);
delay_ms(1000);
output_low(PIN_D0);
output_low(PIN_D1);
output_low(PIN_D2);
output_low(PIN_D3);
delay_ms(1000);
output_high(PIN_D0);
output_low(PIN_D1);
output_low(PIN_D2);
output_high(PIN_D3);
delay_ms(1000);
}

}
}
}
}

PIC A:

#include<16F877.h>
#use delay(clock=10000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7)


int c,d,g,h;



void main()
{
while(1)
{

delay_ms(5000);
putc(1);
delay_ms(13000);
c=getc();
if(c==2)
{
delay_ms(10);
d=c+1;
delay_ms(30);
putc(d);
delay_ms(10);
}

delay_ms(3500);
g=getc();
if(g==4)
{
delay_ms(10);
h=g+1;
putc(h);
delay_ms(10);
}
}
}
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Sep 02, 2008 2:39 pm     Reply with quote

Quote:
Do you have any suggestion about solving the code download problem?

Get one of the standard development environments:

1. PCWH with a ICD-U40 programmer.

or

2. MPLAB with a ICD2 programmer.

If you have a standard development environment, then you can
program ("download") your PIC with no problems.
ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

PostPosted: Tue Sep 02, 2008 4:37 pm     Reply with quote

Quote:
If I wanna upgrade my version, is it free or I have to buy a new one?
CCS does not give free upgrades. You can buy a one year maintenance allowing you the right to download all new updates for the next year. I think you can buy this 'maintenance' even when you have an old version, so effectively you are buying what other companies call an 'upgrade'.

For now stick with v3.222. It is not the best version but the bugs are minor and most likely can be worked around. I'm still a happy user of v3.226 for one of my products.

As long as you don't know if your self built circuit is powered by an RC-oscillator or by a crystal I think you have a more basic problem. You have built a system but you don't know how it is working.

The clock question itself is not so important, but I want to know this to rule out some other problems.

Quote:
I am using the 2840 development board and MPLAB v8.0. I do not use or see any crystal, or see any metal box with two capacitor.
I just found a link to the schematics of the board you use: http://www.basicmicro.com/downloads/docs/proto2840.pdf
If you have placed the components as they are supposed to be then you are using a Ceramic Resonator.

For 10MHz operation the fuses should then be set as:
Code:
#fuses HS, NOLVP, NOWDT


Thinking of it... You are using an old compiler and an ancient PIC.
What brand and type of programmer are you using? Less than 1% of the people using a PIC are using a Low Voltage Programmer (LVP). You might be one of these few people. Try changing the NOLVP fuse to LVP if programming fails.
Wayne_



Joined: 10 Oct 2007
Posts: 681

View user's profile Send private message

PostPosted: Thu Sep 04, 2008 9:30 am     Reply with quote

A couple of things,
first create a routine for displaying a number :-
Code:

void show(int val)
{
  if (val & 0x01)
    output_high(PIN_D0);
  else
    output_low(PIN_D0);
  if (val & 0x02)
    output_high(PIN_D1);
  else
    output_low(PIN_D1);
  if (val & 0x04)
    output_high(PIN_D2);
  else
    output_low(PIN_D2);
  if (val & 0x08)
    output_high(PIN_D3);
  else
    output_low(PIN_D3);
}

use show(0); or show(9) etc to display the number, this will make your code more readable.

Secondly, you still have delays in there where you don't need them.
Any delay before a getc is pointless as this waits for a value anyway, remove them.

Thirdly, I would write the code so that PIC A has a loop where it sends the value 1 and checks for an input (if (kbhit()) for a period of time
Code:

  int16 timeout;
  int c = 0;
 
  do
  {
    putc(1);
    timeout = 1000;
    while (timeout--)
    {
      if (kbhit())
      {
        c = getc();
        break;
      }
    } 
  }  while(c != 2)


And in PIC B wait for a 1

Code:

  do {
    a = getc();
  } while (a != 1);


This way it doesn't matter which is turned on first, also your routines will not start until the correct value is sent and recieved.
Need Help
Guest







I got a problem about my Code. I can not figure out...
PostPosted: Fri Sep 05, 2008 2:21 am     Reply with quote

Hello,

Thank you guys again. I really appreciate you guys' suggestion and reply.


To ckielstra:

Thank you for your reply. I did some check and I think that I am using crystal for clock and it is 10MHz. I used the #fuses which you suggested but it still can not download. I do not know reason but I will try your suggestion.


To Wayne:

Thank you for your suggestion and help, Wayne. I will try your way to test that and let you know the result. What do you mean show(0); or show(9)?

To PCM programmer:

Thank you for your suggestion. I am not sure that I can buy a new device for these test but I appreciate your suggestion.


Again, I really really appreciate you guys' suggestion and help. If you guys get any new idea, plz let me know. Any suggestion and help will be appreciated.



Thank you so much.



Sincerely,
Wayne_



Joined: 10 Oct 2007
Posts: 681

View user's profile Send private message

PostPosted: Fri Sep 05, 2008 3:46 am     Reply with quote

show(0); will call the show routine to display the value 0.

There is actually a couple of issues with my code and unfortunately I don't have the time at the moment to rectify.

One problem with your code is the puts("g!"); at the start.

What is this for ?
Do you need to do this to initialise the devices ?
Why doesn't PIC A do it ?
If this is just for debugging then what will happen is that these 2 characters will sit in PIC A's input buffer and will be the first 2 chars to be read by getc(). This will only happen though if PIC A is on before PIC B!
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Goto page Previous  1, 2
Page 2 of 2

 
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