/Designs/Laboratory_instruments/High_voltage_power_supply/SW/VN/vn.c |
---|
0,0 → 1,82 |
#include "D:\PIC\VN\vn.h" |
//#define MAXDUTY (int16)160 // 50 kHz |
#define MAXDUTY (int16)400 // 20 kHz |
//#define MAXDUTY (int16)800 // 10 kHz |
#define HALFDUTY (int16)MAXDUTY/2 |
//#define DIVISOR 199 // 10 kHz |
#define DIVISOR 99 // 20 kHz |
//#define DIVISOR 39 // 50 kHz |
#define regreseM (2.02) |
#define regreseN (-451) |
void main() |
{ |
setup_adc_ports(sAN0|VSS_VDD); |
setup_adc(ADC_CLOCK_DIV_2); |
setup_spi(SPI_SS_DISABLED); |
setup_timer_0(RTCC_INTERNAL|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(HALFDUTY); |
set_pwm2_duty(MAXDUTY); |
setup_comparator(NC_NC_NC_NC); |
setup_oscillator(OSC_8MHZ); |
set_adc_channel(0); |
delay_ms(500); |
unsigned int16 reg; |
float given; |
printf("Cvak\r\n"); |
reg=400; |
given=regreseM*reg+regreseN; |
while(true) |
{ |
unsigned int16 value; |
value = read_adc(); |
if(kbhit()) |
{ |
char c; |
set_pwm2_duty((int16)MAXDUTY); |
c=getc(); |
if(c=='u') |
{ |
if (reg<600) reg++; |
printf("up*"); |
} |
if(c=='d') |
{ |
if (reg>250) reg--; |
printf("down*"); |
} |
if((c>='a')&&(c<='z')) |
{ |
given=regreseM*reg+regreseN; |
printf("reg: %Lu\r\n",reg); |
} |
} |
if (value >= given) |
{ |
set_pwm2_duty((int16)MAXDUTY); |
} |
else |
{ |
set_pwm2_duty((int16)255); |
} |
delay_us(200); |
} |
} |
/Designs/Laboratory_instruments/High_voltage_power_supply/SW/VN/vn.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=1200,parity=N,xmit=PIN_B7,rcv=PIN_B6,bits=8,stop=1) |
/Designs/Laboratory_instruments/High_voltage_power_supply/SW/VN/vn.pjt |
---|
0,0 → 1,26 |
[PROJECT] |
Target=D:\PIC\VN\vn.hex |
Development_Mode= |
Processor_Text=PIC16F887 |
ToolSuite=CCS |
Processor=0x887F |
[D:\PIC\VN\vn] |
Type=4 |
Path= |
FileList= |
BuildTool= |
OptionString= |
AdditionalOptionString= |
[mru-list] |
1=D:\PIC\VN\vn.c |
[Windows] |
0=0000 %S 0 0 796 451 3 0 |
[Units] |
Link=0 |
Count=1 |
1=D:\PIC\VN\vn |
[Opened Files] |
1=vn.c |
2=vn.h |
3=C:\Program Files (x86)\PICC\devices\16F887.h |
4= |