View previous topic :: View next topic |
Author |
Message |
Guest
|
Comunication problem PC - PIC18F4550 |
Posted: Sun Feb 01, 2009 5:42 pm |
|
|
Hello, I have problems with this code:
Code: |
#include <18f4550.h>
#fuses HSPLL,NOWDT,NOPROTECT,NOLVP,NODEBUG,USBDIV,PLL3,CPUDIV1,VREGEN,NOPBADEN //Ordenes para el programador
#use delay(clock=12000000) //fosc= 12 Mhz
#use standard_io(b)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7, ERRORS)
char boton=' ';
#int_rda
void serial_isr() {
boton=0x00;
if(kbhit()){
boton=getc();
if(boton=='1'){ //this does not work
output_toggle(PIN_B0);
}
if(boton=='2'){ //this does not work
output_toggle(PIN_B1);
}
if(boton=='3'){ //this does not work
output_toggle(PIN_B2);
}
if(boton=='4'){ //this does not work
output_toggle(PIN_b3);
}
if(boton=='5'){ //this does not work
output_toggle(pin_b4);
}
if(boton=='6'){ //this does not work
output_toggle(pin_b5);
}
if(boton=='7'){ //this does not work
output_toggle(pin_b6);
}
output_toggle(PIN_b7); // if this works
putc(boton);
}
}
void main() {
setup_adc_ports(NO_ANALOGS);
setup_adc(ADC_OFF);
setup_spi(FALSE);
setup_psp(PSP_DISABLED);
setup_counters(RTCC_INTERNAL,RTCC_DIV_2);
setup_timer_0(RTCC_OFF);
setup_timer_1(T1_INTERNAL | T1_DIV_BY_1);
setup_timer_2(T2_DISABLED,0,1);
setup_timer_3(T3_DISABLED);
setup_comparator(NC_NC_NC_NC);
setup_vref(FALSE);
port_b_pullups(FALSE);
set_tris_c(0b10000000);
set_tris_b(0b00000000);
output_c(0b00000000);
output_b(0b00000000);
enable_interrupts(global);
enable_interrupts(int_rda);
//lcd_init();
delay_ms(1000);
do {
if(boton!=0x00)
{
;
}
} while (TRUE);
}
|
Why this does not work? |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Sun Feb 01, 2009 6:52 pm |
|
|
What is your crystal frequency ? Read the frequency on the crystal
and post it. |
|
|
mcu
Joined: 01 Feb 2009 Posts: 2
|
|
Posted: Sun Feb 01, 2009 8:30 pm |
|
|
Hi,I am the above message, thanks for your help.
The crystal frequency is 12 Mhz.
#use delay(clock=12000000) //fosc= 12 Mhz
Is there something in the code is wrong? |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Sun Feb 01, 2009 9:00 pm |
|
|
Based on your #fuses statement, the oscillator in the 18F4550 is really
running at 48 MHz. Change your #use delay() statement to this:
Code: | #use delay(clock=48000000) |
|
|
|
mcu
Joined: 01 Feb 2009 Posts: 2
|
|
Posted: Mon Feb 02, 2009 8:16 am |
|
|
Hi, now works fine. I am very happy.
Thank you very much for your help. |
|
|
|