have been doing this small project for a short while. Using 4 LEDs, a potentiometer, PIC16f88 microcontroller. I am having some trouble with setting up the analogue to digital converter to run the motor and light up the LEDs as the motor runs faster
This is the code that i have so far
Any assistance will be greatly appreciated
Rich (BB code):
List p=PIC16F88
#INCLUDE <P16F88.INC>
__CONFIG _CONFIG1, _CP_OFF & _CCP1_RB0 & _DEBUG_OFF & _WRT_PROTECT_OFF & _CPD_OFF & _LVP_OFF & _BODEN_OFF & _MCLR_ON & _PWRTE_OFF & _WDT_OFF & _INTRC_IO
__CONFIG _CONFIG2, _IESO_OFF & _FCMEN_OFF
;-----------------------------------------------------------------------------
;Start of the inital program
ORG 0x0000 ;
goto start ;Go to the start loop
start: ;Begin the start loop
nop ;No operation
bsf STATUS,RP0 ;Go to bank 1
movlw b'00000001' ;Set ping
movwf TRISA ;
movlw b'10111111' ;
movwf TRISB ;
;-----------------------------------------------------------------------------
;Analog to Digital Converter
clrf ANSEL
movlw b'00000100' ;Set pin to analog
movlw ANSEL
movlw b'00110000' ;Ref Voltage to external pins
movwf ADCON1
movlw .1 ;AD format select bits
movwf ADFM
movlw b'10000000' ;Analog Clock
movwf ADCON0
bsf ADON,1 ;ADC switch on
;-----------------------------------------------------------------------------
;Motor Speed Control
bsf STATUS,RP0 ;Go to bank 1
movlw b'00000000' ;Set the corrct Port
movwf TRISB ;Get to TRISB
; movlw .100 ;Set the speed of the motor
movf ADRESH
movwf PR2 ;Period Register
bcf STATUS,RP0 ;Go to back 0
movlw b'00001100' ;
movwf CCP1CON ;
bsf T2CON, TMR2ON ;
movlw .100 ;Set the speed of the motor
movwf CCPR1L
;-----------------------------------------------------------------------------
;End of Program
goto $ ;Endless loop
end ;End the program
Any assistance will be greatly appreciated
Attachments
-
89 KB Views: 44