Yahoo mail is coming slow again. I don't do C, but from what I can see, I think your problem is the TRIS settings. Each bit of the port is set with TRIS, not the entire port. Therefore setting TRISB = 1 sets bit 0 to input and bits 1-7 to outputs. If you want bits 1-4 as inputs and the rest outputs the value would be b'00011110', 1Eh, or 30 decimal. Good luck, Chad --- scubagreg7777777 <> wrote: > > > Hi everyone, > > I'm pretty new to PICS, but will do my best to characterize my > problem > and provide as much pertinent info as possible. I perplexed as to > what is going on with my PIC. I am using an 18f452 on a PICDEM 2 > Plus > board, and my own PCB that I milled. > > Here is the problem: > > I have a 4-bit, high asserting DIP switch, with its input being sent > to PORTC.RC1 through PORTC.RC4. > > Using an oscilliscope on the output I can observe that the switch is > indeed workin, switching from ~0v to ~5v. However, as soon as I plug > the PIC18F452 into the board, the DIP switch no longer responds > (still > viewing the output on a scope), and stays a flat ~0v, regardless of > how the DIP is asserted. As soon as I pop the chip out, the switch > is back to normal, and switches from 0v to 5v. > > Furthermore, If I touch a PORTC pin with a 5v connection, the > software > behaves how it should, and outputs on PORTD. It seems that the DIP > switches simply stop working. > > I am using a 160ohm resistor, and there isn't too much else about my > setup. I have been able to repeat this behaviour on both the PICDEM > 2 > Plus board, and my own PCB. Below is a picture of my setup, and I > have attached a copy of my code (using MCC18 compiled with MPLAB > 6.4). > > I have switched out PICS, but not resistors (they're soldered in, and > I do not have access to a soldering kit right now. > > What really baffles me, is that as soon as I put my chip in, the > switch dies, and no longer works. If anyone has suggestions, PLEASE > let me know. > > (also, as a bonus, if someone could explain why this is happening, I > would be very interested in learning how to fix this problem, and why > it happened) > > Thanks in advance, > > Greg > (DIP setup) > > 5v > | > | > / > \ > / (160 ohm resistor) > \ > | > |--------- output to PORTC > | > > / > / (switch) > / > | > | > | > ----- (ground) > -- > > > Code: > -------- > > /* Include Libraries */ > #include <p18f452.h> /* for TRISB and PORTB declarations */ > #include <adc.h> /* A/D library */ > #include <stdlib.h> /* Standard Library */ > /**********************************************/ > /* Function Prototypes */ > > int checkSpeed( void ); > int checkDip( void ); > /***********************************************/ > /* Variable Declaration */ > /* */ > > /* main() */ > int temp = 0; // temp variabe used in checkSpeed() > int test = 0; // test variable used in main to determine if Ra1 is > detecting high load (temp) > > int dipVal = 0; // value returned from checkDip() function > call > int speedVal = 0; // speed setting returned from checkSpeed() > function call > int onTime = 0; // max amount of time a particular channel/light > can be turned on > int offTime = 0; // amount of time a channel/light will be turned > off > int delayCounter = 0; // counter variable, useed in output > display engine for on and off time > int speedCounter = 1; // used in nested loop to get around max > numeric value -- full explanation in dev notes > int curOutput = 1; // current chanel being output > /* checkSpeed() */ > int a2dSpeed = 0 ; // value obtained from a2d conversion > int userInputSpeed = 0; // speed setting, inferred from a2dSpeed > value, returned to main > // 1 = slow, 2 = medium, 3 = fast > /* checkDip() */ > int inputSum = 0; // final, base-10 value of user input via DIP > /* customLight() */ > /* delay() */ > int i = 0; // counter, used for delay loop > int j = 1; // counter, used for number of loops -- speed control > > void main( void ) > { > > /* Initialize Configuration */ > TRISA = 1; // configs PORTA for INPUT -- used for checkSpeed() > TRISC = 1; // configs PORTC for INPUT -- used for checkDip() > TRISD = 0; // configs PORTD for OUTPUT -- used for light output > > /* configure A/D convertors */ > /* detailled explanation is located at: p 16-18 in > MPLAB-C18-Libraries.pdf */ > /* ADC_FOSC_32 -> a/d clock source uses FOSC/32 > ADC_RIGHT_JUST -> result in least significant bits > ADC_8ANA_0REF -> VREF+ = Vdd and VREF- = Vss (both analog) > ADC_CH# -> the channel being used > ADC_INT_OFF -> disable interrupts */ > > /* ADC_CH0 -> speed */ > OpenADC( ADC_FOSC_32 & ADC_RIGHT_JUST & ADC_8ANA_0REF,ADC_CH0 & > ADC_INT_OFF ); /* checkSpeed() */ > /* main program */ > while(1) > { > > /* (re)initialize values */ > speedVal = 0; > dipVal = 0; > /* obtain user input */ > dipVal = checkDip(); // determine DIP setting > > > if(dipVal == 0) > PORTD = 0; > > if(dipVal == 1) > { > PORTD = 1; > while(speedVal < 24000) speedVal++; > while(speedVal > 3) speedVal--; > PORTD = 0; > } > > if(dipVal == 2) > { > PORTD = 1; > while(speedVal < 24000) speedVal++; > while(speedVal > 3) speedVal--; > PORTD = 0; > while(speedVal < 24000) speedVal++; > while(speedVal > 3) speedVal--; > PORTD = 1; > while(speedVal < 24000) speedVal++; > while(speedVal > 3) speedVal--; > PORTD = 0; > } > > if(dipVal == 3) > { > === message truncated === ===== My software has no bugs, only undocumented features. __________________________________ |