Proyecto

Páginas: 7 (1530 palabras) Publicado: 17 de septiembre de 2012
INPUT OUTPUT PORTS (Detailed Description) #include #include #include #include Notes: 1. C_MICRO has five general purpose digital I/O ports (Ports A, B, C, D and E). C_STAMP has three general purpose digital I/O ports (Ports A, B and C). 2. Several pins of the I/O ports are multiplexed with an alternate function from the internal peripheral modules on the PIC micro-controller, such as ADC(Analog to Digital Converter) and PWM (Pulse Width Modulator). In general, when a peripheral is enabled, that pin may not be used as a general purpose digital I/O pin. 3. p18f252.h and p18f452.h are standard C18 compiler header files that define I/O port names and alternate peripheral pin function names. c_stamp.h / c_micro.h is a user defined header file that can optionally be included AFTER theabove-mentioned standard header file and further simplifies the naming of individual I/O port pins. (The header files are plain text files and can be opened in a text editor to view the details.) 4. p18f252.h is primarily included in C programs written for C_STAMP, but it can also be included in C_MICRO programs instead of p18f452.h, with the restriction that Ports D and E cannot be used. Thisrestriction ensures that the same C program will run on either C_STAMP or C_MICRO without any modifications. 5. Each port has three registers for its operation. These registers are: a. TRIS register (tri-state data direction register) b. PORT register (reads the logic levels on the pins of the device in input mode, outputs the logic levels on the pins of the device in output mode) c. LAT register (outputlatch) 6. The I/O pin’s direction (input or output) is controlled by the data direction register, called the TRIS register. TRIS controls the direction of PORT. A ’1’ in the TRIS bit corresponds to that pin being an input, while a ’0’ corresponds to that pin being an output. An easy way to remember is that a ’1’ looks like an I (input) and a ’0’ looks like an O (output). 7. In output mode, thePORT register is the latch for the data to be output. In input mode, when the PORT is read, the device reads the logic levels present on the I/O pins (not the latch). This means that care should be taken with read-modify-write commands on the ports and changing the direction of a pin from an input to an output on the fly. 8. As mentioned earlier, if a port pin is configured as output, reading thecorresponding port pin using the PORT register, will read the output logic level present on that pin, which will normally be the logic level written to the PORT register in the last write operation. 9. Writing to PORT when it is configured as an input, does not change anything. (standard header file for C_STAMP) (user defined header file for C_STAMP) (standard header file for C_MICRO) (user definedheader file for C_MICRO)

F Zia (20050725)

Examples of C18 Program Statements (this is a not a complete program) 1. All ports can be configured, read or written to, either as groups of bits or as individual bits. C18 compiler allows the use of decimal, binary, octal or hexadecimal constants in the program statements. 2. Configure RB7:RB4 pins as digital inputs and RB3:RB0 pins as digitaloutputs. TRISB = 0xF0; // F0 is hexadecimal constant (11110000 in 8 bit binary) 3. Configure RB3 pin as digital input (configuration of other PORTB pins remains unchanged). TRISBbits.TRISB3 = 1; 4. Set RB7:RB3 output pins to LOW (logic 0) and RB2:RB0 output pins to HIGH (logic 1). PORTB = 7; // 7 is a decimal constant (00000111 in 8 bit binary) 5. Read PORTB input logic levels into a one bytevariable result (declared as type char). result = PORTB; 6. Configure RC2 and RC1 pins as digital outputs and all other PORTC pins as digital inputs. TRISC = 0b11111001; // 11111001 is a binary constant 7. Configure RC0 pin as digital output (configuration of other PORTC pins remains unchanged). TRISCbits.TRISC0 = 0; 8. Set RC0 output pin to LOW (logic 0). Toggle RC1 output pin using read-modify-write...
Leer documento completo

Regístrate para leer el documento completo.

Estos documentos también te pueden resultar útiles

  • Proyectos
  • Proyecto
  • Proyectos
  • Proyecto
  • Proyecto
  • Proyecto
  • Proyectos
  • Proyecto

Conviértase en miembro formal de Buenas Tareas

INSCRÍBETE - ES GRATIS