commit 6e9322b6b49d4930b3bb3020459fe875a883a6e6 Author: sfokin Date: Fri Mar 7 17:19:07 2025 +0300 first working copy diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..10bc1d0 --- /dev/null +++ b/.gitignore @@ -0,0 +1,32 @@ +#Ignore List for Microchip's MPLAB X IDE +#It's a form of NetBeans with vendor specific changes +#Taken from zeha on GIST https://gist.github.com/zeha/5999375 +#Updated by Cristian Cristea (https://github.com/cristiancristea00) + +*.d +*.pre +*.p1 +*.lst +*.sym +*.obj +*.o +*.sdb +*.obj.dmp +*.mk +*.map +*.properties +*.production +*.debug +html/ +nbproject/private/ +nbproject/Package-*.bash +build/ +nbbuild/ +dist/ +nbdist/ +nbactions.xml +nb-configuration.xml +funclist +nbproject/Makefile-* +disassembly/ +.generated_files/ \ No newline at end of file diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..fca8e2c --- /dev/null +++ b/Makefile @@ -0,0 +1,113 @@ +# +# There exist several targets which are by default empty and which can be +# used for execution of your targets. These targets are usually executed +# before and after some main targets. They are: +# +# .build-pre: called before 'build' target +# .build-post: called after 'build' target +# .clean-pre: called before 'clean' target +# .clean-post: called after 'clean' target +# .clobber-pre: called before 'clobber' target +# .clobber-post: called after 'clobber' target +# .all-pre: called before 'all' target +# .all-post: called after 'all' target +# .help-pre: called before 'help' target +# .help-post: called after 'help' target +# +# Targets beginning with '.' are not intended to be called on their own. +# +# Main targets can be executed directly, and they are: +# +# build build a specific configuration +# clean remove built files from a configuration +# clobber remove all built files +# all build all configurations +# help print help mesage +# +# Targets .build-impl, .clean-impl, .clobber-impl, .all-impl, and +# .help-impl are implemented in nbproject/makefile-impl.mk. +# +# Available make variables: +# +# CND_BASEDIR base directory for relative paths +# CND_DISTDIR default top distribution directory (build artifacts) +# CND_BUILDDIR default top build directory (object files, ...) +# CONF name of current configuration +# CND_ARTIFACT_DIR_${CONF} directory of build artifact (current configuration) +# CND_ARTIFACT_NAME_${CONF} name of build artifact (current configuration) +# CND_ARTIFACT_PATH_${CONF} path to build artifact (current configuration) +# CND_PACKAGE_DIR_${CONF} directory of package (current configuration) +# CND_PACKAGE_NAME_${CONF} name of package (current configuration) +# CND_PACKAGE_PATH_${CONF} path to package (current configuration) +# +# NOCDDL + + +# Environment +MKDIR=mkdir +CP=cp +CCADMIN=CCadmin +RANLIB=ranlib + + +# build +build: .build-post + +.build-pre: +# Add your pre 'build' code here... + +.build-post: .build-impl +# Add your post 'build' code here... + + +# clean +clean: .clean-post + +.clean-pre: +# Add your pre 'clean' code here... +# WARNING: the IDE does not call this target since it takes a long time to +# simply run make. Instead, the IDE removes the configuration directories +# under build and dist directly without calling make. +# This target is left here so people can do a clean when running a clean +# outside the IDE. + +.clean-post: .clean-impl +# Add your post 'clean' code here... + + +# clobber +clobber: .clobber-post + +.clobber-pre: +# Add your pre 'clobber' code here... + +.clobber-post: .clobber-impl +# Add your post 'clobber' code here... + + +# all +all: .all-post + +.all-pre: +# Add your pre 'all' code here... + +.all-post: .all-impl +# Add your post 'all' code here... + + +# help +help: .help-post + +.help-pre: +# Add your pre 'help' code here... + +.help-post: .help-impl +# Add your post 'help' code here... + + + +# include project implementation makefile +include nbproject/Makefile-impl.mk + +# include project make variables +include nbproject/Makefile-variables.mk diff --git a/main.c b/main.c new file mode 100644 index 0000000..cf1f48d --- /dev/null +++ b/main.c @@ -0,0 +1,56 @@ +/* + * File: main.c + * Author: sfokin + * + * Created on March 7, 2025, 4:38 PM + */ +#include +#define _XTAL_FREQ 8000000 + +// Configuration bits +#pragma config FOSC = INTOSCIO // Internal oscillator +#pragma config WDTE = OFF // Watchdog disabled +#pragma config PWRTE = OFF // Power-up Timer disabled +#pragma config MCLRE = OFF // MCLR pin as digital input +#pragma config CP = OFF // Code protection off +#pragma config CPD = OFF // Data code protection off +#pragma config BOREN = OFF // Brown-out Reset disabled +#pragma config IESO = OFF // Internal/External Switchover disabled +#pragma config FCMEN = OFF // Fail-Safe Clock Monitor disabled + +void main(void) { + // Set internal oscillator calibration + OSCCON = 0x70; // Set internal oscillator to 8MHz + + TRISIO = 0b00000010; // GP1 as input, GP2 as output + ANSEL = 0b00000010; // AN1 (GP1) as analog input + + // ADC Configuration + ADCON0 = 0x85; // Enable ADC, select AN1, ADC clock = Fosc/32 + //ADCON0 = 0x80; // Right-justified result, ADC clock source bits + + // PWM Configuration + PR2 = 0xFF; // PWM period (255 + 1) * 4 * 0.5us * 1 = 512us (~1.95kHz) + CCP1CON = 0x0C; // PWM mode + T2CON = 0x04; // Timer2 on with prescaler 1:1 + + while(1) { + // Start ADC conversion + ADCON0bits.GO = 1; + char adc = ADCON0; + ADCON0 =adc; + while(ADCON0bits.GO); // Wait for conversion + + // Read 10-bit ADC result + unsigned int adc_value = ((ADRESH & 0x03) << 8) | ADRESL; + + // Set PWM duty cycle + CCPR1L = adc_value >> 2; // Upper 8 bits + + CCP1CONbits.DC1B = adc_value & 3; // Lower 2 bits + char ccp = CCP1CON; + ccp = CCP1CON; + + __delay_ms(10); // Sampling delay + } +} \ No newline at end of file diff --git a/nbproject/configurations.xml b/nbproject/configurations.xml new file mode 100644 index 0000000..00445db --- /dev/null +++ b/nbproject/configurations.xml @@ -0,0 +1,170 @@ + + + + + + + + + main.c + + + Makefile + + + Makefile + + + + localhost + PIC12F683 + + + PICkit3PlatformTool + XC8 + 2.45 + 3 + + + + + + + + + + + + + + + false + false + + + + + + + false + false + + false + + false + false + false + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/nbproject/project.xml b/nbproject/project.xml new file mode 100644 index 0000000..e330395 --- /dev/null +++ b/nbproject/project.xml @@ -0,0 +1,23 @@ + + + com.microchip.mplab.nbide.embedded.makeproject + + + 16f683 pwm control + d50dfb0b-7f19-40bd-935f-2ffb0003e117 + 0 + UTF-8 + + + + + default + 2 + + + + false + + + +