|
|
View previous topic :: View next topic |
Author |
Message |
hadeelqasaimeh
Joined: 05 Jan 2006 Posts: 105
|
18f458 and string |
Posted: Mon Oct 16, 2006 12:35 am |
|
|
hello all;
im working on 16f877,,i try to send and Receive serial string.
then do some function and print on lcd.and its work fine;
i try now to do same but using 18f458,,but it dont work
here is my Receiver code:
Code: |
#include <18F458.h>
#fuses HS,NOWDT,NOPROTECT,NOLVP
#use delay(clock=20000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7)
#include <lcd.c>
#int_rda
void serial_isr()
{
jj=1;
delay_ms(100);
}
void main() {
lcd_init();
enable_interrupts(INT_RDA);// turn on interrupts
enable_interrupts(GLOBAL);
jj=0;
output_low(PIN_A0);
lcd_putc('\f');
while(TRUE)
{
output_low(PIN_A0);
lcd_gotoxy( 1, 1);
printf(lcd_putc(" WAIT"));
delay_ms(1000);
if(jj==1)
{
output_high(PIN_A0);
delay_ms(500);
output_low(PIN_A0);
lcd_putc('\f');
lcd_gotoxy( 1, 1);
printf(lcd_putc(" interrupt"));
delay_ms(1000);
jj=0;
}
}
} |
my transmitter code is simpley "printf" and delay time
any body can help,plz |
|
|
Ttelmah Guest
|
|
Posted: Mon Oct 16, 2006 2:46 am |
|
|
First thing, your 'receive' code, is going to physically hang the UART. You are not reading the received character, and you are then delaying. Result, the UART internal buffer _will_ overflow, and the UART will then be physically hung.
Change the code in the following ways:
Code: |
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7,ERRORS)
//This makes the compiler add code to _recover_ from the hung state...
char received;
#int_rda
void serial_isr()
{
jj=1;
//delay_ms(100);
//Do _not_ delay in an interrupt. There are occassions, where _short_
//delays, may be used, but delays inside interrupts, should be treated
//as if they bought the 'black death' with them...
received=getc();
//You need to read the character, or the interrupt will keep recurring.
}
|
With these changes, it should start to work, and you can then solve the rest yourself.
Best Wishes |
|
|
|
|
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
|