Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //================================================
- procedure TMR6_Initialize();
- begin
- // Set TMR6 to the options selected in the User Interface
- // T6CS LFINTOSC 32kHz;
- T6CLKCON := %00000100;
- // T6PSYNC Not Synchronized; T6MODE Software control; T6CKPOL Rising Edge; T6CKSYNC Not Synchronized;
- T6HLT := %00000000;
- // T6RSEL T6CKIPPS pin;
- T6RST := %00000000;
- // PR6 255;
- T6PR := %11111111;
- // TMR6 0;
- T6TMR := %00000000;
- // Clearing IF flag.
- PIR9.TMR6IF := 0;
- // T6CKPS 1:32; T6OUTPS 1:1; TMR6ON on;
- T6CON := %11110000;
- // T6CKPS 1:16; T6OUTPS 1:1; TMR6ON on;
- //T6CON := 0xC0;
- // Start the Timer by writing to TMRxON bit
- T6CON.TMR6ON := 1;
- TMR6IE_bit := 1;
- end;
- //================================================
- procedure ADCC_Initialize();
- begin
- // set the ADCC to the options selected in the User Interface
- // ADLTH 0;
- ADLTHL := 0x00;
- // ADLTH 0;
- ADLTHH := 0x00;
- // ADUTH 0;
- ADUTHL := 0x00;
- // ADUTH 0;
- ADUTHH := 0x00;
- // ADSTPT 0;
- ADSTPTL := 0x00;
- // ADSTPT 0;
- ADSTPTH := 0x00;
- // ADACC 0;
- ADACCU := 0x00;
- // ADRPT 0;
- ADRPT := 0x00;
- // ADPCH ANA0;
- ADPCH := 0x00;
- // ADACQ 0;
- ADACQL := 0x01;
- // ADACQ 0;
- ADACQH := 0x00;
- // ADCAP Additional uC disabled;
- ADCAP := 0x00;
- // ADPRE 0;
- ADPREL := 0x00;
- // ADPRE 0;
- ADPREH := 0x00;
- // ADDSEN disabled; ADGPOL digital_low; ADIPEN disabled; ADPPOL Vss;
- ADCON1 := 0x00;
- // ADCRS 0; ADMD Average_mode; ADACLR disabled; ADPSIS RES;
- ADCON2 := 0x02;
- // ADCALC First derivative of Single measurement; ADTMD disabled; ADSOI ADGO not cleared;
- ADCON3 := 0x00;
- // ADMATH registers not updated;
- ADSTAT := 0x00;
- // ADNREF VSS; ADPREF VDD;
- ADREF := 0x00;
- // ADACT TMR6;
- ADACT := 0x08;
- // ADCS FOSC/2;
- ADCLK := 0x00;
- // ADGO stop; ADFM right; ADON enabled; ADCS Frc; ADCONT enabled;
- ADCON0 := 0xD4;
- // Clear the ADC interrupt flag
- PIR1.ADIF := 0;
- // Enabling ADCC interrupt.
- PIE1.ADIE := 1;
- end;
- //================================================
- procedure ADCC_Start(channel:byte);
- begin
- // select the A/D channel
- ADPCH := channel;
- // Turn on the ADC module
- ADCON0.ADON := 1;
- // Start the conversion
- ADCON0.ADGO := 1;
- end;
- //================================================
- procedure Interrupt;
- begin
- if (PIR1.ADIF = 1) then
- //if (PIR9.TMR6IF = 1) then
- begin
- SetBit(LATC,5);
- Inc(poc);
- rv_an0 := ADRESH shl 8 + ADRESL;
- rv_an0_flt := ADFLTRH shl 8 + ADFLTRL;
- rv_an0_acc := ADACCH shl 8 + ADACCL;
- SendRS_word(poc);UART1_Write_Text('....');
- SendRS_byte(ADCNT);UART1_Write_Text('....');
- SendRS_word(rv_an0);UART1_Write_Text('....');
- SendRS_word(rv_an0_acc);UART1_Write_Text('....');
- SendRS_word(rv_an0_flt);UART1_Write_Text('....');
- Uart1_CRLF;
- ClearBit(LATC,5);
- //Delay_ms(25);
- ClearBit(PIR1, ADIF);
- //ClearBit(PIR9,TMR6IF);
- end;
- end;
- //================================================
- begin
- TRISC :=%10000000;
- LATC :=0;
- LATB :=0;
- TRISB :=%00000000;
- TRISA :=%11111111;
- ANSELA :=%00001111; //AN0-3 nastavim jako analog
- ANSELB :=%00000000; //vse digi
- ANSELC :=%00000000; //vse digi
- U1CON0 :=%00110000;
- UART1_Init(57600); // Initialize UART module at 19200 bps
- UART_Set_Active(@UART1_Read, @UART1_Write, @UART1_Data_Ready, @UART1_Tx_Idle); // set UART1 active
- TMR6_Initialize();
- ADCC_Initialize;
- poc:=0;
- GIE_bit := 1;
- ADCC_Start(0);
- while (TRUE) do
- begin
- end;
- end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement