/Designs/Laboratory_instruments/HVlamp/SW/PIC16F887/main.c
0,0 → 1,78
#include ".\main.h"
 
 
//#define MAXDUTY (int16)160 // 50 kHz
//#define MAXDUTY (int16)400 // 20 kHz
//#define MAXDUTY (int16)800 // 10 kHz
#define MAXDUTY (int16)1023 // 7.8 kHz
#define HALFDUTY (int16)MAXDUTY/2
#define DIVISOR 255 // 7.8 kHz
//#define DIVISOR 199 // 10 kHz
//#define DIVISOR 99 // 20 kHz
//#define DIVISOR 39 // 50 kHz
 
void main()
{
int16 reg=MAXDUTY;
int16 current;
int16 counter=0;
int16 avg=0;
setup_adc_ports(sAN0|VSS_VREF);
setup_adc(ADC_CLOCK_DIV_32);
setup_spi(SPI_SS_DISABLED);
setup_timer_0(RTCC_EXT_L_TO_H|RTCC_DIV_1);
setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DIV_BY_1,DIVISOR,1);
setup_ccp1(CCP_PWM);
setup_ccp2(CCP_PWM);
set_pwm1_duty(MAXDUTY);
set_pwm2_duty(MAXDUTY);
setup_comparator(NC_NC_NC_NC);// This device COMP currently not supported by the PICWizard
setup_oscillator(OSC_8MHZ);
set_adc_channel(0);
delay_ms(1);
while(TRUE)
{
output_low(PIN_D0);
delay_us(40);
output_high(PIN_D0);
delay_ms(3);
}
 
set_pwm2_duty(HALFDUTY);
delay_ms(10);
set_pwm2_duty((int16)850);
// set_pwm2_duty((int16)650);
 
while(TRUE);
while(TRUE)
{
current=read_adc();
if (current<200)
{
if (reg>HALFDUTY) reg--;
}
else
{
if (reg<MAXDUTY) reg++;
}
set_pwm2_duty(reg);
/*
avg=avg/10*9+reg/10;
//delay_ms(5);
if (counter==60000)
{
set_pwm2_duty(avg);
while(TRUE){};
}
counter++;
*/
}
}
/Designs/Laboratory_instruments/HVlamp/SW/PIC16F887/main.h
0,0 → 1,20
#include <16F887.h>
#device adc=10
 
#FUSES NOWDT //No Watch Dog Timer
#FUSES INTRC //Internal RC Osc
#FUSES NOPUT //No Power Up Timer
#FUSES MCLR //Master Clear pin enabled
#FUSES NOPROTECT //Code not protected from reading
#FUSES NOCPD //No EE protection
#FUSES NOBROWNOUT //No brownout reset
#FUSES IESO //Internal External Switch Over mode enabled
#FUSES FCMEN //Fail-safe clock monitor enabled
#FUSES NOLVP //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
#FUSES NODEBUG //No Debug mode for ICD
#FUSES NOWRT //Program memory not write protected
#FUSES BORV40 //Brownout reset at 4.0V
 
#use delay(clock=8000000)
//#use rs232(baud=9600,parity=N,xmit=PIN_B6,rcv=PIN_B7,bits=5)
 
/Designs/Laboratory_instruments/HVlamp/SW/PIC16F887/main.hex
0,0 → 1,37
:1000000000308A001828000029308400831300087B
:10001000031917280230F800F701F70B0D28F80B29
:100020000C289730F700F70B1328800B0A280800DC
:10003000840183131F308305713083168F000F08EE
:1000400003170908C039890003131F129F120030DB
:10005000031788008312870188018901FF30031389
:10006000A0000330A200FF30A100A601A501A80155
:10007000A701831603170908C039890003131F1647
:100080009F12013003178800831203131F139F1759
:1000900083169F1783121F149412A0122008831630
:1000A0008700831220162008831687008312A01170
:1000B00020088316870001308312940000308316D5
:1000C00094000108C739283881008312900100305C
:1000D000F80004389200FF3083169200831220113A
:1000E00020088316870083120711831609130C302A
:1000F0008312970083169B019C0101309D0083129F
:10010000A010200883168700831287100C309D00F2
:1001100001308000FF3095001708CF393038970044
:10012000FF309B001D08CF3930389D000317870131
:10013000880189017130831603138F000F08003086
:10014000F80083121F08C33978049F000130A9000A
:10015000042083160810831208101A30F700F70BDA
:10016000AF28000083160810831208140330A9007A
:100170000420A9287F309B001D08CF3930389D000E
:100180000A30A9000420D4309B001D08CF39203844
:100190009D00C9289F149F18CB2883161E08831220
:1001A000A3001E08A400A408031DE3282308C73CDD
:1001B000031CE3282208013C0318E2282108031944
:1001C000A203A103F0282208033C031CF028031D0E
:1001D000ED282108FE3C031CF028A10A0319A20AFD
:1001E0002208F9002108F800F90CF80CF90CF80CB9
:1001F000F90C78089B00F90C790C3039F7001D08D0
:0A020000CF3977049D00CA2863007F
:04400E00F52CFF3F4F
:00000001FF
;PIC16F887
;CRC=43CA CREATED="18-Jul-14 01:08"