|
|
View previous topic :: View next topic |
Author |
Message |
June Guest
|
What's wrong with my code? |
Posted: Wed Nov 20, 2002 9:38 pm |
|
|
Dear all,
The following codes is a PIC RS232 transmitter program. Every output will be delivered to another PIC and its own port B for display.
However the output of the program keep blinking after display from 0-15. What's wrong with my program? Please do me a favour. I need your help.
//program to transmit data
#include <16F876.h>
#use delay(clock=20000000)
#fuses hs,noprotect,nowdt,nolvp
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7)
#byte PORTA=5
#byte PORTB=6
#byte PORTC=7
main()
{
int i;
set_tris_b(0); //set pin b0-b7 as output
delay_ms(1000);
do
{
for(i=0; i<16; i++)
{
putc(i);
portb=i;
delay_ms(2000);
}
}while(1);
}
Regards: June,
___________________________
This message was ported from CCS's old forum
Original Post ID: 9195 |
|
|
Mark
Joined: 07 Sep 2003 Posts: 2838 Location: Atlanta, GA
|
Re: What's wrong with my code? |
Posted: Thu Nov 21, 2002 12:56 am |
|
|
That is because your for loop is inside your do...while(1) so it will repeat over and over. The program below should only do 0-15 as you want
:=Dear all,
:=
:= The following codes is a PIC RS232 transmitter program. Every output will be delivered to another PIC and its own port B for display.
:=
:= However the output of the program keep blinking after display from 0-15. What's wrong with my program? Please do me a favour. I need your help.
:=
:=//program to transmit data
:=#include <16F876.h>
:=#use delay(clock=20000000)
:=#fuses hs,noprotect,nowdt,nolvp
:=#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7)
:=#byte PORTA=5
:=#byte PORTB=6
:=#byte PORTC=7
:=
:=main()
:={
:=int i;
:=
:=set_tris_b(0); //set pin b0-b7 as output
:=delay_ms(1000);
:=
for(i=0; i<16; i++)
{
putc(i);
portb=i;
delay_ms(2000);
}
while(1);
:=
:=}
:=
:=
:=Regards: June,
___________________________
This message was ported from CCS's old forum
Original Post ID: 9201 |
|
|
June Guest
|
Re: What's wrong with my code? |
Posted: Thu Nov 21, 2002 2:40 am |
|
|
Thanks for your reply, I appreciate it much.
However if I want to design a program that can execute the following pattern:
1. Blink 0xFF for 1 times
2. Display 0-15
3. Blink 0xAA for 1 times
4. Go back to run step 1.
In this case can I write like following?
do
{
portb=0xff;
delay_ms(1000);
portb=0;
delay_ms(1000);
for(i=0; i<16; i++)
{
portb=i;
delay_ms(1000);
}
portb=0xaa;
delay_ms(1000);
portb=0;
delay_ms(1000);
}while(1);
___________________________
This message was ported from CCS's old forum
Original Post ID: 9202 |
|
|
Mark
Joined: 07 Sep 2003 Posts: 2838 Location: Atlanta, GA
|
Re: What's wrong with my code? |
Posted: Thu Nov 21, 2002 6:53 am |
|
|
Yes, that is correct.
Regards,
mark
:=
:=Thanks for your reply, I appreciate it much.
:=
:=However if I want to design a program that can execute the following pattern:
:=1. Blink 0xFF for 1 times
:=2. Display 0-15
:=3. Blink 0xAA for 1 times
:=4. Go back to run step 1.
:=
:=In this case can I write like following?
:=
:=do
:={
:=
:=portb=0xff;
:=delay_ms(1000);
:=portb=0;
:=delay_ms(1000);
:=
:=for(i=0; i<16; i++)
:={
:= portb=i;
:= delay_ms(1000);
:=}
:=
:=portb=0xaa;
:=delay_ms(1000);
:=portb=0;
:=delay_ms(1000);
:=
:=}while(1);
:=
:=
:=
___________________________
This message was ported from CCS's old forum
Original Post ID: 9209 |
|
|
|
|
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
|