'---------------Title-------------- ' File......16F877A_adc1.pbp ' Started....1/7/08 ' Microcontroller used: Microchip Technology PIC16F877A ' microchip.com ' PicBasic Pro Code: micro-Engineering Labs, Inc. ' melabs.com '--------Program Desciption-------- ' The program uses one of the analog-to-digital ' converters,(AN0), to measure the voltage ' on the center pin of a potentiometer (an analog signal). ' It then converts the analog voltage into an 8-bit ' digital value (0 to 255) and displays it on an LCD. '----------Related Lesson---------- ' adc1.pbp (the 16F88 program) is used in ' the lesson Resistive Sensors at: ' http://www.cornerstonerobotics.org/curriculum/lessons_year2/erii23_resistive_sensors.pdf '-----New PicBasic Pro Commands---- ' ADCIN Channel,Variable ' Reads analog value into Channel (one of the AN inputs), ' converts the analog value to a digital value and ' stores the result in Variable. '---------PIC Connections--------- ' 16F877A Pin Wiring ' --------- ---------- ' RB4 LCD pin 11(DB4) ' RB5 LCD pin 12(DB5) ' RB6 LCD pin 13(DB6) ' RB7 LCD pin 14(DB7) ' RA0 Center Lead of Potentiometer ' RA4 LCD Register Select(RS) ' RB3 LCD Enable(E) ' See schematic at: ' http://www.cornerstonerobotics.org/schematics/pic16f877a_adc1.pdf '----------LCD Connections--------- ' LCD Pin Wiring ' --------- ---------- ' 1 Ground(Vss) ' 2 + 5v(Vdd) ' 3 Center of 20K Pot(Contrast) ' 4 RA4(Register Select,RS) ' 5 Ground(Read/Write,R/W) ' 6 RB3(Enable) ' 7 No Connection(DB0) ' 8 No Connection(DB1) ' 9 No Connection(DB2) ' 10 No Connection(DB3) ' 11 RB4(DB4) ' 12 RB5(DB5) ' 13 RB6(DB6) ' 14 RB7(DB7) '----------Constants/Defines------- ' To free up AN0 (Pin RA0) for an analog input, the ' default four LCD Data Bits must be removed from RA0 - RA3. ' This is relocated to the upper 4 bits RB4 - RB7 in PORTB ' using the LCD DEFINE statements below. All other ' default LCD pins and functions are left unchanged. ' For details see: ' http://www.cornerstonerobotics.org/curriculum/lessons_year2/erii16_lcd3_pot_command_and_lcd_defines.pdf ' or ' Look around page 97 in the PicBasic Pro Compiler Manual. ' The PicBasic Pro Compiler Manual is on line at: ' http://www.microengineeringlabs.com/resources/index.htm#Manuals define LCD_DREG PORTB ' PORTB - Data bit Port define LCD_DBIT 4 ' Set starting Data Bit to bit 4 '------------Variables------------- x var byte ' Byte for potentiometer input '-------------Main Code------------ pause 1000 ' Pause to allow LCD to setup start: adcin 0, x ' Read analog voltage on AN0(RA0) and ' convert to 8-bit digital value ' and store as x. lcdout $FE,1,"POT =", #x ' Clears LCD screen, displays ' "POT =" and the 8-bit value of x pause 500 ' Pause 1/2 second goto start ' Go to loop label end