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 support@ccsinfo.com

Comunication problem PC - PIC18F4550

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








Comunication problem PC - PIC18F4550
PostPosted: Sun Feb 01, 2009 5:42 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Sun Feb 01, 2009 6:52 pm     Reply with quote

What is your crystal frequency ? Read the frequency on the crystal
and post it.
mcu



Joined: 01 Feb 2009
Posts: 2

View user's profile Send private message

PostPosted: Sun Feb 01, 2009 8:30 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Sun Feb 01, 2009 9:00 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Mon Feb 02, 2009 8:16 am     Reply with quote

Hi, now works fine. I am very happy. Very Happy
Thank you very much for your help.
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