8/26/2009

Get all possible digital inputs on a PIC18F2*50

Same thing as last post, the other way round.

Pins available for digital input:

  • PORTA: RA0 through RA6 gives 7 inputs
  • PORTB: RB0 through RB7 gives 8 inputs
  • PORTC: RB0 through RB2 and RB4 through RB7 gives 7 inputs
  • PORTE: RE3 gives one input
=> on a PIC18F2*50 you have 23 digital outputs total.

Configure options:
  • FOSC = INTOSCIO_EC //using the internal oscillator will free pins RA5 and RA6
  • LVP = OFF //you don't have to ground RB5 anymore
  • PBADEN = OFF //disable the analog inputs on RB0 through RB4
  • DEBUG = OFF //disable debug output, free RB6 and RB7
  • MCLRE = OFF //disable the master clear option, free RE3

Registers to set:
  • ADCON1 = 0x0F; //disable analog inputs on RA0 through RA3
  • UCON = 0x00; //disable the usb module, free RC4 and RC5
  • UCFG = 0x08;
RC4, RC5 & RE3 can only be used as digital inputs, not as outputs. PORTB has internal pullups which can be activated by clearing bit7 at INTCON2. This is very handy for me because I have wildly fluctuating inputs here with the breadboard and power over my pc's USB.

Keine Kommentare: