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 CCS Technical Support

What's wrong with my code?

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
June
Guest







What's wrong with my code?
PostPosted: Wed Nov 20, 2002 9:38 pm     Reply with quote

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

View user's profile Send private message Send e-mail

Re: What's wrong with my code?
PostPosted: Thu Nov 21, 2002 12:56 am     Reply with quote

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?
PostPosted: Thu Nov 21, 2002 2:40 am     Reply with quote

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

View user's profile Send private message Send e-mail

Re: What's wrong with my code?
PostPosted: Thu Nov 21, 2002 6:53 am     Reply with quote

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
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
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