Problem with comparison.
/Designs/Measuring_instruments/GM_counter/SW/HV_source/main.c
0,0 → 1,172
#include ".\main.h"
 
#define LED1 PIN_C6 //CHANGE PIN_XX TO YOUR LED PIN NUMBER, EX: PIN_A5
#define LED2 PIN_C5 //CHANGE PIN_XX TO YOUR LED PIN NUMBER, EX: PIN_A5
#define LED3 PIN_C4 //CHANGE PIN_XX TO YOUR LED PIN NUMBER
#define LED4 PIN_D3 //CHANGE PIN_XX TO YOUR LED PIN NUMBER
 
#define S1 PIN_B0 //Raw up
#define S2 PIN_B1 //Raw down
#define S3 PIN_D0 //Fine up
#define S4 PIN_D1 //Fine down
 
#define BEEP PIN_D2 //piezo beeper
 
#define LCD_ENABLE_PIN PIN_E0 ////
#define LCD_RS_PIN PIN_E1 ////
#define LCD_RW_PIN PIN_E2 ////
#define LCD_DATA4 PIN_D4 ////
#define LCD_DATA5 PIN_D5 ////
#define LCD_DATA6 PIN_D6 ////
#define LCD_DATA7 PIN_D7
#include <lcd.c>
 
#define OUTPUT_ENABLE PIN_C1
 
 
//#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 sound_beep( unsigned int lenght, int16 frequency)
{
unsigned int i;
for(i=0;i<=lenght;i++)
{
output_toggle(BEEP);
delay_us(1/frequency);
}
}
 
