/Designs/Measuring_instruments/ACOUNTER02A/SW/PIC16F887/acounter.c
0,0 → 1,103
//*** Atomic counter up to 800 MHz ***
#include "acounter.h"
#include <string.h>
 
#define LED PIN_C1 //CHANGE PIN_XX TO YOUR LED PIN NUMBER, EX: PIN_A5
#define SEL0 PIN_E0 // external counter division ratio
#define SEL1 PIN_E1 // external counter division ratio
#define MR PIN_E2 // external counter master reset
#define CLKI PIN_C0 // internal counter input
#define BEEP PIN_C3 // buzzer
 
// LCD definitions
#define LCD_ENABLE_PIN PIN_D4 ////
#define LCD_RS_PIN PIN_D6 ////
#define LCD_RW_PIN PIN_D5 ////
#define LCD_DATA4 PIN_D0 ////
#define LCD_DATA5 PIN_D1 ////
#define LCD_DATA6 PIN_D2 ////
#define LCD_DATA7 PIN_D3
#include <lcd.c>
 
int16 of=0; // count of overflow
int1 flag; // flag for a blinking dot
 
#int_EXT // Interrupt from 1PPS
void EXT_isr(void)
{
unsigned int16 countH;
unsigned int8 countL;
unsigned int32 count;
char countS[10], a[4], b[4], c[4]; // strings for printing results
countL=0;
countH=get_timer1(); // read internal counter
output_low(SEL0);
output_low(SEL1);
countL=input(CLKI); // read bit 0 of external counter
output_high(SEL0);
output_low(SEL1);
countL|=input(CLKI)<<1; // read bit 1 of external counter
output_low(SEL0);
output_high(SEL1);
countL|=input(CLKI)<<2; // read bit 2 of external counter
output_high(SEL0);
output_high(SEL1);
countL|=input(CLKI)<<3; // read bit 3 of external counter
 
output_low(MR); // External counter Master Reset
output_high(MR);
set_timer1(0); // Internal counter reset
count=((unsigned int32)of<<20)+((unsigned int32)countH<<4)+(unsigned int32)countL; // concatenate
 
sprintf(countS,"%09Lu", count); // engeneering values conversion
strncpy(a, countS, 3); a[3]='\0';
strncpy(b, &countS[3], 3); b[3]='\0';
strncpy(c, &countS[6], 3); c[3]='\0';
printf("%s\r\n", countS); // output to RS232
if(flag==0){lcd_putc("\fCvak... \n"); flag=1;} else {lcd_putc("\fCvak....\n"); flag=0;};
printf(lcd_putc, "%s %s %s Hz\n", a, b, c); // output to LCD
 
output_toggle(BEEP); // cvak...
 
of=0; // reset overflow counter
}
 
#int_TIMER1 // Interrupf from overflow
void TIMER1_isr(void)
{
of++;
}
 
void main()
{
 
setup_adc_ports(NO_ANALOGS|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_EXTERNAL|T1_DIV_BY_1);
setup_timer_2(T2_DISABLED,0,1);
setup_ccp1(CCP_OFF);
setup_comparator(NC_NC_NC_NC);// This device COMP currently not supported by the PICWizard
 
output_toggle(BEEP); // cvak...
printf("Cvak....");
ext_int_edge( L_TO_H ); // set 1PPS active edge
enable_interrupts(INT_TIMER1);
enable_interrupts(INT_EXT);
enable_interrupts(GLOBAL);
 
lcd_init();
 
lcd_putc("\fCvak...\nHmmm...\n");
 
while(true)
{
}
 
}
/Designs/Measuring_instruments/ACOUNTER02A/SW/PIC16F887/acounter.h
0,0 → 1,20
#include <16F887.h>
#device adc=8
 
#FUSES NOWDT //No Watch Dog Timer
#FUSES HS //High speed Osc (> 4mhz for PCM/PCH) (>10mhz for PCD)
#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=20000000)
#use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8,errors)
 
