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

RS232 doesn�t seem to work?! HELP!!

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







RS232 doesn�t seem to work?! HELP!!
PostPosted: Mon May 10, 2004 3:47 am     Reply with quote

Hi!

I have been coding a code that is transmitting some numbers through RS232, at some random times,

Well, it doesnt� seem to work

will anyone please say if the code should work?!?! (then at least I may lay the code behind my troubleshooting.

CODE:

Quote:

#include <16f870.h>
#include <stdlib.h>
#include <stdio.h>
/* Config f�r PIC-processor*/
#fuses XT, NOPROTECT, NOWDT, HS
#use delay (clock=4000000)
#use rs232(baud=19200,parity=N,xmit=PIN_C6,rcv=PIN_C7) // Jumpers: 8 to 11, 7 to 12
//#define RAND_MAX 60

void Config(void);
void Bevakning(void);
void tick(void);
void Clockwise(void);
void Counter_Clockwise(void);

int time_to_send=30;
int phase=8, step_pos=0;
unsigned int desired_step_pos=0;

/**************************************************/
/* Funktionen main() */
/* Funktionen startar Config() och Start() */
/* funktionerna samt �ven en o�ndlig whileloop */
/* som startar funktionen knappar() som k�nner */
/* av knapptryck */
/**************************************************/
void main(void)
{
Config();
while(1)
{
Tick();
}
}

/*****************************************************/
/* L�GG ALLT SOM SKA STARTAS ENDAST EN G�NG H�R!!!*/
/*****************************************************/

void Config(void)
{
setup_adc_ports(RA0_RA1_RA3_ANALOG);
setup_adc(ADC_CLOCK_INTERNAL);
set_adc_channel(0);
setup_spi(FALSE);
setup_psp(PSP_DISABLED);
setup_counters(RTCC_INTERNAL,RTCC_DIV_2);
setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DIV_BY_4,0xc0,2);
setup_ccp1(CCP_OFF);
enable_interrupts(INT_RDA);
enable_interrupts(INT_TIMER2);
enable_interrupts(global);
srand(1);
OUTPUT_HIGH(PIN_C4);
}

/***********************************************************/
/* H�LLER KOLL P� OM DET FINNS STR�M ELLER INTE */
/***********************************************************/

#INT_TIMER2 //timer function, random times
void tick(void)
{

static int8 tick=100;
static int8 time=10;
if (tick != 0)
--tick;
else
{
tick=100;
--time;
time_to_send=rand();
if (time_to_send == time)
Bevakning();
// else
// --time_to_send;
}
time=10;
}

void Bevakning(void) //sending function
{
int16 ad=12;
int16 id=5;
int16 random;
float check=0;
float test;
//ad=read_adc(); //time_to_send =0
check=(float)((id+ad)/2);
//test=(2*(check-id));

printf("%ld:%ld:%2.2f",id, ad, check);
ad=0;
check=0;
}


/************************************************/
/* Tar emot ett v�rde */
/************************************************/

#INT_RDA
void ta_emot(void)
{
int16 c;
int16 d;
int8 id=5;

if(kbhit())
{
c=getc();
if(c==id)
{
d=getc();
desired_step_pos=d;
if (desired_step_pos>step_pos)
{
Clockwise(); //not done yet
}
if (desired_step_pos < step_pos)
{
Counter_Clockwise(); //not done yet
}

}
}
}

Woody



Joined: 11 Sep 2003
Posts: 83
Location: Warmenhuizen - NL

View user's profile Send private message

PostPosted: Mon May 10, 2004 4:36 am     Reply with quote

Hi,

I am not completely sure what your program is meant to do but looking at it there are a couple of things that I would check:

- XT _and_ HS in the #fuses setting?
- In tick() tick and time are initialized to 100 and 10 every iteration. They never get to 0 and Bevakning() is never executed.
- tick() is executed every timer2 interrupt and also every pass through main?

Paul
ckielstra



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

View user's profile Send private message

PostPosted: Mon May 10, 2004 4:48 am     Reply with quote

Can you be a little more specific? What is not working? In your headline you say the RS-232 is not working, but how would you confirm that? I mean, your rs-232 receive interrupt is doing nothing, so how can you say it is not working???

I don't know for the CCS compiler, but what value range is Rand() returning? You compare this return value to time (allways 9), I guess this will never be true so Bevakning() is nver called.
CyberTron
Guest







PostPosted: Mon May 10, 2004 5:30 am     Reply with quote

The program should only be able to send a byte to the computer,

(the recieve part of the program is just *for fun*)
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