![](templates/subSilver/images/CCSLogo.jpg) |
![CCS C Software and Maintenance Offers](templates/subSilver/images/forumAd6.jpg) |
View previous topic :: View next topic |
Author |
Message |
Labiran, Simeon Olusola Guest
|
request for help |
Posted: Fri Jul 29, 2005 9:31 am |
|
|
Hi,
can someone help me out to find solution to this my programme.
the last programme transmit the data correctly but unable to receive . i decide to include" input.c" command to enable reception of input data. the programme is as follow:
#include <18F452.h>
#include <stdio.h>
#fuses HS,NOWDT,NOPROTECT,NOLVP
#use fixed_io(C_outputs=pin_C6)
#use delay(clock=4000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7) // Jumpers: 8 to 11, 7 to 12
//#include <loader.c>
#define INTS_PER_SECOND 25 // (4000000/(4*16*250*10)
// set up timer
set_timer_2(T2_DIV_BY_16,250,10);
int8 seconds; //A running seconds counter
int8 int_count; // Numbering of interrupts left before a second has elapsed
#INT_TIMER2 // This function is called every time
void clock_isr(){ // Timer2 overflows (250 to 0) which is approaximately 25 times per second for this program
if(--int_count==0){
++seconds;
int_count=INTS_PER_SECOND;
}
}
#include<input.c>
#define KEYHIT_DELAY 500 // IN MILLISECONDS
char timed_getc(){
long timeout;
timeout_error=FALSE;
timeout=0;
while(!kbhit&&(++timeout<50000)) // 1/2 second
delay_us(10);
if(kbhit)
return(getc());
else{
timeout_error=TRUE;
return(0);
}
}
void main(void)
{
int time;
unsigned int second;
unsigned int control; // 0=250
int_count=INTS_PER_SECOND;
//set_timer_2(T2_DIV_BY_16,250,10);
set_timer2(0);
enable_interrupts(INT_TIMER2);
enable_interrupts(global);
while (TRUE)
{
printf("press any key to begin.\n\r");
getc();
int_count=INTS_PER_SECOND;
seconds=int_count;
printf("press any key to stop.\n\r");
getc();
printf("%u seconds.\n\r", seconds);
}
}
// clears out the rs232 buffer
delay_us(10);
while(kbhit())
{
getc();
}
// loop until "L" is pressed
do
{
printf("\r\nSoftware Version A!\r\n");
printf("press L to download new software.\r\n");
}
while(getc())!='L');
// let the user know it is ready to accept a download
printf("\r\nWaiting for download...");
//Load the program
Load_program();
}
/*
for (time = 0; time < 10; time++){
delay_us(10);
second = read_set_up_timer();
printf("numb=%u,second;
printf("time=%u",time);
getc(0);
getc(10);
*/
please, i need your advice on what to do. |
|
![](templates/subSilver/images/spacer.gif) |
ckielstra
Joined: 18 Mar 2004 Posts: 3680 Location: The Netherlands
|
|
Posted: Sat Jul 30, 2005 5:56 am |
|
|
I haven't checked all of your code as it is hard to read in the current format. Please, when posting code use the code button at the start and end of your code part. This will help to remain the formatting.
Code: |
// set up timer
set_timer_2(T2_DIV_BY_16,250,10); |
This line in the start of the program is causing you several problems:
1) The line is not inside a function, so it will not be executed and the timer will not be setup the way you expect it to.
2) The compiler sees this as a new function declaration, hence no error message.
3) You intended to call setup_timer_2() but misspelled the name wrong.
Solution:
- Remove this line
- Re-enable the same line in your main() again
- Rename set_timer_2() to setup_timer_2() |
|
![](templates/subSilver/images/spacer.gif) |
ckielstra
Joined: 18 Mar 2004 Posts: 3680 Location: The Netherlands
|
|
Posted: Sat Jul 30, 2005 6:42 am |
|
|
I tried to compile your program, but I gave up. There are just too many errors. Please give us a short compilable program. I know this will be some work for you, but now you are expecting to this job for you. The easier you make it for us, the more, better and quicker responses you will get.
Some of the errors I found:
- You are testing kbhit two times. Now this gives my compiler an error message as unknown variable, very likely you meant to call the function kbhit() ??
- The declaration for the variable timeout_error is missing.
- The function timed_getc() is defined but never used.
- There is a '}' too many in you main, causing an early ending to main().
- the line Code: | while(getc())!='L'); | has a ')' too many.
- In your question you are referring to the use of <input.c>, but you are using none of the functions from that file.
- And several more errors.... sigh...
For not receiving data, I'm not sure. You might try to remove the line Code: | #use fixed_io(C_outputs=pin_C6) | I never use fixed_io as it hard-codes the direction register with every I/O operation, I like fast_io better because it programs the direction register only once resulting in a shorter program. For the serial port you don't need either of those instructions, the UART will configure the direction flags automatically. |
|
![](templates/subSilver/images/spacer.gif) |
Olusola Labiran Guest
|
Serial Communication to PC through PIC18F452 and RS232 |
Posted: Sat Aug 06, 2005 3:23 am |
|
|
Hi cKielstra,
All what i want to do is to progam my uC 18F452 to transmit frequency data generated from external Xtal (40MHz) to PC, receive and compare this information (data) through RS232.
I used putc, getc and use of 'RS232' examples in the C compiler and the tutorial manual which i received.
I need someone to help me. I am novice in this C language.
Thank you |
|
![](templates/subSilver/images/spacer.gif) |
Labiran, Simeon Olusola Guest
|
serial Communication to PC through PIC18F452 and RS232 |
Posted: Sat Aug 06, 2005 3:26 am |
|
|
Hi cKielstra,
All what i want to do is to progam my uC 18F452 to transmit frequency data generated from external Xtal (40MHz) to PC, receive and compare this information (data) through RS232.
I used putc, getc and use of 'RS232' examples in the C compiler and the tutorial manual which i received.
I need someone to help me. I am novice in this C language.
Thank you |
|
![](templates/subSilver/images/spacer.gif) |
Mark
Joined: 07 Sep 2003 Posts: 2838 Location: Atlanta, GA
|
|
Posted: Sat Aug 06, 2005 8:08 am |
|
|
You've got someone willing to help you. But for that help, they requested that you do something so that they may help you. I'd suggest that you do what they ask and maybe you'll get the help. Also register so that you can edit your posts and post your code with the code button. |
|
![](templates/subSilver/images/spacer.gif) |
Labiran S.O Guest
|
Serial Communication |
Posted: Sat Aug 13, 2005 3:26 am |
|
|
Hi Mark,
I registered my profile with CCS User's forum. Is there any other registration i have to do to post my codes? If there is any, please let me know. |
|
![](templates/subSilver/images/spacer.gif) |
Mark
Joined: 07 Sep 2003 Posts: 2838 Location: Atlanta, GA
|
|
Posted: Sat Aug 13, 2005 7:32 am |
|
|
You have to log in. After you do, then anything you post you can edit. |
|
![](templates/subSilver/images/spacer.gif) |
|
|
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
|