« Stripped Down PIC code: Nov 24 | Main | Part Spec Short Cuts »

December 01, 2004

PIC Transistor test code

Simple test code transistor ADC in, print to serial out

'****************************************************************
'* Name : transistor test *
'* Author : silly code by goodness *
'* Notice : Copyright (c) 2004 *
'* : All Rights Reserved *
'* Date : 4/16/2004 *
'* Version : 1.0 *
'* Notes : *
'* : *
'****************************************************************
'needed for serin and serout

include "modedefs.bas"

DEFINE OSC 4
' ----------------------------------------------------- PORT SET-UP
'SET PORT A TO INPUT
TRISA = %11111111
'SET PORT C TO OUTPUT
TRISC = %00000000
' ----------------------------------------------------- CONSTANTS

' ----------------------------------------------------- VARIABLES
getTrans VAR BYTE
' ----------------------------------------------------- START MAIN


main:

ADCIN 0, getTrans ' get the ADC value from the transistor on PortA.0 pin

serout2 portc.6, 16468, [DEC getTrans, 10, 13]

PAUSE 50


goto main


Posted by christina at December 1, 2004 08:55 PM

Comments

'****************************************************************
'* Name : UNTITLED.BAS *
'* Author : [select VIEW...EDITOR OPTIONS] *
'* Notice : Copyright (c) 2004 [select VIEW...EDITOR OPTIONS] *
'* : All Rights Reserved *
'* Date : 12/3/2004 *
'* Version : 1.0 *
'* Notes : *
'* : *
'****************************************************************
include "modedefs.bas"

DEFINE OSC 4 'Sets the clock

' Define ADCIN parameters
DEFINE ADC_BITS 10 ' Set number of bits in result
DEFINE ADC_CLOCK 3 ' Set clock source (3=rc)
DEFINE ADC_SAMPLEUS 50 ' Set sampling time in uS

ADCvar VAR WORD ' Create variable to store result

TRISA = %11111111 ' Set PORTA to all input
ADCON1 = %10000010 ' Set PORTA analog and right justify result
'SET PORT C TO OUTPUT
TRISC = %00000000
Pause 500 ' Wait .5 second

main:
ADCIN 0, ADCvar ' Read channel 0 to adval
serout2 PORTC.6, 16468, [DEC ADCvar, 13, 10] ' print it to serial out,
' with linefeed and carriage return (10, 13)
PAUSE 1000
GoTo main ' Do it forever

Posted by: phaedra at December 3, 2004 11:57 PM

this might be why we're getting funny readings on the phototransistors:

Note that most pins on a PIC have more than one function. For example, pin 4 on the 18F452 is RA2/AN2/Vref-. In other words, it functions as I/O port A, pin 2; analog in channel 2; or analog in negative voltage reference, depending on the configuration of the various special function registers associated with it. If the A/D converter is on, and set to channel 2, this pin will function as an analog in. If the ADC is configured to take a negative voltage reference signal, this pin will be that reference. If the ADC is off, it'll function as a normal digital I/O pin.

Posted by: phaedra at December 6, 2004 03:04 PM

Post a comment




Remember Me?