11.07.2015 Views

PICBASIC PLUS LITE Manual - Profe Saul

PICBASIC PLUS LITE Manual - Profe Saul

PICBASIC PLUS LITE Manual - Profe Saul

SHOW MORE
SHOW LESS
  • No tags were found...

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

<strong>PICBASIC</strong> <strong>PLUS</strong> Compiler3 - Program RulesAs with any language, there are rules you must follow when producing a program and<strong>PICBASIC</strong> <strong>PLUS</strong> is no exception. These are laid out in this section.3.1. Device specific issues.Before venturing into your latest project, always read the datasheet for the specific devicebeing used. Because some devices have features that may interfere with expectedpin operations. The PIC16C62x and the 16F62x devices are examples of this. ThesePICmicros have analogue comparators on PORTA. When these chips first power up,PORTA is set to analogue mode. This makes the pin functions on PORTA work in astrange manner. To change the pins to digital, simply add the following line near thefront of your BASIC program, or before any of the pins are accessed: -CMCON = 7Any PICmicro with analogue inputs, such as the PIC16C7xx, PIC16F87x andPIC12C67x series devices, will power up in analogue mode. If you intend to use themas digital types you must set the pins to digital by using the following line of code: -ADCON1 = 7Another example of potential problems is that bit-4 of PORTA (PortA.4) exhibits unusualbehaviour when used as an output. This is because the pin has an open drain outputrather than the usual bipolar stage as in the rest of the output pins. This means it canpull to ground when set to 0 (low), but it will simply float when set to a 1 (high), insteadof going high.To make this pin act as expected, add a pull-up resistor between the pin and 5 Volts. Atypical value resistor may be between 1K and 33K, depending on the device it is driving.If the pin is used as an input, it behaves the same as any other pin.Some PICmicros, such as the PIC16F87x range, allow low-voltage programming. Thisfunction takes over one of the PORTB (PortB.3) pins and can cause the device to acterratically if this pin is not pulled low. In normal use, It’s best to make sure that lowvoltageprogramming is disabled at the time the PICmicro is programmed. By default,the low voltage programming fuse is disabled, however, if the CONFIG directive is used,then it may inadvertently be omitted.All of the PICmicro pins are set to inputs on power-up. If you need a pin to be an output,set it to an output before you use it, or use a BASIC command that does it for you. Onceagain, always read the PICmicro data sheets to become familiar with the particular part.The name of the port pins on the PIC12C67x and 12CE67x devices is GPIO. The namefor the TRIS register is TRISIO: -GPIO.0 = 1TRISIO = %101010‘ Set GPIO.0 high‘ Manipulate ins and outs11Copyright Crownhill 2001

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!