• No se han encontrado resultados

Aproximación sintáctica y pragmática de la interfaz de usuario

CAPITULO IV. LA GRAMÁTICA DE LOS MEDIOS DIGITALES

4.4 Aproximación sintáctica y pragmática de la interfaz de usuario

By clearing some bit of the TRIS register (bit=0), the corresponding port pin is configured as output.

Similarly, by setting some bit of the TRIS register (bit=1), the corresponding port pin is configured as input.

This rule is easy to remember 0 = Output, 1 = Input.

Most other programming languages require you to set the appropriate bits of TRIS registers before using the port. Although this is supported in Proton Basic, yet this has a nice simple command, which internally does the same thing.

Device=18F452 Output PORTC Input PORTE.0

In this program the output command has set the entire portc as output, and the Input command has selected only PORTE.0 as input. This could also have been accomplished using associated TRISC and TRISE registers.

Analog and Digital Pins

As we have seen, that each pin on microcontroller has more than one functions. Although most of the data and communication is in digital format, yet analog features are also very important. A large number of sensors give their output as analog. Thus analog input is essential to work with these devices. PIC18F452 has a number of pins, which can acquire analog data. The same pins however can also be configured as digital, if not to be used as analog.

PORTA

Lets consider the PORTA, which is most commonly used to acquire analog data. By default this port, is configured as analog, when processor is reset. In order to configure entire port, or some of its pins as digital, certain registers have to be set.

Just like TRISA register, which configures the direction of individual pins, there is also an ADCON0 register. This register has three bits which correspond to the 7 analog input channels. Internally there is one Analog to digital converter, so only one channel can be accessed at a time. By changing the number in ADCON0 register all channels are sampled one by one if you want.

In case you do not want to implement analog function at all, you can simply issue:

ALL_DIGITAL true

This will configure all lines as digital and turn the analog function off. This is implemented in ADCON1 register. If you need a mix of analog and digital pins then you will have to play with this register. In order to use a pin as analog input the corresponding TRIS bit must be set as 1, or issue INPUT command for that port pin, so that it can acquire analog data.

PORTB

PORTB is the second most commonly used port. This is also a bidirectional port, and has an associated TRISB register. The bits of TRISB register corresponding to PORTB bits determine if the port pin will act as input or output. This port does not have analog inputs, however various other functions are associated with individual pins. These functions will be referred in appropriate sections.

RB6 & RB7 Pins

These pins deserve a special note. RB6 and RB7 pins of PORTB are also used for programming the microcontroller. While its not a problem when the microcontroller is being programmed in the socket of a stand-alone programmer. However since more and more programmers and specially in case of prototyping where the microcontroller has to be programmed a number of times while testing the software, are using In Circuit programming.

This method uses the microcontroller while it is in the main development board. The RB6 and RB7 then must be free from interference. If certain circuitry or devices have been attached to these pins, which tend to give low resistance and therefore steel the programming signals, it is likely that programming will experience problems. It is therefore advisable, either to keep these pins free, or if used in your design, there should be an intervening 4.7K resistor to the device so that it does not interfere.

PIC Lab-II provides facilities of in circuit programming, and does not use these pins in any circuit.

However since this is a general purpose board and you may use these pins in your projects through headers.

In that case keep this in mind, while programming. If your device is interfering, either disconnect it while programming of interpose a 4.7-10K resistors in your project.

RB3, LVP

Although most programmer use High Voltage Programming mode, which means the microcontroller needs 12V on MCLR pin to put it into programming mode. However some programmers use Low Voltage Programming. In order to use a low voltage programming mode the RB3 pin must be connected to VDD, or pulled high. PIC-Lab-II allows LVP mode, and RB3 is connected to the programming header as PGM pin.

It is the responsibility of programmer to give logical ‘1’ on this pin to use LVP. So keep this fact in mind while using RB3 in your projects, that if your programmer is LVP it will give a logical ‘1’ to this pin while programming.

Microtronics PIC-PG II as well as ICD-2 do not use this pin, so you are free to use it as you like, it will not interfere with these programmers.

RB0 (Interrupt)

Normally processor is executing one instruction at a time, and while it is executing an instruction it can not monitor another event, like push of a button or coming signals. This problems has been overcome by using interrupt mechanism. We shall talk about this later in appropriate section. RB0, can be configured using internal registers not only to act as input pin, but also to fire an interrupt event whenever its status is changed. To facilitate this type of experiments a push button SW5 has been provided on RB0.

Internal Pull-Up Resistors

Many input devices like switches, keypads etc. require a pull-up resistor, which gives a logical ‘1’ to the pin when there is no ‘0’ from the input device. PORTB has internal pull-up resistors which can be enabled through special function

However it can be directly connected to PORTB, by enabling its internal pull-up resistors.

PORTC

PORTC is similar to PORTB, as its also a bi-directional digital port. It has an associated TRISC register which determines the direction of port pins. PORTC has number of additional functions associated with its

pins. These functions will be referred to in relevant sections.

PIC Lab-II has 8 LED indicators connected to this port via 220 ohms current limiting resistors. These LEDs are there to show an experiment how to control a pin on and off. In your actual projects you can however connect a small circuitry to turn a relay on or off. The LEDs when turn ON drain a significant amount of current and therefore may interfere with other devices if being used. For example RC6 and RC7 are used for USART communication. This fails if LEDs on PORTC are enabled. You can disable LEDs using SW1 on DIP switch.

PORTD

PORTD and TRISD registers are same as PORTC, other relevant functions will be discussed in appropriate sections. PIC Lab-II uses this port for LCD.