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 CCS Technical Support

Is it software? is it hardware? is it startup power issue?

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







Is it software? is it hardware? is it startup power issue?
PostPosted: Mon May 05, 2008 1:17 pm     Reply with quote

Hey all,

I'm using an 18F4525 that is supposed to interact with a Hexadecimal rotary switch. On the switch there are 4 set locations for 4 different devices that my code can work with with slight differences for each device. What I want to do is, upon startup, read in the HEX switch from port C (temp) and set the device_type.

Code:

   setup_adc_ports(NO_ANALOGS);
   setup_adc(ADC_OFF);
   setup_psp(PSP_DISABLED);
   setup_spi(FALSE);
   //****5MHz
   setup_timer_0(RTCC_INTERNAL);
   setup_timer_1(T1_INTERNAL|T1_DIV_BY_2);
   setup_timer_2(T2_DIV_BY_4,175,2);
   //******
   setup_comparator(NC_NC_NC_NC);
   setup_vref(FALSE);
   enable_interrupts(INT_EXT);   //turn on EXT to find start bit
   ext_int_edge( H_TO_L );   // Sets up EXT
   disable_interrupts(INT_TIMER2); //turn off timer 2
    enable_interrupts(GLOBAL);

   initialize(&que); //sets up parameters for que
   temp = (0x0f & input_c()); //read lowest portc bits
   device_type = 0x0f ^ temp; //invert portc bits, see Device table for reference

   while (TRUE) //continuous loop through the different mode cases, read buttons, etc.
   {
      switch (mode)
      {


Now I only want this to occur once at start up. Read the port, set the device and then continue. However, I can't seem to make it work this way. At first I thought it was a hardware issue, but when it's hooked up to the debugger, everything works fine, and whatever I have the switch set to, it reads correctly evertime I run the debugger. The only way I've been able to make things work without the debugger is by rearranging the code to look like this...

Code:

   initialize(&que); //sets up parameters for que

   while (TRUE) //continuous loop through the different mode cases, read buttons, etc.
   {
      temp = (0x0f & input_c()); //read lowest portc bits
      device_type = 0x0f ^ temp; //invert portc bits, see Device table for reference
      switch (mode)
      {


Which causes the code to read in port C everytime it loops around, which isn't what I need or want. I've tried adding a delay at the beginning right before initialize(&que); to see if it was a power issue on startup, but that didn't make any difference. If anyone has any ideas for me, I'm more than willing to listen, this thing has been driving me crazy for almost a week now. Crying or Very sad


Kmoe
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon May 05, 2008 1:36 pm     Reply with quote

Make a very simple test program that only tests reading the switches.
Get rid of all other code. Example:
Code:

#include <18F4525.h>
#fuses XT,NOWDT,PUT,BROWNOUT,NOLVP
#use delay(clock=4000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7, ERRORS)

//====================================
void main()
{
int8 value;

while(1)
  {
   value = input_c();
   value &= 0x0F;
   
   printf("%x \n\r", value);
   delay_ms(500);
  }

while(1);
}

This program will read the switches and display the value every 1/2
second on a terminal window. Try it. Change the oscillator fuse
and #use delay() statement as required to match your hardware.
coderchick
Guest







PostPosted: Mon May 05, 2008 5:51 pm     Reply with quote

thanks PCM, but I figured it out. It turned out to be a case of the compiler Wizard being too helpful. Once I removed the line setup_spi(FALSE); everything worked the way I wanted it to. Thanks for your time!


Kmoe Very Happy
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