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

kbhit() does not hit at all

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







kbhit() does not hit at all
PostPosted: Mon Nov 24, 2008 11:29 am     Reply with quote

Hi Forum,

I am trying to catch an user input over RS232 with kbhit().

Down below you can see the whole program.
My problem is, that kbhit() does not hit any time and so the if-statement (marked with ***** 1 *****) is never executed.
I tryed several work-arounds and I also viewed the RS232-Input by putting out every char with putc().
Everything works fine, but no kbhit() will occour at all.

Please give me some help

Dirk


(Excuse, that the Code has no tabs, I didn't know how to get the code out of CCSC with tabs)


Code:
#opt 0
#include <18F252.h>
#fuses HS,WDT,WDT128,PUT,BROWNOUT,BORV45,PROTECT,NOLVP

#FUSES NOWRT                    //Program memory not write protected
#FUSES NOWRTD                   //Data EEPROM not write protected
#FUSES WRTB                     //Boot block write protected
#FUSES NOWRTC                   //configuration not registers write protected
#FUSES NOCPD                    //No EE protection
#FUSES CPB                      //Boot Block Code Protected

#use delay(clock = 40M, oscillator = 10M, restart_wdt)
#use rs232(baud=57600, xmit=PIN_C6, rcv=PIN_C7,restart_wdt)                                   //

#define _bootloader

#include <bootloader.h>
#include <loader.c>
#rom 0xf000ff={255}                                                               // Flag for bootloader start

#org LOADER_END+2,LOADER_END+20
void application(void) {
  while(TRUE);
}


#org 0x20,0xFF
void main(void) {   
byte eeprom_value, i;
   eeprom_value =  read_eeprom(0xf000ff);               
   if(eeprom_value>=127){                                                        // 255: programming default value               
      load_program();                                                             // 127: value after successful bootloader Menue                 
      write_eeprom(0xf000ff,0);   
   }
   else {
      for (i=0;i<250;i++) {                                                       // test 250 times, if an event occurs on RS232                                                                                   
         if (kbhit()){         // ****** 1*****
            if(getc() == 0x1B) {                                                   // this case will hit, if [ESC] is pressed and hold during power on
               load_program();                                                 // start bootloader from RS232               
               write_eeprom(0xf000ff,0); 
               break;
            }
         
         }
      }
      
   }
   application();
}

#ORG default

#int_global
void isr(void) {
   jump_to_isr(LOADER_END +10);
}
ECACE



Joined: 24 Jul 2006
Posts: 94

View user's profile Send private message

PostPosted: Mon Nov 24, 2008 12:36 pm     Reply with quote

For starters, strip out all the bootloader stuff. Start with just the code that is giving you the problem and get it to work before adding the loader.
Second, what version of the compiler are you using?

With that information given, we can help out. As it stands now, are you sure it isn't a loader problem or your values in the eeprom? Let's narrow it down first, so get rid of everything but the kbhit problem.

Best of luck.
_________________
A HW Engineer 'trying' to do SW !!! Run!!!
ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

PostPosted: Mon Nov 24, 2008 1:40 pm     Reply with quote

Code:
#use delay(clock = 40M, oscillator = 10M, restart_wdt)
From this line it looks like you are using a 10MHz crystal + 4xPLL to reach 40MHz.
The above setup might work on some of the newer chips with software controllable clock configuration but not on the good old 18F252 where you have to enable the PLL by setting a fuse. Change the HS fuse to H4 (HS + 4xPLL).


Code:
write_eeprom(0xf000ff,0);
The address value is too large. The write_eeprom 'knows' the base address so you only have to specify the actual offset (0xFF).

Like ECACE suggested, bug hunting is easier when you simplify your program by removing all not required stuff.
Guest








PostPosted: Mon Nov 24, 2008 5:28 pm     Reply with quote

Hi ECACE and ckielstra,

Thanks for your help first.

I did not know the things you wrote about oscillator settings and eeprom-address range. At first I changed the settings, but that was not the solution for my bug.
Then I simplified the program and installed an Answer over RS232 every time the pic gets the kbhit(). The Answer('A') did not come.
(I tested this also before my first post). Then I throw away the loader.c-file and my bug was fixed. What is there going on in the loader.c-file, that collides with my program?

Here is the actual Code

Thanks for more Help.

Dirk

Code:
#opt 0
#include <18F252.h>
#fuses H4,WDT,WDT128,PUT,BROWNOUT,BORV45,PROTECT,NOLVP

#FUSES NOWRT                    //Program memory not write protected
#FUSES NOWRTD                   //Data EEPROM not write protected
#FUSES WRTB                     //Boot block write protected
#FUSES NOWRTC                   //configuration not registers write protected
#FUSES NOCPD                    //No EE protection
#FUSES CPB                      //Boot Block Code Protected

#use delay(clock = 40M, oscillator = 10M, restart_wdt)
#use rs232(baud=57600, xmit=PIN_C6, rcv=PIN_C7,restart_wdt)                                   //

#define _bootloader

#include <bootloader.h>
//#include <loader.c>      //***** if I uncomment this line kbhit() does not work any more
#rom 0xf000ff={255}                                                               // Flag for bootloader start

#org LOADER_END+2,LOADER_END+20
void application(void) {
  while(TRUE);
}


#org 0x20,0xFF
void main(void) {   
byte eeprom_value, i;
   eeprom_value =  read_eeprom(0xff);               
   //if(eeprom_value>=127){                                                        // 255: programming default value               
      //load_program();                                                             // 127: value after successful bootloader Menue                 
   //   write_eeprom(0xff,0);   
   //}
   //else {
      for (i=0;i<250;i++) {                                                       // test 250 times, if an event occurs on RS232                                                                                   
         if (kbhit()){
            if(getc() == 0x1B) {                                                   // this case will hit, if [ESC] is pressed and hold during power on
               //load_program();                                                 // start bootloader from RS232               
               //write_eeprom(0xff,255); 
               //break;
               putc('A');
            }
         }
         i--;
      }
      
   //}
   //application();
}

#ORG default

#int_global
void isr(void) {
   jump_to_isr(LOADER_END +10);
}
ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

PostPosted: Wed Nov 26, 2008 5:29 pm     Reply with quote

There are no big differences between your bootloader and the ex_bootloader.c program so at a quick glance I don't see what is causing your problems.

One suggestion is to add the 'errors' keyword to the '#use rs232' line. The hardware UART will stop receiving when the input buffer overflows, that is after 3 characters, and only starts receiving again after explicit error reset. Adding the errors keyword causes the compiler to add code for resetting the error condition on every getc call.

For further looking into your problem you need to post your compiler's version number.
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