void main()
{
unsigned int16 setpoint=43;
unsigned int16 napeti;
unsigned int1 button_press; // semafor pro cteni tlacitek
 
setup_adc_ports(sAN0|VSS_VDD);
setup_adc(ADC_CLOCK_DIV_2);
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(HALFDUTY);
set_pwm2_duty(MAXDUTY);
setup_comparator(NC_NC_NC_NC);// This device COMP currently not supported by the PICWizard
setup_oscillator(OSC_8MHZ);
 
// set_pwm1_duty(0);
// set_pwm2_duty(0);
 
output_high(LED1);
output_high(LED2);
output_high(LED3);
output_high(LED4);
output_low(BEEP);
 
lcd_init();
set_adc_channel(0);
lcd_gotoxy(1,1);
lcd_putc("HVPS01A");
lcd_gotoxy(1,2);
lcd_putc(" MLAB.cz");
Delay_ms(1000);
lcd_putc("\f");
 
while(true)
{
napeti = read_adc();
if(input(OUTPUT_ENABLE))
{
if (napeti <= setpoint)
{
set_pwm2_duty((int16)255); // zapnuti menice
output_low(LED2);
}
else // vypnuti menice
{
set_pwm2_duty((int16)MAXDUTY);
output_high(LED2);
}
 
}
else
{
set_pwm2_duty((int16)MAXDUTY);
output_high(LED2);
}
lcd_gotoxy(1,1);
printf(lcd_putc,"%4lu",napeti);
lcd_gotoxy(1,2);
 
if(input(OUTPUT_ENABLE))printf(lcd_putc,"Set:%lu "setpoint);
else printf(lcd_putc,"DISABLED");
 
if(button_press==false ) // tlacitka se ctou znovu pouze pokud v redchozim cyklu nebyla zmacknuta.
{
if(!input(S1))
{
delay_ms(20);
if(!input(S1))
{
button_press=true;
sound_beep(100,700);
if(setpoint < (1023-5) )setpoint+=5;
}
}
 
if(!input(S2))
{
delay_ms(20);
if(!input(S2))
{
button_press=true;
sound_beep(100,600);
if(setpoint > 0x05 ) setpoint-=5;
}
}
 
if(!input(S3))
{
delay_ms(20);
if(!input(S3))
{
button_press=true;
sound_beep(100,500);
if(setpoint < 1023 )setpoint++;
}
}
 
if(!input(S4))
{
delay_ms(20);
if(!input(S4))
{
button_press=true;
sound_beep(100,400);
if(setpoint > 0x00 ) setpoint--;
}
}
}
if ( input(S1) && input(S2) && input(S3) && input(S4) ) button_press=false;
output_toggle(LED1);
}
 
}
/Designs/Measuring_instruments/GM_counter/SW/HV_source/main.hex
0,0 → 1,153
:1000000002308A00BB2A00000A108A100A118207F7
:1000100028340C3401340634482BD029B018410060
:10002000A026CC204217633D00010C00D332741D82
:100030002536751020100000C424D3204226452206
:100040000000303084008313000803193428023084
:10005000F800F701F70B2A28F80B29289730F7004A
:10006000F70B3028800B272808003718392808128A
:100070003A280816831608128312B71841288812E6
:1000800042288816831688128312371949280813C4
:100090004A280817831608138312B71951288813A2
:1000A00052288817831688130000831209148316B8
:1000B00009105A285B28831209108316091083122D
:1000C0000800B8018316081600308312081A0130A0
:1000D000B8048316881600308312881A0130F7009E
:1000E0000310F70D7708B804831608170030831241
:1000F000081B0130F700F70DF70DFC30F705770806
:10010000B8048316881700308312881B0130F7006B
:10011000F70DF70DF70DF830F7057708B804380834
:10012000F80008008316091089100911831289103C
:100130008316891008168816081788178312091560
:100140008316091100008312091483160910000098
:10015000831261207808B700091083160910000087
:100160008312091483160910B528831261207808B8
:10017000B600091083160910081288120813881394
:100180008312370EF700F030F70577083604F800D1
:100190007808B600B61FCE2883169A28B408031D27
:1001A000D3288910D428891483168910000083125B
:1001B0000911831609110000831209108316091012
:1001C0008312350EB6000F30B6053608B70035205D
:1001D00035080F39B600B70035200800831608121D
:1001E00088120813881309108910091183128910C5
:1001F00083168910831209118316091183120910BD
:10020000831609100F308312B00021200130A600A0
:100210002608033C031C14290330B70035200530A1
:10022000B0002120A60A08290230B7003520A60117
:100230002608033C031C252926080420A700B40136
:100240002708B5009220A60A18298A110A125B2BEA
:10025000310B2B292E294030B2002F29B201013059
:100260003002B20732088038B300B4013308B50059
:10027000922008002F08073A031948290B3A03195E
:100280004D29063A03195529023A03195B296029B9
:100290000130B000B10028216629B4010130B50059
:1002A00092200230B000212066290130B0000230D7
:1002B000B10028216629B4011030B50092206629CA
:1002C0000130B4002F08B50092206629080083167B
:1002D00003178C170C140000000083120C087F39E0
:1002E0000319AB290313A60003170D080313A70076
:1002F00003170F080313A8002608AF003A212708A8
:1003000003178D000313280803178F0083168C171B
:100310000C140000000083120C0D0E0D7F39031920
:10032000AB290313A60003170D080313A700031737
:100330000F080313A8002608AF003A212708031767
:100340008D000313280803178F008D0A03198F0AE5
:1003500003136729031703130800AE010408AD0057
:100360002E10831B2E14270EF038A900A907E23E99
:10037000AA00323EAC0027080F39AA07AA07AC072B
:10038000E93EAB00AB07AB07260E0F39AB07AC0756
:10039000AB0DAC0DAC09AC0D26080F39AC07A90D9F
:1003A0000730A8000A30AC07AB03031CD329AB0706
:1003B000AA03031CD729AA07A903031CDB29A90741
:1003C000A803031CDF2928308400831307302D0580
:1003D0002D1384072C30040203192D170008F70091
:1003E000031DFA292D1BFA292D1A0C2AAD19FA29F9
:1003F0002030FD29AD152D123030F707A701040874
:10040000A6002710831B27147708AF003A2126087F
:100410008400831327188317840A2D1FEA290800F4
:10042000831603178C170C140000000003183F2AD2
:1004300083120C087F390313A70003170D08031359
:10044000A80003170F080313A9002708AF003A21DB
:10045000280803178D000313290803178F0083163C
:100460008C170C140000000083120313A60B392A0A
:100470003C2A831603173F2A5E2A8316031783122A
:100480000C0D0E0D7F390313A70003170D0803137E
:10049000A80003170F080313A9002708AF003A218B
:1004A000280803178D000313290803178F008D0AEE
:1004B00003198F0A03100313A60B102A8A110A12BC
:1004C000E52B0830AD02031C712A2D308400831304
:1004D0000310800C00080319712A6F2A0000800B9A
:1004E0006E2A0800A90129082602031CBA2A8316CD
:1004F0000811043083128806AB010130AA002808D5
:10050000AD002708AC00F801F901F701FA012D0848
:10051000031D8D2A2C080319A72A1030AE000310E2
:10052000AA0DAB0DF70DFA0D2D087A02031D9A2ABC
:100530002C087702031CA32A2C08F702031CFA03D9
:100540002D08FA020314F80DF90DAE0B8F2A790865
:10055000AB007808AA002B08AC00AC0AAC03031966
:10056000B52AFF30AD006122AE2A2A08AD00612213
:10057000A90A732A0800840183131F308305713090
:1005800083168F000F0806138312061783160317AE
:100590000908C039890003131F129F120030031786
:1005A00088008312870188018901FF300313A000AE
:1005B000A2012B30A100831603170908C039890056
:1005C00003131F129F1201300317880083120313B5
:1005D0001F139F1383169F1783121F149412A012C8
:1005E00020088316870083122016200883168700B0
:1005F0008312A01120088316870001308312940013
:100600000030831694000108C7392838810083120E
:1006100090010030F8000438920063308316920095
:100620008312201120088316870083120711831676
:1006300009130C308312970083169B019C01013033
:100640009D008312A0102008831687008312871054
:100650000C309D0001308000323095001708CF39F2
:10066000970064309B001D08CF399D000317870158
:10067000880189017130831603138F000F088312DC
:10068000201320088316870083120717A012200862
:10069000831687008312871620122008831687008E
:1006A0008312071683168811831288158316081182
:1006B00083120811EE280030F8001F08C3397804AF
:1006C0009F000130B000B10028210C3003178D00CD
:1006D00000308F00031367210130B0000230B100F9
:1006E0002821103003178D0000308F00031367217D
:1006F0000430A600FA30B0002120A60B7A2B15306A
:1007000003178D0000308F00031367219F149F187B
:10071000872B83161E088312A3001E08A400A014B2
:100720002008831687008312871CB92B2408220215
:10073000031CAD2B031DA02B23082102031CAD2B92
:100740003F309B001D08CF3930389D00A012200893
:100750008316870083128712B82B64309B001D0814
:10076000CF399D00A01220088316870083128716B8
:10077000C42B64309B001D08CF399D00A0122008B7
:1007800083168700831287160130B000B10028213C
:10079000013084002408A7002308A600AD21013001
:1007A000B0000230B1002821A01420088316870071
:1007B0008312871CF62B163003178D0000308F0034
:1007C000031004300313A600102A103084002208FE
:1007D000A7002108A600AD212030AF003A2120302B
:1007E000AF003A212030AF003A21FD2B1C30031717
:1007F0008D0000308F00031367212518852C831688
:10080000061483120618222C1430B00021208316FF
:10081000061483120618222C25146430A600023018
:10082000A800BC30A70072222208033C031C222C23
:10083000031D1E2C2108F93C031C222C0530A107A6
:100840000318A20A8316861483128618442C1430C7
:10085000B00021208316861483128618442C251498
:100860006430A6000230A8005830A7007222A20807
:10087000031D3E2C2108053C0318442C0530A10221
:100880000030031C0130A2028316081483120818DA
:10089000662C1430B0002120831608148312081827
:1008A000662C25146430A6000130A800F430A7009F
:1008B00072222208033C031C662C031D632C2108B2
:1008C000FE3C031C662CA10A0319A20A8316881495
:1008D00083128818852C1430B000212083168814C8
:1008E00083128818852C25146430A6000130A800D6
:1008F0009030A7007222A108031D812CA2080319C1
:10090000852C21080319A203A10383160614831260
:10091000061C992C831686148312861C992C831628
:1009200008148312081C992C8316881483128818C3
:100930002510201320088316870040308312870675
:04094000862B63009F
:04400E00F52CFF3F4F
:00000001FF
;PIC16F887
;CRC=7CE0 CREATED="23-IX-13 00:21"
/Designs/Measuring_instruments/GM_counter/SW/HV_source/main.pjt
0,0 → 1,29
[PROJECT]
Target=D:\MLAB\Designs\Measuring_instruments\GM_counter\SW\main.hex
Development_Mode=
Processor_Text=PIC16F887
ToolSuite=CCS
Processor=0x887F
[D:\MLAB\Designs\Measuring_instruments\GM_counter\SW\main]
Type=4
Path=
FileList=
BuildTool=
OptionString=
AdditionalOptionString=
[mru-list]
1=D:\MLAB\Designs\Measuring_instruments\GM_counter\SW\main.c
[Windows]
0=0000 %S 0 0 796 451 3 0
[Opened Files]
1=main.c
2=
3=C:\Program Files (x86)\PICC\devices\16F887.h
4=C:\Program Files (x86)\PICC\drivers\lcd.c
5=
[Target Data]
OptionString=-p +FM
FileList=Z:\home\kaklik\svnMLAB\Designs\Measuring_instruments\GM_counter\SW\HV_source\main.c
[Units]
Count=1
1=main (main)
/Designs/Measuring_instruments/GM_counter/SW/HV_source/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)