|
|
View previous topic :: View next topic |
Author |
Message |
les Guest
|
First time using a PIC, please advise. |
Posted: Wed Mar 26, 2003 10:34 am |
|
|
Hello, This is the first time I have ever used a micro-controller and I'm having a lot of silly problems. I’m trying to write a very simple program with no success. The program is to output a number over the RS232 line using the printf statement every time the PIC receives the character Y. I have written a program (Prog 1 below) to insure the hardware works OK and it does. But when I try the next program (Prog 2) nothing happens. I have tried using decimal, hex and the character Y in the while (a!=89); and it still doesn’t work. Could anyone help?
Thanks
//-----------------------------------------------
// Prog 1
#include <16F877.h>
#fuses XT, NOWDT, NOPROTECT, PUT, BROWNOUT, NOLVP
#use Delay(clock=4000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7)
main()
{
while(TRUE)
{
putc(getc());
}
}
//-----------------------------------------------
//Prog 2
#include <16F877.h>
#fuses XT, NOWDT, NOPROTECT, PUT, BROWNOUT, NOLVP
#use Delay(clock=4000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7)
int a;
int nu;
main()
{
a = 0;
nu = 2;
do
{
a = getch();
} while (a!=89);
if (a==89);
{
printf("\%i",nu);
}
}
___________________________
This message was ported from CCS's old forum
Original Post ID: 13091 |
|
|
R.J.Hamlett Guest
|
Re: First time using a PIC, please advise. |
Posted: Wed Mar 26, 2003 11:40 am |
|
|
:=Hello, This is the first time I have ever used a micro-controller and I'm having a lot of silly problems. I’m trying to write a very simple program with no success. The program is to output a number over the RS232 line using the printf statement every time the PIC receives the character Y. I have written a program (Prog 1 below) to insure the hardware works OK and it does. But when I try the next program (Prog 2) nothing happens. I have tried using decimal, hex and the character Y in the while (a!=89); and it still doesn’t work. Could anyone help?
:=
:=Thanks
:=
:=
:=
:=//-----------------------------------------------
:=// Prog 1
:=#include <16F877.h>
:=#fuses XT, NOWDT, NOPROTECT, PUT, BROWNOUT, NOLVP
:=#use Delay(clock=4000000)
:=#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7)
:=main()
:={
:= while(TRUE)
:= {
:= putc(getc());
:= }
:=
:=}
:=
:=
:=//-----------------------------------------------
:=//Prog 2
:=#include <16F877.h>
:=#fuses XT, NOWDT, NOPROTECT, PUT, BROWNOUT, NOLVP
:=#use Delay(clock=4000000)
:=#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7)
:=int a;
:=int nu;
:=main()
:={
:=a = 0;
:=nu = 2;
:= do
:= {
:= a = getch();
Here the processor will wait for a character, and read it.
:= } while (a!=89);
Here the processor will wait forever, if the character does not equal 89.
:= if (a==89);
Now the statement ';' will be executed if a==89.
:={
:=printf("\%i",nu);
This code is executed for the character, that has passed the earlier tests, but '\%i', is not a legitimate printf format command...
:=}
:=}
You are effectively 'testing twice', The second test is redundant, but unless the very first character matches your test, nothing else happens. Then the output is not what you expect, because the format string is invalid.
Try this instead:
#include <16F877.h>
#fuses XT, NOWDT, NOPROTECT, PUT, BROWNOUT, NOLVP
#use Delay(clock=4000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7)
int a;
int nu;
main()
{
nu = 2;
do {
a = getch();
if (a=='Y') {
printf("\%d",nu++);
}
} while (true);
}
This will send '2' in ASCII the first time a 'Y' is seen, and then '3' the next time, '4' the next etc., ignoring any other character.
Best Wishes
___________________________
This message was ported from CCS's old forum
Original Post ID: 13094 |
|
|
les Guest
|
Re: First time using a PIC, please advise. |
Posted: Wed Mar 26, 2003 12:45 pm |
|
|
:=:=Hello, This is the first time I have ever used a micro-controller and I'm having a lot of silly problems. I’m trying to write a very simple program with no success. The program is to output a number over the RS232 line using the printf statement every time the PIC receives the character Y. I have written a program (Prog 1 below) to insure the hardware works OK and it does. But when I try the next program (Prog 2) nothing happens. I have tried using decimal, hex and the character Y in the while (a!=89); and it still doesn’t work. Could anyone help?
:=:=
:=:=Thanks
:=:=
:=:=
:=:=
:=:=//-----------------------------------------------
:=:=// Prog 1
:=:=#include <16F877.h>
:=:=#fuses XT, NOWDT, NOPROTECT, PUT, BROWNOUT, NOLVP
:=:=#use Delay(clock=4000000)
:=:=#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7)
:=:=main()
:=:={
:=:= while(TRUE)
:=:= {
:=:= putc(getc());
:=:= }
:=:=
:=:=}
:=:=
:=:=
:=:=//-----------------------------------------------
:=:=//Prog 2
:=:=#include <16F877.h>
:=:=#fuses XT, NOWDT, NOPROTECT, PUT, BROWNOUT, NOLVP
:=:=#use Delay(clock=4000000)
:=:=#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7)
:=:=int a;
:=:=int nu;
:=:=main()
:=:={
:=:=a = 0;
:=:=nu = 2;
:=:= do
:=:= {
:=:= a = getch();
:=Here the processor will wait for a character, and read it.
:=
:=:= } while (a!=89);
:=Here the processor will wait forever, if the character does not equal 89.
:=
:=:= if (a==89);
:=Now the statement ';' will be executed if a==89.
:=
:=:={
:=:=printf("\%i",nu);
:=This code is executed for the character, that has passed the earlier tests, but '\%i', is not a legitimate printf format command...
:=
:=:=}
:=:=}
:=You are effectively 'testing twice', The second test is redundant, but unless the very first character matches your test, nothing else happens. Then the output is not what you expect, because the format string is invalid.
:=
:=Try this instead:
:=#include <16F877.h>
:=#fuses XT, NOWDT, NOPROTECT, PUT, BROWNOUT, NOLVP
:=#use Delay(clock=4000000)
:=#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7)
:=int a;
:=int nu;
:=main()
:={
:= nu = 2;
:= do {
:= a = getch();
:= if (a=='Y') {
:= printf("\%d",nu++);
:= }
:= } while (true);
:=}
:=This will send '2' in ASCII the first time a 'Y' is seen, and then '3' the next time, '4' the next etc., ignoring any other character.
:=
:=Best Wishes
Thanks for your help, its much appreciated.
I do have one more question, sometimes the program stops counting up and starts repeating the same number. Have you any ideas?
___________________________
This message was ported from CCS's old forum
Original Post ID: 13099 |
|
|
Humberto
Joined: 08 Sep 2003 Posts: 1215 Location: Buenos Aires, La Reina del Plata
|
Re: First time using a PIC, please advise. |
Posted: Wed Mar 26, 2003 4:06 pm |
|
|
:=:=:=Hello, This is the first time I have ever used a micro-controller and I'm having a lot of silly problems. I’m trying to write a very simple program with no success. The program is to output a number over the RS232 line using the printf statement every time the PIC receives the character Y. I have written a program (Prog 1 below) to insure the hardware works OK and it does. But when I try the next program (Prog 2) nothing happens. I have tried using decimal, hex and the character Y in the while (a!=89); and it still doesn’t work. Could anyone help?
:=:=:=
:=:=:=Thanks
:=:=:=
:=:=:=
:=:=:=
:=:=:=//-----------------------------------------------
:=:=:=// Prog 1
:=:=:=#include <16F877.h>
:=:=:=#fuses XT, NOWDT, NOPROTECT, PUT, BROWNOUT, NOLVP
:=:=:=#use Delay(clock=4000000)
:=:=:=#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7)
:=:=:=main()
:=:=:={
:=:=:= while(TRUE)
:=:=:= {
:=:=:= putc(getc());
:=:=:= }
:=:=:=
:=:=:=}
:=:=:=
:=:=:=
:=:=:=//-----------------------------------------------
:=:=:=//Prog 2
:=:=:=#include <16F877.h>
:=:=:=#fuses XT, NOWDT, NOPROTECT, PUT, BROWNOUT, NOLVP
:=:=:=#use Delay(clock=4000000)
:=:=:=#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7)
:=:=:=int a;
:=:=:=int nu;
:=:=:=main()
:=:=:={
:=:=:=a = 0;
:=:=:=nu = 2;
:=:=:= do
:=:=:= {
:=:=:= a = getch();
:=:=Here the processor will wait for a character, and read it.
:=:=
:=:=:= } while (a!=89);
:=:=Here the processor will wait forever, if the character does not equal 89.
:=:=
:=:=:= if (a==89);
:=:=Now the statement ';' will be executed if a==89.
:=:=
:=:=:={
:=:=:=printf("\%i",nu);
:=:=This code is executed for the character, that has passed the earlier tests, but '\%i', is not a legitimate printf format command...
:=:=
:=:=:=}
:=:=:=}
:=:=You are effectively 'testing twice', The second test is redundant, but unless the very first character matches your test, nothing else happens. Then the output is not what you expect, because the format string is invalid.
:=:=
:=:=Try this instead:
:=:=#include <16F877.h>
:=:=#fuses XT, NOWDT, NOPROTECT, PUT, BROWNOUT, NOLVP
:=:=#use Delay(clock=4000000)
:=:=#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7)
:=:=int a;
:=:=int nu;
:=:=main()
:=:={
:=:= nu = 2;
:=:= do {
:=:= a = getch();
:=:= if (a=='Y') {
:=:= printf("\%d",nu++);
:=:= }
:=:= } while (true);
:=:=}
:=:=This will send '2' in ASCII the first time a 'Y' is seen, and then '3' the next time, '4' the next etc., ignoring any other character.
:=:=
:=:=Best Wishes
:=
:=
:=Thanks for your help, its much appreciated.
:=I do have one more question, sometimes the program stops counting up and starts repeating the same number. Have you any ideas?
#include <16F877.h>
#fuses XT, NOWDT, NOPROTECT, PUT, BROWNOUT, NOLVP
#use Delay(clock=4000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7)
int a;
int nu;
main()
{
nu = 2;
do {
a = getch();
if (a=='Y'){
printf("\%d",nu++);
a = 0; // clear the TRUE if condition
}
} while (true);
}
rgds,
Humberto
___________________________
This message was ported from CCS's old forum
Original Post ID: 13110 _________________ Humber |
|
|
R.J.Hamlett Guest
|
Re: First time using a PIC, please advise. |
Posted: Thu Mar 27, 2003 4:52 am |
|
|
:=:=:=:=Hello, This is the first time I have ever used a micro-controller and I'm having a lot of silly problems. I’m trying to write a very simple program with no success. The program is to output a number over the RS232 line using the printf statement every time the PIC receives the character Y. I have written a program (Prog 1 below) to insure the hardware works OK and it does. But when I try the next program (Prog 2) nothing happens. I have tried using decimal, hex and the character Y in the while (a!=89); and it still doesn’t work. Could anyone help?
:=:=:=:=
:=:=:=:=Thanks
:=:=:=:=
:=:=:=:=
:=:=:=:=
:=:=:=:=//-----------------------------------------------
:=:=:=:=// Prog 1
:=:=:=:=#include <16F877.h>
:=:=:=:=#fuses XT, NOWDT, NOPROTECT, PUT, BROWNOUT, NOLVP
:=:=:=:=#use Delay(clock=4000000)
:=:=:=:=#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7)
:=:=:=:=main()
:=:=:=:={
:=:=:=:= while(TRUE)
:=:=:=:= {
:=:=:=:= putc(getc());
:=:=:=:= }
:=:=:=:=
:=:=:=:=}
:=:=:=:=
:=:=:=:=
:=:=:=:=//-----------------------------------------------
:=:=:=:=//Prog 2
:=:=:=:=#include <16F877.h>
:=:=:=:=#fuses XT, NOWDT, NOPROTECT, PUT, BROWNOUT, NOLVP
:=:=:=:=#use Delay(clock=4000000)
:=:=:=:=#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7)
:=:=:=:=int a;
:=:=:=:=int nu;
:=:=:=:=main()
:=:=:=:={
:=:=:=:=a = 0;
:=:=:=:=nu = 2;
:=:=:=:= do
:=:=:=:= {
:=:=:=:= a = getch();
:=:=:=Here the processor will wait for a character, and read it.
:=:=:=
:=:=:=:= } while (a!=89);
:=:=:=Here the processor will wait forever, if the character does not equal 89.
:=:=:=
:=:=:=:= if (a==89);
:=:=:=Now the statement ';' will be executed if a==89.
:=:=:=
:=:=:=:={
:=:=:=:=printf("\%i",nu);
:=:=:=This code is executed for the character, that has passed the earlier tests, but '\%i', is not a legitimate printf format command...
:=:=:=
:=:=:=:=}
:=:=:=:=}
:=:=:=You are effectively 'testing twice', The second test is redundant, but unless the very first character matches your test, nothing else happens. Then the output is not what you expect, because the format string is invalid.
:=:=:=
:=:=:=Try this instead:
:=:=:=#include <16F877.h>
:=:=:=#fuses XT, NOWDT, NOPROTECT, PUT, BROWNOUT, NOLVP
:=:=:=#use Delay(clock=4000000)
:=:=:=#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7)
:=:=:=int a;
:=:=:=int nu;
:=:=:=main()
:=:=:={
:=:=:= nu = 2;
:=:=:= do {
:=:=:= a = getch();
:=:=:= if (a=='Y') {
:=:=:= printf("\%d",nu++);
:=:=:= }
:=:=:= } while (true);
:=:=:=}
:=:=:=This will send '2' in ASCII the first time a 'Y' is seen, and then '3' the next time, '4' the next etc., ignoring any other character.
:=:=:=
:=:=:=Best Wishes
:=:=
:=:=
:=:=Thanks for your help, its much appreciated.
:=:=I do have one more question, sometimes the program stops counting up and starts repeating the same number. Have you any ideas?
:=
:=#include <16F877.h>
:=#fuses XT, NOWDT, NOPROTECT, PUT, BROWNOUT, NOLVP
:=#use Delay(clock=4000000)
:=#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7)
:=int a;
:=int nu;
:=main()
:={
:= nu = 2;
:= do {
:= a = getch();
:= if (a=='Y'){
:= printf("\%d",nu++);
:= a = 0; // clear the TRUE if condition
:= }
:= } while (true);
:=}
:=
:=rgds,
:=Humberto
The clear here shouldn't be needed, since 'a' is set by the getch before the test...
Even if the true condition was still met, it wouldn't stop the increment.
Basically, if it sends back a character, it should do the increment. The exception would be (for instance), if the MCLR line was floating, and the chip was occasionally doing a hardware reset, when the counter would restart.
What number does it 'stop' on?. Is there a pattern?.
Best Wishes
___________________________
This message was ported from CCS's old forum
Original Post ID: 13129 |
|
|
les Guest
|
Re: First time using a PIC, please advise. |
Posted: Thu Mar 27, 2003 9:00 am |
|
|
:=:=:=:=:=Hello, This is the first time I have ever used a micro-controller and I'm having a lot of silly problems. I’m trying to write a very simple program with no success. The program is to output a number over the RS232 line using the printf statement every time the PIC receives the character Y. I have written a program (Prog 1 below) to insure the hardware works OK and it does. But when I try the next program (Prog 2) nothing happens. I have tried using decimal, hex and the character Y in the while (a!=89); and it still doesn’t work. Could anyone help?
:=:=:=:=:=
:=:=:=:=:=Thanks
:=:=:=:=:=
:=:=:=:=:=
:=:=:=:=:=
:=:=:=:=:=//-----------------------------------------------
:=:=:=:=:=// Prog 1
:=:=:=:=:=#include <16F877.h>
:=:=:=:=:=#fuses XT, NOWDT, NOPROTECT, PUT, BROWNOUT, NOLVP
:=:=:=:=:=#use Delay(clock=4000000)
:=:=:=:=:=#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7)
:=:=:=:=:=main()
:=:=:=:=:={
:=:=:=:=:= while(TRUE)
:=:=:=:=:= {
:=:=:=:=:= putc(getc());
:=:=:=:=:= }
:=:=:=:=:=
:=:=:=:=:=}
:=:=:=:=:=
:=:=:=:=:=
:=:=:=:=:=//-----------------------------------------------
:=:=:=:=:=//Prog 2
:=:=:=:=:=#include <16F877.h>
:=:=:=:=:=#fuses XT, NOWDT, NOPROTECT, PUT, BROWNOUT, NOLVP
:=:=:=:=:=#use Delay(clock=4000000)
:=:=:=:=:=#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7)
:=:=:=:=:=int a;
:=:=:=:=:=int nu;
:=:=:=:=:=main()
:=:=:=:=:={
:=:=:=:=:=a = 0;
:=:=:=:=:=nu = 2;
:=:=:=:=:= do
:=:=:=:=:= {
:=:=:=:=:= a = getch();
:=:=:=:=Here the processor will wait for a character, and read it.
:=:=:=:=
:=:=:=:=:= } while (a!=89);
:=:=:=:=Here the processor will wait forever, if the character does not equal 89.
:=:=:=:=
:=:=:=:=:= if (a==89);
:=:=:=:=Now the statement ';' will be executed if a==89.
:=:=:=:=
:=:=:=:=:={
:=:=:=:=:=printf("\%i",nu);
:=:=:=:=This code is executed for the character, that has passed the earlier tests, but '\%i', is not a legitimate printf format command...
:=:=:=:=
:=:=:=:=:=}
:=:=:=:=:=}
:=:=:=:=You are effectively 'testing twice', The second test is redundant, but unless the very first character matches your test, nothing else happens. Then the output is not what you expect, because the format string is invalid.
:=:=:=:=
:=:=:=:=Try this instead:
:=:=:=:=#include <16F877.h>
:=:=:=:=#fuses XT, NOWDT, NOPROTECT, PUT, BROWNOUT, NOLVP
:=:=:=:=#use Delay(clock=4000000)
:=:=:=:=#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7)
:=:=:=:=int a;
:=:=:=:=int nu;
:=:=:=:=main()
:=:=:=:={
:=:=:=:= nu = 2;
:=:=:=:= do {
:=:=:=:= a = getch();
:=:=:=:= if (a=='Y') {
:=:=:=:= printf("\%d",nu++);
:=:=:=:= }
:=:=:=:= } while (true);
:=:=:=:=}
:=:=:=:=This will send '2' in ASCII the first time a 'Y' is seen, and then '3' the next time, '4' the next etc., ignoring any other character.
:=:=:=:=
:=:=:=:=Best Wishes
:=:=:=
:=:=:=
:=:=:=Thanks for your help, its much appreciated.
:=:=:=I do have one more question, sometimes the program stops counting up and starts repeating the same number. Have you any ideas?
:=:=
:=:=#include <16F877.h>
:=:=#fuses XT, NOWDT, NOPROTECT, PUT, BROWNOUT, NOLVP
:=:=#use Delay(clock=4000000)
:=:=#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7)
:=:=int a;
:=:=int nu;
:=:=main()
:=:={
:=:= nu = 2;
:=:= do {
:=:= a = getch();
:=:= if (a=='Y'){
:=:= printf("\%d",nu++);
:=:= a = 0; // clear the TRUE if condition
:=:= }
:=:= } while (true);
:=:=}
:=:=
:=:=rgds,
:=:=Humberto
:=The clear here shouldn't be needed, since 'a' is set by the getch before the test...
:=Even if the true condition was still met, it wouldn't stop the increment.
:=Basically, if it sends back a character, it should do the increment. The exception would be (for instance), if the MCLR line was floating, and the chip was occasionally doing a hardware reset, when the counter would restart.
:=What number does it 'stop' on?. Is there a pattern?.
:=
:=Best Wishes
Hello
Sorry I havent replied before, lack of time. There doesnt seen to be any pattern. It gets to a number then returns back to 2 and keeps repeating. eg. 2,3,4,5,6,2,2,2,2,2,2,
___________________________
This message was ported from CCS's old forum
Original Post ID: 13137 |
|
|
R.J.Hamlett Guest
|
Re: First time using a PIC, please advise. |
Posted: Thu Mar 27, 2003 9:14 am |
|
|
:=:=:=:=:=:=Hello, This is the first time I have ever used a micro-controller and I'm having a lot of silly problems. I’m trying to write a very simple program with no success. The program is to output a number over the RS232 line using the printf statement every time the PIC receives the character Y. I have written a program (Prog 1 below) to insure the hardware works OK and it does. But when I try the next program (Prog 2) nothing happens. I have tried using decimal, hex and the character Y in the while (a!=89); and it still doesn’t work. Could anyone help?
:=:=:=:=:=:=
:=:=:=:=:=:=Thanks
:=:=:=:=:=:=
:=:=:=:=:=:=
:=:=:=:=:=:=
:=:=:=:=:=:=//-----------------------------------------------
:=:=:=:=:=:=// Prog 1
:=:=:=:=:=:=#include <16F877.h>
:=:=:=:=:=:=#fuses XT, NOWDT, NOPROTECT, PUT, BROWNOUT, NOLVP
:=:=:=:=:=:=#use Delay(clock=4000000)
:=:=:=:=:=:=#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7)
:=:=:=:=:=:=main()
:=:=:=:=:=:={
:=:=:=:=:=:= while(TRUE)
:=:=:=:=:=:= {
:=:=:=:=:=:= putc(getc());
:=:=:=:=:=:= }
:=:=:=:=:=:=
:=:=:=:=:=:=}
:=:=:=:=:=:=
:=:=:=:=:=:=
:=:=:=:=:=:=//-----------------------------------------------
:=:=:=:=:=:=//Prog 2
:=:=:=:=:=:=#include <16F877.h>
:=:=:=:=:=:=#fuses XT, NOWDT, NOPROTECT, PUT, BROWNOUT, NOLVP
:=:=:=:=:=:=#use Delay(clock=4000000)
:=:=:=:=:=:=#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7)
:=:=:=:=:=:=int a;
:=:=:=:=:=:=int nu;
:=:=:=:=:=:=main()
:=:=:=:=:=:={
:=:=:=:=:=:=a = 0;
:=:=:=:=:=:=nu = 2;
:=:=:=:=:=:= do
:=:=:=:=:=:= {
:=:=:=:=:=:= a = getch();
:=:=:=:=:=Here the processor will wait for a character, and read it.
:=:=:=:=:=
:=:=:=:=:=:= } while (a!=89);
:=:=:=:=:=Here the processor will wait forever, if the character does not equal 89.
:=:=:=:=:=
:=:=:=:=:=:= if (a==89);
:=:=:=:=:=Now the statement ';' will be executed if a==89.
:=:=:=:=:=
:=:=:=:=:=:={
:=:=:=:=:=:=printf("\%i",nu);
:=:=:=:=:=This code is executed for the character, that has passed the earlier tests, but '\%i', is not a legitimate printf format command...
:=:=:=:=:=
:=:=:=:=:=:=}
:=:=:=:=:=:=}
:=:=:=:=:=You are effectively 'testing twice', The second test is redundant, but unless the very first character matches your test, nothing else happens. Then the output is not what you expect, because the format string is invalid.
:=:=:=:=:=
:=:=:=:=:=Try this instead:
:=:=:=:=:=#include <16F877.h>
:=:=:=:=:=#fuses XT, NOWDT, NOPROTECT, PUT, BROWNOUT, NOLVP
:=:=:=:=:=#use Delay(clock=4000000)
:=:=:=:=:=#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7)
:=:=:=:=:=int a;
:=:=:=:=:=int nu;
:=:=:=:=:=main()
:=:=:=:=:={
:=:=:=:=:= nu = 2;
:=:=:=:=:= do {
:=:=:=:=:= a = getch();
:=:=:=:=:= if (a=='Y') {
:=:=:=:=:= printf("\%d",nu++);
:=:=:=:=:= }
:=:=:=:=:= } while (true);
:=:=:=:=:=}
:=:=:=:=:=This will send '2' in ASCII the first time a 'Y' is seen, and then '3' the next time, '4' the next etc., ignoring any other character.
:=:=:=:=:=
:=:=:=:=:=Best Wishes
:=:=:=:=
:=:=:=:=
:=:=:=:=Thanks for your help, its much appreciated.
:=:=:=:=I do have one more question, sometimes the program stops counting up and starts repeating the same number. Have you any ideas?
:=:=:=
:=:=:=#include <16F877.h>
:=:=:=#fuses XT, NOWDT, NOPROTECT, PUT, BROWNOUT, NOLVP
:=:=:=#use Delay(clock=4000000)
:=:=:=#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7)
:=:=:=int a;
:=:=:=int nu;
:=:=:=main()
:=:=:={
:=:=:= nu = 2;
:=:=:= do {
:=:=:= a = getch();
:=:=:= if (a=='Y'){
:=:=:= printf("\%d",nu++);
:=:=:= a = 0; // clear the TRUE if condition
:=:=:= }
:=:=:= } while (true);
:=:=:=}
:=:=:=
:=:=:=rgds,
:=:=:=Humberto
:=:=The clear here shouldn't be needed, since 'a' is set by the getch before the test...
:=:=Even if the true condition was still met, it wouldn't stop the increment.
:=:=Basically, if it sends back a character, it should do the increment. The exception would be (for instance), if the MCLR line was floating, and the chip was occasionally doing a hardware reset, when the counter would restart.
:=:=What number does it 'stop' on?. Is there a pattern?.
:=:=
:=:=Best Wishes
:=
:=Hello
:=Sorry I havent replied before, lack of time. There doesnt seen to be any pattern. It gets to a number then returns back to 2 and keeps repeating. eg. 2,3,4,5,6,2,2,2,2,2,2,
So how is MCLR pulled up?.
It is behaving as if something is causing a reset. Normally, I'd think in terms of a watchdog, and suggest you double check that your programmer does disable the watchog (this is disabled in the code, but if your programmer is not importing the fuses properly, could still be enabled). However if this was the case, I'd expect it to count in 'waves', resetting every couple of seconds (assuming the largest divider on the watchdog).
So try this:
#include <16F877.h>
#fuses XT, NOWDT, NOPROTECT, PUT, BROWNOUT, NOLVP
#use Delay(clock=4000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7)
int a;
int nu;
main()
{
nu = 2;
printf("RESET \%d\n",restart_cause());
do {
a = getch();
if (a=='Y') {
printf("\%d",nu++);
}
} while (true);
}
Which will prove if the chip is resetting, and give a number saying what type of reset it is. Post this back, and it may be possible to work out what is happening.
Best Wishes
___________________________
This message was ported from CCS's old forum
Original Post ID: 13138 |
|
|
les Guest
|
Re: First time using a PIC, please advise. |
Posted: Thu Mar 27, 2003 10:28 am |
|
|
:=:=:=:=:=:=:=Hello, This is the first time I have ever used a micro-controller and I'm having a lot of silly problems. I’m trying to write a very simple program with no success. The program is to output a number over the RS232 line using the printf statement every time the PIC receives the character Y. I have written a program (Prog 1 below) to insure the hardware works OK and it does. But when I try the next program (Prog 2) nothing happens. I have tried using decimal, hex and the character Y in the while (a!=89); and it still doesn’t work. Could anyone help?
:=:=:=:=:=:=:=
:=:=:=:=:=:=:=Thanks
:=:=:=:=:=:=:=
:=:=:=:=:=:=:=
:=:=:=:=:=:=:=
:=:=:=:=:=:=:=//-----------------------------------------------
:=:=:=:=:=:=:=// Prog 1
:=:=:=:=:=:=:=#include <16F877.h>
:=:=:=:=:=:=:=#fuses XT, NOWDT, NOPROTECT, PUT, BROWNOUT, NOLVP
:=:=:=:=:=:=:=#use Delay(clock=4000000)
:=:=:=:=:=:=:=#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7)
:=:=:=:=:=:=:=main()
:=:=:=:=:=:=:={
:=:=:=:=:=:=:= while(TRUE)
:=:=:=:=:=:=:= {
:=:=:=:=:=:=:= putc(getc());
:=:=:=:=:=:=:= }
:=:=:=:=:=:=:=
:=:=:=:=:=:=:=}
:=:=:=:=:=:=:=
:=:=:=:=:=:=:=
:=:=:=:=:=:=:=//-----------------------------------------------
:=:=:=:=:=:=:=//Prog 2
:=:=:=:=:=:=:=#include <16F877.h>
:=:=:=:=:=:=:=#fuses XT, NOWDT, NOPROTECT, PUT, BROWNOUT, NOLVP
:=:=:=:=:=:=:=#use Delay(clock=4000000)
:=:=:=:=:=:=:=#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7)
:=:=:=:=:=:=:=int a;
:=:=:=:=:=:=:=int nu;
:=:=:=:=:=:=:=main()
:=:=:=:=:=:=:={
:=:=:=:=:=:=:=a = 0;
:=:=:=:=:=:=:=nu = 2;
:=:=:=:=:=:=:= do
:=:=:=:=:=:=:= {
:=:=:=:=:=:=:= a = getch();
:=:=:=:=:=:=Here the processor will wait for a character, and read it.
:=:=:=:=:=:=
:=:=:=:=:=:=:= } while (a!=89);
:=:=:=:=:=:=Here the processor will wait forever, if the character does not equal 89.
:=:=:=:=:=:=
:=:=:=:=:=:=:= if (a==89);
:=:=:=:=:=:=Now the statement ';' will be executed if a==89.
:=:=:=:=:=:=
:=:=:=:=:=:=:={
:=:=:=:=:=:=:=printf("\%i",nu);
:=:=:=:=:=:=This code is executed for the character, that has passed the earlier tests, but '\%i', is not a legitimate printf format command...
:=:=:=:=:=:=
:=:=:=:=:=:=:=}
:=:=:=:=:=:=:=}
:=:=:=:=:=:=You are effectively 'testing twice', The second test is redundant, but unless the very first character matches your test, nothing else happens. Then the output is not what you expect, because the format string is invalid.
:=:=:=:=:=:=
:=:=:=:=:=:=Try this instead:
:=:=:=:=:=:=#include <16F877.h>
:=:=:=:=:=:=#fuses XT, NOWDT, NOPROTECT, PUT, BROWNOUT, NOLVP
:=:=:=:=:=:=#use Delay(clock=4000000)
:=:=:=:=:=:=#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7)
:=:=:=:=:=:=int a;
:=:=:=:=:=:=int nu;
:=:=:=:=:=:=main()
:=:=:=:=:=:={
:=:=:=:=:=:= nu = 2;
:=:=:=:=:=:= do {
:=:=:=:=:=:= a = getch();
:=:=:=:=:=:= if (a=='Y') {
:=:=:=:=:=:= printf("\%d",nu++);
:=:=:=:=:=:= }
:=:=:=:=:=:= } while (true);
:=:=:=:=:=:=}
:=:=:=:=:=:=This will send '2' in ASCII the first time a 'Y' is seen, and then '3' the next time, '4' the next etc., ignoring any other character.
:=:=:=:=:=:=
:=:=:=:=:=:=Best Wishes
:=:=:=:=:=
:=:=:=:=:=
:=:=:=:=:=Thanks for your help, its much appreciated.
:=:=:=:=:=I do have one more question, sometimes the program stops counting up and starts repeating the same number. Have you any ideas?
:=:=:=:=
:=:=:=:=#include <16F877.h>
:=:=:=:=#fuses XT, NOWDT, NOPROTECT, PUT, BROWNOUT, NOLVP
:=:=:=:=#use Delay(clock=4000000)
:=:=:=:=#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7)
:=:=:=:=int a;
:=:=:=:=int nu;
:=:=:=:=main()
:=:=:=:={
:=:=:=:= nu = 2;
:=:=:=:= do {
:=:=:=:= a = getch();
:=:=:=:= if (a=='Y'){
:=:=:=:= printf("\%d",nu++);
:=:=:=:= a = 0; // clear the TRUE if condition
:=:=:=:= }
:=:=:=:= } while (true);
:=:=:=:=}
:=:=:=:=
:=:=:=:=rgds,
:=:=:=:=Humberto
:=:=:=The clear here shouldn't be needed, since 'a' is set by the getch before the test...
:=:=:=Even if the true condition was still met, it wouldn't stop the increment.
:=:=:=Basically, if it sends back a character, it should do the increment. The exception would be (for instance), if the MCLR line was floating, and the chip was occasionally doing a hardware reset, when the counter would restart.
:=:=:=What number does it 'stop' on?. Is there a pattern?.
:=:=:=
:=:=:=Best Wishes
:=:=
:=:=Hello
:=:=Sorry I havent replied before, lack of time. There doesnt seen to be any pattern. It gets to a number then returns back to 2 and keeps repeating. eg. 2,3,4,5,6,2,2,2,2,2,2,
:=
:=So how is MCLR pulled up?.
:=It is behaving as if something is causing a reset. Normally, I'd think in terms of a watchdog, and suggest you double check that your programmer does disable the watchog (this is disabled in the code, but if your programmer is not importing the fuses properly, could still be enabled). However if this was the case, I'd expect it to count in 'waves', resetting every couple of seconds (assuming the largest divider on the watchdog).
:=So try this:
:=#include <16F877.h>
:=#fuses XT, NOWDT, NOPROTECT, PUT, BROWNOUT, NOLVP
:=#use Delay(clock=4000000)
:=#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7)
:=int a;
:=int nu;
:=main()
:={
:= nu = 2;
:= printf("RESET \%d\n",restart_cause());
:= do {
:= a = getch();
:= if (a=='Y') {
:= printf("\%d",nu++);
:= }
:= } while (true);
:=}
:=
:=Which will prove if the chip is resetting, and give a number saying what type of reset it is. Post this back, and it may be possible to work out what is happening.
:=
:=Best Wishes
Have tried the code you recommend and you where right the PIC is resetting the message returned is RESET 24. I have looked in the PIC C Compiler Reference Manual and function is listed but there are no details on the error codes. The configuration bit options when programming the PIC are set that the watchdog timer is off. The only configuration bits set as on are Power Up Timer and the Brown Out Detect.
Any idears
___________________________
This message was ported from CCS's old forum
Original Post ID: 13142 |
|
|
R.J.Hamlett Guest
|
Re: First time using a PIC, please advise. |
Posted: Thu Mar 27, 2003 10:52 am |
|
|
:=:=:=:=:=:=:=:=Hello, This is the first time I have ever used a micro-controller and I'm having a lot of silly problems. I’m trying to write a very simple program with no success. The program is to output a number over the RS232 line using the printf statement every time the PIC receives the character Y. I have written a program (Prog 1 below) to insure the hardware works OK and it does. But when I try the next program (Prog 2) nothing happens. I have tried using decimal, hex and the character Y in the while (a!=89); and it still doesn’t work. Could anyone help?
:=:=:=:=:=:=:=:=
:=:=:=:=:=:=:=:=Thanks
:=:=:=:=:=:=:=:=
:=:=:=:=:=:=:=:=
:=:=:=:=:=:=:=:=
:=:=:=:=:=:=:=:=//-----------------------------------------------
:=:=:=:=:=:=:=:=// Prog 1
:=:=:=:=:=:=:=:=#include <16F877.h>
:=:=:=:=:=:=:=:=#fuses XT, NOWDT, NOPROTECT, PUT, BROWNOUT, NOLVP
:=:=:=:=:=:=:=:=#use Delay(clock=4000000)
:=:=:=:=:=:=:=:=#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7)
:=:=:=:=:=:=:=:=main()
:=:=:=:=:=:=:=:={
:=:=:=:=:=:=:=:= while(TRUE)
:=:=:=:=:=:=:=:= {
:=:=:=:=:=:=:=:= putc(getc());
:=:=:=:=:=:=:=:= }
:=:=:=:=:=:=:=:=
:=:=:=:=:=:=:=:=}
:=:=:=:=:=:=:=:=
:=:=:=:=:=:=:=:=
:=:=:=:=:=:=:=:=//-----------------------------------------------
:=:=:=:=:=:=:=:=//Prog 2
:=:=:=:=:=:=:=:=#include <16F877.h>
:=:=:=:=:=:=:=:=#fuses XT, NOWDT, NOPROTECT, PUT, BROWNOUT, NOLVP
:=:=:=:=:=:=:=:=#use Delay(clock=4000000)
:=:=:=:=:=:=:=:=#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7)
:=:=:=:=:=:=:=:=int a;
:=:=:=:=:=:=:=:=int nu;
:=:=:=:=:=:=:=:=main()
:=:=:=:=:=:=:=:={
:=:=:=:=:=:=:=:=a = 0;
:=:=:=:=:=:=:=:=nu = 2;
:=:=:=:=:=:=:=:= do
:=:=:=:=:=:=:=:= {
:=:=:=:=:=:=:=:= a = getch();
:=:=:=:=:=:=:=Here the processor will wait for a character, and read it.
:=:=:=:=:=:=:=
:=:=:=:=:=:=:=:= } while (a!=89);
:=:=:=:=:=:=:=Here the processor will wait forever, if the character does not equal 89.
:=:=:=:=:=:=:=
:=:=:=:=:=:=:=:= if (a==89);
:=:=:=:=:=:=:=Now the statement ';' will be executed if a==89.
:=:=:=:=:=:=:=
:=:=:=:=:=:=:=:={
:=:=:=:=:=:=:=:=printf("\%i",nu);
:=:=:=:=:=:=:=This code is executed for the character, that has passed the earlier tests, but '\%i', is not a legitimate printf format command...
:=:=:=:=:=:=:=
:=:=:=:=:=:=:=:=}
:=:=:=:=:=:=:=:=}
:=:=:=:=:=:=:=You are effectively 'testing twice', The second test is redundant, but unless the very first character matches your test, nothing else happens. Then the output is not what you expect, because the format string is invalid.
:=:=:=:=:=:=:=
:=:=:=:=:=:=:=Try this instead:
:=:=:=:=:=:=:=#include <16F877.h>
:=:=:=:=:=:=:=#fuses XT, NOWDT, NOPROTECT, PUT, BROWNOUT, NOLVP
:=:=:=:=:=:=:=#use Delay(clock=4000000)
:=:=:=:=:=:=:=#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7)
:=:=:=:=:=:=:=int a;
:=:=:=:=:=:=:=int nu;
:=:=:=:=:=:=:=main()
:=:=:=:=:=:=:={
:=:=:=:=:=:=:= nu = 2;
:=:=:=:=:=:=:= do {
:=:=:=:=:=:=:= a = getch();
:=:=:=:=:=:=:= if (a=='Y') {
:=:=:=:=:=:=:= printf("\%d",nu++);
:=:=:=:=:=:=:= }
:=:=:=:=:=:=:= } while (true);
:=:=:=:=:=:=:=}
:=:=:=:=:=:=:=This will send '2' in ASCII the first time a 'Y' is seen, and then '3' the next time, '4' the next etc., ignoring any other character.
:=:=:=:=:=:=:=
:=:=:=:=:=:=:=Best Wishes
:=:=:=:=:=:=
:=:=:=:=:=:=
:=:=:=:=:=:=Thanks for your help, its much appreciated.
:=:=:=:=:=:=I do have one more question, sometimes the program stops counting up and starts repeating the same number. Have you any ideas?
:=:=:=:=:=
:=:=:=:=:=#include <16F877.h>
:=:=:=:=:=#fuses XT, NOWDT, NOPROTECT, PUT, BROWNOUT, NOLVP
:=:=:=:=:=#use Delay(clock=4000000)
:=:=:=:=:=#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7)
:=:=:=:=:=int a;
:=:=:=:=:=int nu;
:=:=:=:=:=main()
:=:=:=:=:={
:=:=:=:=:= nu = 2;
:=:=:=:=:= do {
:=:=:=:=:= a = getch();
:=:=:=:=:= if (a=='Y'){
:=:=:=:=:= printf("\%d",nu++);
:=:=:=:=:= a = 0; // clear the TRUE if condition
:=:=:=:=:= }
:=:=:=:=:= } while (true);
:=:=:=:=:=}
:=:=:=:=:=
:=:=:=:=:=rgds,
:=:=:=:=:=Humberto
:=:=:=:=The clear here shouldn't be needed, since 'a' is set by the getch before the test...
:=:=:=:=Even if the true condition was still met, it wouldn't stop the increment.
:=:=:=:=Basically, if it sends back a character, it should do the increment. The exception would be (for instance), if the MCLR line was floating, and the chip was occasionally doing a hardware reset, when the counter would restart.
:=:=:=:=What number does it 'stop' on?. Is there a pattern?.
:=:=:=:=
:=:=:=:=Best Wishes
:=:=:=
:=:=:=Hello
:=:=:=Sorry I havent replied before, lack of time. There doesnt seen to be any pattern. It gets to a number then returns back to 2 and keeps repeating. eg. 2,3,4,5,6,2,2,2,2,2,2,
:=:=
:=:=So how is MCLR pulled up?.
:=:=It is behaving as if something is causing a reset. Normally, I'd think in terms of a watchdog, and suggest you double check that your programmer does disable the watchog (this is disabled in the code, but if your programmer is not importing the fuses properly, could still be enabled). However if this was the case, I'd expect it to count in 'waves', resetting every couple of seconds (assuming the largest divider on the watchdog).
:=:=So try this:
:=:=#include <16F877.h>
:=:=#fuses XT, NOWDT, NOPROTECT, PUT, BROWNOUT, NOLVP
:=:=#use Delay(clock=4000000)
:=:=#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7)
:=:=int a;
:=:=int nu;
:=:=main()
:=:={
:=:= nu = 2;
:=:= printf("RESET \%d\n",restart_cause());
:=:= do {
:=:= a = getch();
:=:= if (a=='Y') {
:=:= printf("\%d",nu++);
:=:= }
:=:= } while (true);
:=:=}
:=:=
:=:=Which will prove if the chip is resetting, and give a number saying what type of reset it is. Post this back, and it may be possible to work out what is happening.
:=:=
:=:=Best Wishes
:=
:=
:=Have tried the code you recommend and you where right the PIC is resetting the message returned is RESET 24. I have looked in the PIC C Compiler Reference Manual and function is listed but there are no details on the error codes. The configuration bit options when programming the PIC are set that the watchdog timer is off. The only configuration bits set as on are Power Up Timer and the Brown Out Detect.
:=Any idears
The details of what the numbers mean, are in the include file for the chip.
The value '24', is a 'normal power up'. This implies it is not MCLR, or the watchdog causing the reset, but probably the power rail giving the problem. I don't think the CCS code at this point distinguishes between a reset, and a brownout (technically if is possible to do this, by checking the status of the POR bit). My guess is that your power rail is not 100\% stable, and the brownout circuit is being triggered. This requires the supply to drop below 4v for a moment. You might try a larger supply capacitor by the chip.
Best Wishes
___________________________
This message was ported from CCS's old forum
Original Post ID: 13145 |
|
|
R.J.Hamlett Guest
|
Re: First time using a PIC, please advise. |
Posted: Fri Mar 28, 2003 6:03 am |
|
|
:=:=:=:=:=:=:=:=:=Hello, This is the first time I have ever used a micro-controller and I'm having a lot of silly problems. I’m trying to write a very simple program with no success. The program is to output a number over the RS232 line using the printf statement every time the PIC receives the character Y. I have written a program (Prog 1 below) to insure the hardware works OK and it does. But when I try the next program (Prog 2) nothing happens. I have tried using decimal, hex and the character Y in the while (a!=89); and it still doesn’t work. Could anyone help?
:=:=:=:=:=:=:=:=:=
:=<snipped>
#include <16F877.h>
#fuses XT, NOWDT, NOPROTECT, PUT, BROWNOUT, NOLVP
#use Delay(clock=4000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7)
#bit TO=3.4
#bit PD=3.3
#byte STATUS=03
#bit POR=0x8E.1
#bit BOR=0x8E.0
int a;
int nu;
main()
{
if (POR==0) printf("Power on\n");
else {
if (BOR==0) printf("Brownout\n");
else {
switch ((status>>3) & 3) {
case 0 :
printf("WDT wake-up\n");
break;
case 1:
printf("WDT reset\n");
break;
case 2:
printf("MCLR from sleep, or INT from sleep\n");
break;
default:
printf("MCLR from running\n");
break;
}
}
}
//This allows MCLR from running to be detected
PD=TO=1;
nu = 2;
do {
a = getch();
if (a=='Y') {
printf("\%d",nu++);
}
} while (true);
}
Hi,
Taken the chance to redo the 'wake up' detector code, to printout exactly why the chip has restarted.
This should give a different message for each possible cause of a reset.
It gives a demo, of how you can use the chip to 'debug itself'!.
This pulls in the extra bits, that the CCS restart_cause function, doesn't use, and (since MCLR from normal running, leaves the PD and TO bits unchanged), I have set these to allow this fourth state to be distinguished as well.
It should point to what exactly is happening (I suspect your supply has some glitches).
Best Wishes
___________________________
This message was ported from CCS's old forum
Original Post ID: 13187 |
|
|
les Guest
|
Re: First time using a PIC, please advise. |
Posted: Fri Mar 28, 2003 7:54 am |
|
|
:=:=:=:=:=:=:=:=:=:=Hello, This is the first time I have ever used a micro-controller and I'm having a lot of silly problems. I’m trying to write a very simple program with no success. The program is to output a number over the RS232 line using the printf statement every time the PIC receives the character Y. I have written a program (Prog 1 below) to insure the hardware works OK and it does. But when I try the next program (Prog 2) nothing happens. I have tried using decimal, hex and the character Y in the while (a!=89); and it still doesn’t work. Could anyone help?
:=:=:=:=:=:=:=:=:=:=
:=:=<snipped>
:=
:=#include <16F877.h>
:=#fuses XT, NOWDT, NOPROTECT, PUT, BROWNOUT, NOLVP
:=#use Delay(clock=4000000)
:=#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7)
:=#bit TO=3.4
:=#bit PD=3.3
:=#byte STATUS=03
:=#bit POR=0x8E.1
:=#bit BOR=0x8E.0
:=
:=int a;
:=int nu;
:=main()
:={
:= if (POR==0) printf("Power on\n");
:= else {
:= if (BOR==0) printf("Brownout\n");
:= else {
:= switch ((status>>3) & 3) {
:= case 0 :
:= printf("WDT wake-up\n");
:= break;
:= case 1:
:= printf("WDT reset\n");
:= break;
:= case 2:
:= printf("MCLR from sleep, or INT from sleep\n");
:= break;
:= default:
:= printf("MCLR from running\n");
:= break;
:= }
:= }
:= }
:= //This allows MCLR from running to be detected
:= PD=TO=1;
:=
:= nu = 2;
:= do {
:= a = getch();
:= if (a=='Y') {
:= printf("\%d",nu++);
:= }
:= } while (true);
:=}
:=
:=Hi,
:=Taken the chance to redo the 'wake up' detector code, to printout exactly why the chip has restarted.
:=This should give a different message for each possible cause of a reset.
:=It gives a demo, of how you can use the chip to 'debug itself'!.
:=This pulls in the extra bits, that the CCS restart_cause function, doesn't use, and (since MCLR from normal running, leaves the PD and TO bits unchanged), I have set these to allow this fourth state to be distinguished as well.
:=
:=It should point to what exactly is happening (I suspect your supply has some glitches).
:=
:=Best Wishes
Hello again,
Thanks for taking so much time over the problem I am having, it is much appreciated. I have tried the code, and the error return was “power on”, I have also added a 100uF Cap across the power supply rail, tried another PSU and made sure the Vcc is at 5.00V. But still there is no improvement. I really don’t understand what is going wrong.
___________________________
This message was ported from CCS's old forum
Original Post ID: 13197 |
|
|
R.J.Hamlett Guest
|
Re: First time using a PIC, please advise. |
Posted: Fri Mar 28, 2003 9:13 am |
|
|
:=:=:=:=:=:=:=:=:=:=:=Hello, This is the first time I have ever used a micro-controller and I'm having a lot of silly problems. I’m trying to write a very simple program with no success. The program is to output a number over the RS232 line using the printf statement every time the PIC receives the character Y. I have written a program (Prog 1 below) to insure the hardware works OK and it does. But when I try the next program (Prog 2) nothing happens. I have tried using decimal, hex and the character Y in the while (a!=89); and it still doesn’t work. Could anyone help?
:=:=:=:=:=:=:=:=:=:=:=
:=:=:=<snipped>
:=:=
:=:=#include <16F877.h>
:=:=#fuses XT, NOWDT, NOPROTECT, PUT, BROWNOUT, NOLVP
:=:=#use Delay(clock=4000000)
:=:=#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7)
:=:=#bit TO=3.4
:=:=#bit PD=3.3
:=:=#byte STATUS=03
:=:=#bit POR=0x8E.1
:=:=#bit BOR=0x8E.0
:=:=
:=:=int a;
:=:=int nu;
:=:=main()
:=:={
:=:= if (POR==0) printf("Power on\n");
:=:= else {
:=:= if (BOR==0) printf("Brownout\n");
:=:= else {
:=:= switch ((status>>3) & 3) {
:=:= case 0 :
:=:= printf("WDT wake-up\n");
:=:= break;
:=:= case 1:
:=:= printf("WDT reset\n");
:=:= break;
:=:= case 2:
:=:= printf("MCLR from sleep, or INT from sleep\n");
:=:= break;
:=:= default:
:=:= printf("MCLR from running\n");
:=:= break;
:=:= }
:=:= }
:=:= }
:=:= //This allows MCLR from running to be detected
:=:= PD=TO=1;
:=:=
:=:= nu = 2;
:=:= do {
:=:= a = getch();
:=:= if (a=='Y') {
:=:= printf("\%d",nu++);
:=:= }
:=:= } while (true);
:=:=}
:=:=
:=:=Hi,
:=:=Taken the chance to redo the 'wake up' detector code, to printout exactly why the chip has restarted.
:=:=This should give a different message for each possible cause of a reset.
:=:=It gives a demo, of how you can use the chip to 'debug itself'!.
:=:=This pulls in the extra bits, that the CCS restart_cause function, doesn't use, and (since MCLR from normal running, leaves the PD and TO bits unchanged), I have set these to allow this fourth state to be distinguished as well.
:=:=
:=:=It should point to what exactly is happening (I suspect your supply has some glitches).
:=:=
:=:=Best Wishes
:=
:=Hello again,
:= Thanks for taking so much time over the problem I am having, it is much appreciated. I have tried the code, and the error return was “power on”, I have also added a 100uF Cap across the power supply rail, tried another PSU and made sure the Vcc is at 5.00V. But still there is no improvement. I really don’t understand what is going wrong.
So you are seeing 'Power on', followed by a numeric sequence, and then getting Power on again, then the '2' repeated?.
Ouch.
Scratch head, and start thinking.
At this point, I'd be trying a second chip if you have one, and also working round with an ohmeter, and very carefully checking that there is no possibility of a dry joint between any of the power connections (including the grounds), and the actual chip pins. If I have got the code right (no guarantees, but it agrees with the value being returned by the CCS routine as well), the chip is behaving exactly as if it has lost power....
Best Wishes
___________________________
This message was ported from CCS's old forum
Original Post ID: 13202 |
|
|
|
|
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
|