/Designs/Measuring_instruments/ACOUNTER02A/SW/PIC16F887/acounter.hex
0,0 → 1,207
:1000000005308A00862D0000FF00030E8301A10049
:100010000A08A0008A010408A2007708A300780853
:10002000A4007908A5007A08A600831383120B1E8A
:100030001B288B1832288C308400001C21280C18B7
:100040003528220884002308F7002408F800250832
:10005000F9002608FA0020088A00210E8300FF0E0E
:100060007F0E09008A110A12272A8A110A12B72C58
:100070000A108A100A11820728340C34013406341D
:10008000F701F801F901FA01F001F101F201F301C0
:100090006F086E046D046C0403197E282030F40090
:1000A0000310E80DE90DEA0DEB0DF00DF10DF20D69
:1000B000F30D6F087302031D67286E087202031D9B
:1000C00067286D087102031D67286C087002031C05
:1000D00078286C08F0026D08031C6D0FF1026E08A1
:1000E000031C6E0FF2026F08031C6F0FF302031460
:1000F000F70DF80DF90DFA0DF40B5028703084004F
:10010000831308005D08E2005C08E100E0080319C1
:10011000B1285F08FA005E08840083137A188317F9
:1001200080080319B1286208FA006108E10A03197E
:10013000E20AE3007A08E4005F08FA005E08DE0ADB
:100140000319DF0A840083137A1883170008E50077
:100150006308840083136418831765088000E00334
:100160008628E0080319C1286208FA006108E10A3C
:100170000319E20A840083137A1883178001E003CD
:10018000B1285C08F8005D08F9000800831608141F
:1001900088140815881583128816831688120000A3
:1001A000831208168316081200008312E9018316D1
:1001B00008140030831208180130E90483168814EB
:1001C0000030831288180130F7000310F70D77080C
:1001D000E904831608150030831208190130F7006E
:1001E000F70DF70DFC30F7057708E904831688153D
:1001F0000030831288190130F700F70DF70DF70D65
:10020000F830F7057708E9046908F8007808E8008D
:1002100008128316081200008312081683160812AB
:100220001129122900008312E901831608140030F5
:10023000831208180130E9048316881400308312F1
:1002400088180130F7000310F70D7708E9048316CA
:1002500008150030831208190130F700F70DF70D6B
:10026000FC30F7057708E9048316881500308312FF
:1002700088190130F700F70DF70DF70DF830F70585
:100280007708E9046908F8007808E700081283167F
:10029000081208108810081188118312680EF700E0
:1002A000F030F70577086704F800080068185A2945
:1002B00008105B290814831608108312E8186229B5
:1002C00088106329881483168810831268196A2994
:1002D00008116B290815831608118312E819722971
:1002E0008811732988158316881100008312081657
:1002F000831608120330F700F70B7C2983120812CB
:100300008316081283120800831608120813881235
:1003100083120813831608138312C6207808E70097
:10032000E71B8D29E508031D97290813982908174D
:1003300083160813000083128812831688120000A7
:1003400083120812831608128312660EE7000F301C
:10035000E7056708E800562166080F39E700E8005E
:10036000562108006008073A0319C0290B3A0319FF
:10037000D529063A0319EF29023A0319052A0A2A50
:100380000130E100E200620BC629C9294030E300D8
:10039000CA29E30101306102E30763088038E40001
:1003A000E5016408E6008421102AE5010130E60039
:1003B00084210230E10061308400831300080319B6
:1003C000EE290630F800F701F70BE429F80BE329D2
:1003D0007B30F700F70BEA29800BE129102A013066
:1003E000E1000230E200620BF629F9294030E30017
:1003F000FA29E30101306102E30763088038E40071
:10040000E5016408E6008421102AE5011030E600C9
:100410008421102A0130E5006008E6008421102ABA
:10042000080080080319262ADD010408DC005D109D
:10043000831B5D140008E000B2215C088400831374
:100440005D188317840A0319850A112A0800C1015F
:100450000F08FA000E08F7000F087A02031D282A79
:100460007708BF007A08C0008316091083120910AC
:1004700083168910831289102E142E088316870084
:100480008312C1010718C10A8316091083120914C7
:1004900083168910831289102E142E088316870064
:1004A0000030831207180130F7000310F70D7708AA
:1004B000C104831609108312091083168910831250
:1004C00089142E142E088316870000308312071813
:1004D0000130F700F70DF70DFC30F7057708C10480
:1004E0008316091083120914831689108312891444
:1004F0002E142E088316870000308312071801304F
:10050000F700F70DF70DF70DF830F7057708C10480
:100510008316091183120911831609118312091513
:100520008F018E01DF01DE012C08DD002B08DC00CD
:100530002C08DF002B08DE00DC01DD01DE0DDF0D05
:10054000DE0DDF0DDE0DDF0DDE0DDF0DF030DE0523
:10055000E401E3013F0DF700400DF800630DF900E1
:10056000640DFA00F70DF80DF90DFA0DF70DF80D01
:10057000F90DFA0DF70DF80DF90DFA0DF030F7053C
:100580007708DC0778080318780FDD077908031867
:10059000790FDE077A0803187A0FDF07F801F901EF
:1005A000FA0141085C07C2005D08C300780803181F
:1005B000780FC3075E08C40079080318790FC407D1
:1005C0005F08C5007A0803187A0FC507B0014630E6
:1005D000AF00493084004508DF004408DE004308CE
:1005E000DD004208DC000408E0003B30E7009A3000
:1005F000E600CA30E500E4010A30E2005F08EB00E3
:100600005E08EA005D08E9005C08E8006708EF00A2
:100610006608EE006508ED006408EC0040207808EC
:100620000008DC00840A0008DD00840A0008DE00FF
:10063000840A0008DF00FD308407F708031D332B10
:100640006208013A0319332B60080319342B0F3960
:10065000620203192D2B0318442BE01B442B601B53
:10066000342B2030352BE0013030F7077708E800D5
:100670002F08840083133018831768088000840AC9
:100680008001AF0A0319B00A6708EB006608EA00A8
:100690006508E9006408E800EF01EE01ED010A30A9
:1006A000EC0040207A08E7007908E6007808E500C9
:1006B0007708E400E20BFE2ADD015030DC00DF01A8
:1006C0004630DE000330E0008220D301DD015430EB
:1006D000DC00DF014930DE000330E0008220D7017A
:1006E000DD015830DC00DF014C30DE000330E0007B
:1006F0008220DB0146308400831380080319932B8A
:10070000DD010408DC005D10831B5D1400080C1E75
:10071000872B99005C08840083135D188317840A73
:100720000319850A7D2B0D300C1E942B99000A307D
:100730000C1E982B99002D18E62BA43003178D0062
:1007400004308F0083168C170C14000000008312F5
:100750000C087F390319E32B0313DC0003170D0882
:100760000313DD0003170F080313DE005C08E0002D
:10077000B2215D0803178D0003135E0803178F0075
:1007800083168C170C140000000083120C0D0E0D44
:100790007F390319E32B0313DC0003170D08031340
:1007A000DD0003170F080313DE005C08E000B22130
:1007B0005D0803178D0003135E0803178F008D0A71
:1007C00003198F0AA22B03132D142E2CAA30031702
:1007D0008D0004308F0083168C170C14000000006D
:1007E00083120C087F3903192C2C0313DC00031728
:1007F0000D080313DD0003170F080313DE005C0868
:10080000E000B2215D0803178D0003135E08031793
:100810008F0083168C170C140000000083120C0D3F
:100820000E0D7F3903192C2C0313DC0003170D0860
:100830000313DD0003170F080313DE005C08E0005C
:10084000B2215D0803178D0003135E0803178F00A4
:100850008D0A03198F0AEB2B03132D1050308400DF
:10086000831311222030E000B2215430840083131E
:1008700011222030E000B22158308400831311226D
:10088000B43003178D0004308F00031004300313BD
:10089000DC00831603178C170C14000000000318EB
:1008A000782C83120C087F390313DD0003170D0821
:1008B0000313DE0003170F080313DF005D08E000D9
:1008C000B2215E0803178D0003135F0803178F0022
:1008D00083168C170C140000000083120313DC0B2A
:1008E000722C752C83160317782C972C83160317FC
:1008F00083120C0D0E0D7F390313DD0003170D0855
:100900000313DE0003170F080313DF005D08E00088
:10091000B2215E0803178D0003135F0803178F00D1
:100920008D0A03198F0A03100313DC0B492CAE1137
:100930002E0883168700083083128706AC01AB01AE
:100940008B108A110A1221288C21F6306B172E1772
:10095000200500008C21F6306B172E172E050001A4
:10096000A539A0127310A53920247A050000AB0A1E
:100970000319AC0A0C108A110A122128433BE135F5
:100980002E172E1700008C21F6306B172E170A2415
:10099000ED366D172E170A00831603178C170C14EB
:1009A0000000000083120C087F390319122D031375
:1009B000B10003170D080313B20003170F08031348
:1009C000B30031080C1EE22C9900320803178D0089
:1009D0000313330803178F0083168C170C140000C1
:1009E000000083120C0D0E0D7F390319122D031315
:1009F000B10003170D080313B20003170F08031308
:100A0000B30031080C1E022D9900320803178D0027
:100A10000313330803178F008D0A03198F0A03137A
:100A2000CC2C031703138A110A12052E8316081003
:100A300088100811881108120813881283120813ED
:100A400083160813831288128316881283120812E1
:100A5000831608120F308312E10061308400831383
:100A600000080319402D0630F800F701F70B362D6A
:100A7000F80B352D7B30F700F70B3C2D800B332D19
:100A80000130B1003108033C031C662DA7018B1B0C
:100A9000A7178B130330E8005621A71B8B170530CF
:100AA000E10061308400831300080319642D0630CF
:100AB000F800F701F70B5A2DF80B592D7B30F70092
:100AC000F70B602D800B572DB10A422DA7018B1B10
:100AD000A7178B130230E8005621A71B8B17B10113
:100AE0003108033C031C832D31083820B200A701D4
:100AF0008B1BA7178B13E5013208E6008421A71B87
:100B00008B17B10A702D8A110A120D2E84018313DE
:100B10001F308305831603178715083003139900C8
:100B200002309A00A6309800903083129800AC01F1
:100B3000AB01831603170908C039890003131F127C
:100B40009F120030031788008312870188018901F2
:100B50000313A801A901AA01FF30AE00AF01B00143
:100B6000831603170908C039890003131F129F1247
:100B7000003003178800831203131F139F1383167B
:100B80009F1383121F149412AE122E08831687002F
:100B900083122E162E08831687008312AE112E089C
:100BA000831687000130831294000030831694006E
:100BB0000108C739083881000730831290000030DF
:100BC000F800920000308316920083122E152E0832
:100BD000831687008312970183169B019C010130C5
:100BE0009D00831203178701880189010313AE1149
:100BF0002E0883168700083083128706BE3003173D
:100C00008D0004308F000313CC2C831601170C14B5
:100C100083120B16C0308B04162DC33003178D00C2
:100C200004308F0083168C170C1400000000831210
:100C30000C087F390319532E0313DC0003170D082A
:100C40000313DD0003170F080313DE005C08E00048
:100C5000B2215D0803178D0003135E0803178F0090
:100C600083168C170C140000000083120C0D0E0D5F
:100C70007F390319532E0313DC0003170D080313E8
:100C8000DD0003170F080313DE005C08E000B2214B
:100C90005D0803178D0003135E0803178F008D0A8C
:0A0CA00003198F0A122E532E630071
:04400E00F22CFF3F52
:00000001FF
;PIC16F887
;CRC=A46F CREATED="12-I-14 18:39"
/Designs/Measuring_instruments/ACOUNTER02A/SW/PIC16F887/acounter.pjt
0,0 → 1,28
[PROJECT]
Target=D:\PIC\acounter\acounter.hex
Development_Mode=
Processor_Text=PIC16F887
ToolSuite=CCS
Processor=0x887F
[D:\PIC\acounter\acounter]
Type=4
Path=
FileList=
BuildTool=
OptionString=
AdditionalOptionString=
[mru-list]
1=D:\PIC\acounter\acounter.c
[Windows]
0=0000 %S 0 0 796 451 3 0
[Units]
Link=0
Count=1
1=D:\PIC\acounter\acounter
[Opened Files]
1=acounter.c
2=
3=C:\Program Files (x86)\PICC\devices\16F887.h
4=..\counter\main.c
5=C:\Program Files (x86)\PICC\examples\ex_str.c
6=