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

Trouble reading a button

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







Trouble reading a button
PostPosted: Thu Jul 27, 2006 1:26 am     Reply with quote

Hi! I have been using C18, and have just changed to CCS. I'm simply trying to toggle an LED using a button input. I can flash an LED through code, but not through the button.

Please see my code below:
[ while (1) {

while(input(PIN_A0)) {
output_high(PIN_D1);
delay_ms(500);
output_low(PIND1);
}

while(!input(PIN_A0)){
output_high(PIN_D2);
delay_ms(500);
output_low(PIN_D2);
}
}
]

Any help understanding why this might not work would be greatly appreciated!

Thanks!
Guest








PostPosted: Thu Jul 27, 2006 1:28 am     Reply with quote

Sorry, there was an error in my code. Here is the revised version:
while (1) {

while(input(PIN_A0)) {
output_high(PIN_D1);
delay_ms(500);
output_low(PIN_D1);
}

while(!input(PIN_A0)){
output_high(PIN_D2);
delay_ms(500);
output_low(PIN_D2);
}
}
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Jul 27, 2006 1:42 am     Reply with quote

If you want the LEDs to flash, you've got to have a delay for both
the high and the low time. Add the lines shown in bold below.
Quote:

while(input(PIN_A0))
{
output_high(PIN_D1);
delay_ms(500);
output_low(PIN_D1);
delay_ms(500);
}

while(!input(PIN_A0))
{
output_high(PIN_D2);
delay_ms(500);
output_low(PIN_D2);
delay_ms(500);
}
}
Guest








PostPosted: Thu Jul 27, 2006 2:14 am     Reply with quote

Thanks for your reply. I tried what you suggested, but no luck. I can't make the LEDs trun on at all!!! Crying or Very sad
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Jul 27, 2006 2:25 am     Reply with quote

Post a test program. Show the code that you've already posted,
but also show the main() function, and all #include, #use, and #fuses
statements.

When post the code, highlight all of it and then press the "Code" button.
This will make it be formatted better.

Also, when you post, make that HTML is disabled. Look below the
window where you type in your post. There is a checkbox labeled:
Quote:
Disable HTML in this post

Make sure it is selected.
Guest








PostPosted: Thu Jul 27, 2006 2:30 am     Reply with quote

Thanks so much for your help. Here is my program. I used the project wizard to set it up.

Code:
#include "C:\Documents and Settings\simon\My Documents\Contract Work\DFS\Firmware\Prototyping\Basic Functions\LED Flash on Button Input\Button Input.h"
  #include <stdio.h>
  #include <stddef.h>
  #include <stdlib.h>
  #include <string.h>


void main()
{

   port_b_pullups(TRUE);
   setup_adc_ports(NO_ANALOGS);
   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(FALSE);
   setup_low_volt_detect(FALSE);
   setup_oscillator(False);

      while (1) {

         while(input(PIN_A0)) {
            output_high(PIN_D1);
            delay_ms(500);
            output_low(PIN_D1);
            delay_ms(500);
         }

         while(!input(PIN_A0)){
            output_high(PIN_D2);
            delay_ms(500);
            output_low(PIN_D2);
            delay_ms(500);
         }
   }


}


Thanks again!
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Jul 27, 2006 2:45 am     Reply with quote

Can you post the #include, #use, and #fuses statements ?
They are likely to be in this file:
Quote:
Button Input.h


Also post your version of the compiler.
Guest








PostPosted: Thu Jul 27, 2006 5:09 am     Reply with quote

Here's the .h file:

Code:
#include <18F458.h>
#device adc=8

#FUSES NOWDT                    //No Watch Dog Timer
#FUSES WDT128                   //Watch Dog Timer uses 1:128 Postscale
#FUSES HS                       //High speed Osc (> 4mhz)
#FUSES NOPROTECT                //Code not protected from reading
#FUSES NOOSCSEN                 //Oscillator switching is disabled, main oscillator is source
#FUSES BROWNOUT                 //Reset when brownout detected
#FUSES BORV20                   //Brownout reset at 2.0V
#FUSES NOPUT                    //No Power Up Timer
#FUSES NOCPD                    //No EE protection
#FUSES STVREN                   //Stack full/underflow will cause reset
#FUSES NODEBUG                  //No Debug mode for ICD
#FUSES LVP                      //Low Voltage Programming on B3(PIC16) or B5(PIC18)
#FUSES NOWRT                    //Program memory not write protected
#FUSES NOWRTD                   //Data EEPROM not write protected
#FUSES NOWRTB                   //Boot block not write protected
#FUSES NOCPB                    //No Boot Block code protection
#FUSES NOWRTC                   //configuration not registers write protected
#FUSES NOEBTR                   //Memory not protected from table reads
#FUSES NOEBTRB                  //Boot block not protected from table reads

#use delay(clock=20000000)
#use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=9)



I ordered the PIC18 version of the compiler today, but have been using the demonstration version until they email me the link to download it.

Thanks so much again for your help!
rnielsen



Joined: 23 Sep 2003
Posts: 852
Location: Utah

View user's profile Send private message

PostPosted: Thu Jul 27, 2006 8:08 am     Reply with quote

Try NOLVP in your fuses. This one bit me when I first started using CCS.

Ronald
Guest








PostPosted: Thu Jul 27, 2006 5:38 pm     Reply with quote

Dear Ronald,

Thank you so much for your suggestion - it works now!!!

Thanks again - I really appreciate the 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