|
|
View previous topic :: View next topic |
Author |
Message |
Bart
Joined: 12 Jul 2005 Posts: 49
|
Working on 16F877, not on 18F4550. Why ? |
Posted: Tue Oct 11, 2005 2:55 pm |
|
|
Hello,
Can't find why the below code won't work on me 18F. It worked fine on a 16F877.
I made some changes in my hardware (and also my code) between 16F and 18F :
* use of INT2 i.p.o. INT
* RS232 on other pins (but it is working fine, I get the version info in the Hyperterminal)
* other LCD driver (but it is working fine, I get the version info on the LCD)
It seems that I don't get the char's with the fgetc(GPS). But the char's seems to be there (on the pin) becase I receive interrupts (checked by printing - - - - - in the Hyperterminal via the fprintf(MODEM," - %S",c)
Someone an idee ?
Thanks.
Code: |
// VERSION : 0.1.03
// * blinking blue led
// * RS232 (E0 E1) : GPS stream to PC
// * RS232 (B2 B3) : GPS stream to PIC
// * LCD 4x20 : version displaying on LCD
#include <18F4550.h>
#fuses HS,NOWDT,NOPUT,NOLVP,NOBROWNOUT,NOCPD,NOWRT
#use delay(clock=20000000)
#use rs232(baud=9600, xmit=PIN_E1, rcv=PIN_E0, stream=MODEM)
#use rs232(baud=4800, xmit=PIN_B1, rcv=PIN_B0, stream=GPS)
#include <LCD4x20D.C>
#define GPS_BUFFER_SIZE 70
static char GPS_buffer[GPS_BUFFER_SIZE];
static char GPS_code[] = "$GPRMC";
static char* GPS_p = GPS_buffer;
static int GPS_state = 0;
static short GPS_done = TRUE;
static short GPS_found = FALSE;
#int_ext2
void GPS_isr()
{
char c;
c = fgetc(GPS);
fprintf(MODEM," - %S",c);
if( GPS_found == FALSE )
{
GPS_found = TRUE;
}
if( GPS_state < 6 )
{
if( c == GPS_code[GPS_state] )
{
if( GPS_state == 0 )
{
GPS_p = GPS_buffer;
}
*GPS_p = c;
GPS_p++;
GPS_state++;
}
else
{
GPS_state = 0;
}
}
else
{
if( c == 0x0d ) // carriage return
{
*GPS_p = 0;
GPS_done = TRUE;
disable_interrupts(INT_EXT2);
}
else
{
*GPS_p = c;
GPS_p++;
GPS_state++;
}
}
}
void main()
{
setup_adc_ports(NO_ANALOGS|VSS_VDD);
setup_adc(ADC_OFF);
setup_psp(PSP_DISABLED);
setup_spi(FALSE);
setup_wdt(WDT_OFF);
setup_timer_0(RTCC_INTERNAL);
setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DISABLED,0,1);
setup_timer_3(T3_DISABLED|T3_DIV_BY_1);
setup_comparator(NC_NC_NC_NC);
setup_vref(VREF_LOW|-2);
setup_low_volt_detect(FALSE);
setup_oscillator(False);
// Version output to RS232 PC Hyperterminal (stream MODEM)
fprintf(MODEM,"\033[2J"); // clear screen
fprintf(MODEM," PIC Online\n\r");
fprintf(MODEM," Version : 0.1.03\n\r");
fprintf(MODEM," Copyright 2005 Bart De Pauw\n\r");
fprintf(MODEM," For PIC 18F4550\n\r");
fprintf(MODEM," GPS stream to PC\n\r");
// Version output to LCD
lcd_init();
lcd_putc("\f**** PIC Online ****\n");
lcd_putc("Copyright 2005 \n");
lcd_putc("V0.1.03 Bart De Pauw\n");
lcd_putc("* GPS stream to PC *\n");
// 12345678901234567890 (Help for alligning messages on LCD)
// GPS tx is connected to pin RB2 (pin 35) so INT2
ext_int_edge(2,H_TO_L);
enable_interrupts(INT_EXT2);
enable_interrupts(GLOBAL);
while (TRUE)
{
if( GPS_found && GPS_done )
{
fputs(GPS_buffer,MODEM);
GPS_state = 0;
GPS_done = FALSE;
output_HIGH(PIN_A0);
delay_ms(100);
output_LOW(PIN_A0);
enable_interrupts(INT_EXT2);
}
}
}
|
_________________ I like Skype (www.skype.com), my username is BplotM |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Tue Oct 11, 2005 7:24 pm |
|
|
Quote: | VERSION : 0.1.03
// * blinking blue led
// * RS232 (E0 E1) : GPS stream to PC
// * RS232 (B2 B3) : GPS stream to PIC
// * LCD 4x20 : version displaying on LCD
#use rs232(baud=4800, xmit=PIN_B1, rcv=PIN_B0, stream=GPS) |
The pins in the comments don't match the #use rs232() statement.
Is the GPS connected to pins B2 and B3, or pins B1 and B0 ?
If that's not the problem, then post your compiler version. |
|
|
|
|
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
|