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

IO Problem, Cannot Read Inputs

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








IO Problem, Cannot Read Inputs
PostPosted: Tue Sep 20, 2005 1:45 pm     Reply with quote

Im not sure what the problem is, but I cannot seem to read my IO pins.

I am using the PIC18F8490. I have an LCD connected (which I know works). I am just trying to change whats displayed to corresond to switch settings. It never changes. I have external pullups on all of the input pins. Any ideas?

Code:

#include "lcdboard.h"

void main() {
   PreLaunch();
   Configure_IO();

   Configure_Units();   // Read all switch setting, set defaults

   while(1){
      testIO();
   }
}

void PreLaunch(){
   setup_oscillator(OSC_31KHZ|OSC_INTRC);

   setup_adc_ports(NO_ANALOGS|VSS_VDD);
   setup_adc(ADC_OFF|ADC_TAD_MUL_0);

   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_ccp1(CCP_OFF);
   setup_ccp2(CCP_OFF);

   setup_comparator(NC_NC_NC_NC);
   setup_vref(FALSE);

   setup_spi(SPI_SLAVE);

   setup_low_volt_detect(FALSE);
   setup_lcd(0b10001001,0b01110000);
}

void Configure_IO() {

   Set_TRIS_B(0x00);
   Set_TRIS_C(0x00);

}

void TestIO(){
   int value1 = 0;
   int value2 = 0;

   if (DIP1 == 0)
      value1+=1;
   if (DIP2 == 0)
      value1+=2;
   if (DIP3 == 0)
      value1+=4;
   if (DIP4 == 0)
      value1+=8;
   if (DIP5 == 0)
      value1+=16;
   if (DIP6 == 0)
      value1+=32;

   if (value1 > 29){
      lcd_symbol(Digit_Map[3],DIGIT5);
      lcd_symbol(Digit_Map[value1-30],DIGIT4);
   }
   else if (value1 > 19){
      lcd_symbol(Digit_Map[2],DIGIT5);
      lcd_symbol(Digit_Map[value1-20],DIGIT4);
   }
   else if (value1 > 9){
      lcd_symbol(Digit_Map[1],DIGIT5);
      lcd_symbol(Digit_Map[value1-10],DIGIT4);
   }
   else {
      lcd_symbol(Digit_Map[value1],DIGIT4);
   }

   if (SW1 == 0)
      lcd_symbol(Digit_Map[1],DIGIT8);
   if (SW2 == 0)
      lcd_symbol(Digit_Map[2],DIGIT8);
   if (SW3 == 0)
      lcd_symbol(Digit_Map[3],DIGIT5);
}



Heres part of the .h file

Code:

#include <18F8490.h>

#device adc=10

#FUSES NOWDT                    //Watch Dog Timer uses 1:32 Postscale
#FUSES INTRC_IO                 //Internal RC Osc, no CLKOUT
#FUSES NOPROTECT                //Code not protected from reading
#FUSES NOBROWNOUT               //No brownout reset
#FUSES BORV28                   //Brownout reset at 2.8V
#FUSES NOPUT                    //No Power Up Timer
#FUSES NOIESO                   //Internal External Switch Over mode disabled
#FUSES STVREN                   //Stack full/underflow will cause reset
#FUSES NODEBUG                  //No Debug mode for ICD
#FUSES NOFCMEN                  //Fail-safe clock monitor disabled
#FUSES NOMCLR                 //Master Clear pin enabled
#FUSES LPT1OSC                  //Timer1 configured for low-power operation
#FUSES NOXINST                  //Extended set extension and Indexed Addressing mode disabled (Legacy mode)

#use delay(clock=32000)

#define SW1 PIN_B7
#define SW2 PIN_B6
#define SW3 PIN_B5
#define DIP1 PIN_B0
#define DIP2 PIN_B1
#define DIP3 PIN_B2
#define DIP4 PIN_B3
#define DIP5 PIN_B4
#define DIP6 PIN_C2
newguy



Joined: 24 Jun 2004
Posts: 1908

View user's profile Send private message

PostPosted: Tue Sep 20, 2005 1:52 pm     Reply with quote

You have the tris set wrong. 0 = output, 1 = input.
Mark



Joined: 07 Sep 2003
Posts: 2838
Location: Atlanta, GA

View user's profile Send private message Send e-mail

PostPosted: Tue Sep 20, 2005 1:59 pm     Reply with quote

PIN_B7 is #defined as a number
Code:
#define PIN_B7  31759

that means something to CCS specific functions.

In your code:
Code:

   if (DIP1 == 0)

would be
Code:

if (31759 == 0)


See the problem yet? You need to define DIP1 as portb.7 where you define portb as a variabe at the location of portb. Another option is to use the CCS function input(DIP1).

Also, if you handle the var yourself, remember to set the tris correctly (1 for an input). If you use standard_io and the CCS function, the Compiler will handle the tris for you.
Guest








PostPosted: Tue Sep 20, 2005 2:29 pm     Reply with quote

Thanks Guys, works now.
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