'**************************************************************** '* Name : Speed and Volume Control * '* Author : Molly and Daniel * '* Notice : Copyright (c) 2018 [select VIEW...EDITOR OPTIONS] * '* : All Rights Reserved * '* Date : 4/22/2018 * '* Version : 1.0 * '**************************************************************** ' The following code is taken from Dr. Nickels set up of internal oscillator ' PIC16F88 code template for MECH307 Labs ' The following configuration bits and register settings ' enable the internal oscillator, set it to 8MHz, ' disables master clear, and turn off A/D conversion ' Configuration Bit Settings: ' Oscillator INTRC (INT102) (RA6 for I/O) ' Watchdog Timer Enabled ' Power-up Timer Enabled ' MCLR Pin Function Input Pin (RA5 for I/O) ' Brown-out Reset Enabled ' Low Voltage Programming Disabled ' Flash Program Memory Write Enabled ' CCP Multiplexed With RB0 ' Code Not Protected ' Data EEPROM Not Protected ' Fail-safe Clock Monitor Enabled ' Internal External Switch Over Enabled ' Define configuration settings (different from defaults) #CONFIG __CONFIG _CONFIG1, _INTRC_IO & _PWRTE_ON & _MCLR_OFF & _LVP_OFF #ENDCONFIG ' Set the internal oscillator frequency to 8 MHz DEFINE OSC 8 OSCCON.4 = 1 OSCCON.5 = 1 OSCCON.6 = 1 ' 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 15 ' Set sampling time in uS ' Set up ADCON1 ADCON1 = %10000000 ' Right-justify results (lowest 10 bits) ' borrowed code ends here ' Set up A/D converters and inputs and outputs ansel = %01100000 TRISB.6 = 1 TRISB.7 = 1 TRISB.0 = 0 ' Define variables adcVar_v VAR WORD ' ADC result for volume input dutyCycle_v var byte ' Duty cycle for PWM for volume control level_v var byte ' Variable to hold percentage of volume level adcVar_s var word ' ADC result for speed input dutyCycle_s var byte ' Duty cycle for PWM for speed control level_s var byte ' Variable to hold percentage of speed level main: pause 1000 ' Set up time for LCD while(1) ' loop adcin 5, adcVar_v ' get ADC input from volume pot dutyCycle_v = adcVar_v/4 ' convert to 0 to 255 duty cycle level_v = dutycycle_v*100/255 ' determine percentage adcin 6, adcVar_s ' get ADC input from speed pot dutyCycle_s = adcVar_s/4 ' convert to 0 to 255 duty cycle level_s = dutyCycle_s*100/255 ' determine percentage dutyCycle_s = dutyCycle_s/128 ' reduce speed of motor lcdout $FE, 1, "Volume:", $14, #level_v, "%" ' update LCD with volume level lcdout $FE, $C0, "Speed:", $14, #level_s, "%" ' update LCD with speed level pwm portB.0, dutyCycle_s, 10 ' output motor speed wend end