Advertisement
Guest User

Untitled

a guest
Aug 12th, 2019
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pascal 3.94 KB | None | 0 0
  1. //================================================
  2. procedure TMR6_Initialize();
  3. begin
  4.    // Set TMR6 to the options selected in the User Interface
  5.     // T6CS LFINTOSC 32kHz;
  6.     T6CLKCON := %00000100;
  7.     // T6PSYNC Not Synchronized; T6MODE Software control; T6CKPOL Rising Edge; T6CKSYNC Not Synchronized;
  8.     T6HLT := %00000000;
  9.     // T6RSEL T6CKIPPS pin;
  10.     T6RST := %00000000;
  11.     // PR6 255;
  12.     T6PR := %11111111;
  13.     // TMR6 0;
  14.     T6TMR := %00000000;
  15.     // Clearing IF flag.
  16.     PIR9.TMR6IF := 0;
  17.     // T6CKPS 1:32; T6OUTPS 1:1; TMR6ON on;
  18.     T6CON := %11110000;
  19.     // T6CKPS 1:16; T6OUTPS 1:1; TMR6ON on;
  20.     //T6CON := 0xC0;
  21.    // Start the Timer by writing to TMRxON bit
  22.     T6CON.TMR6ON := 1;
  23.     TMR6IE_bit := 1;
  24. end;
  25. //================================================
  26. procedure ADCC_Initialize();
  27. begin
  28.     // set the ADCC to the options selected in the User Interface
  29.     // ADLTH 0;
  30.     ADLTHL := 0x00;
  31.     // ADLTH 0;
  32.     ADLTHH := 0x00;
  33.     // ADUTH 0;
  34.     ADUTHL := 0x00;
  35.     // ADUTH 0;
  36.     ADUTHH := 0x00;
  37.     // ADSTPT 0;
  38.     ADSTPTL := 0x00;
  39.     // ADSTPT 0;
  40.     ADSTPTH := 0x00;
  41.     // ADACC 0;
  42.     ADACCU := 0x00;
  43.     // ADRPT 0;
  44.     ADRPT := 0x00;
  45.     // ADPCH ANA0;
  46.     ADPCH := 0x00;
  47.     // ADACQ 0;
  48.     ADACQL := 0x01;
  49.     // ADACQ 0;
  50.     ADACQH := 0x00;
  51.     // ADCAP Additional uC disabled;
  52.     ADCAP := 0x00;
  53.     // ADPRE 0;
  54.     ADPREL := 0x00;
  55.     // ADPRE 0;
  56.     ADPREH := 0x00;
  57.     // ADDSEN disabled; ADGPOL digital_low; ADIPEN disabled; ADPPOL Vss;
  58.     ADCON1 := 0x00;
  59.     // ADCRS 0; ADMD Average_mode; ADACLR disabled; ADPSIS RES;
  60.     ADCON2 := 0x02;
  61.     // ADCALC First derivative of Single measurement; ADTMD disabled; ADSOI ADGO not cleared;
  62.     ADCON3 := 0x00;
  63.     // ADMATH registers not updated;
  64.     ADSTAT := 0x00;
  65.     // ADNREF VSS; ADPREF VDD;
  66.     ADREF := 0x00;
  67.     // ADACT TMR6;
  68.     ADACT := 0x08;
  69.     // ADCS FOSC/2;
  70.     ADCLK := 0x00;
  71.     // ADGO stop; ADFM right; ADON enabled; ADCS Frc; ADCONT enabled;
  72.     ADCON0 := 0xD4;
  73.  
  74.     // Clear the ADC interrupt flag
  75.     PIR1.ADIF := 0;
  76.     // Enabling ADCC interrupt.
  77.     PIE1.ADIE := 1;
  78.  
  79. end;
  80. //================================================
  81. procedure ADCC_Start(channel:byte);
  82. begin
  83.     // select the A/D channel
  84.     ADPCH := channel;
  85.  
  86.     // Turn on the ADC module
  87.     ADCON0.ADON := 1;
  88.  
  89.     // Start the conversion
  90.     ADCON0.ADGO := 1;
  91. end;
  92. //================================================
  93. procedure Interrupt;
  94. begin
  95.     if (PIR1.ADIF = 1) then
  96.     //if (PIR9.TMR6IF = 1) then
  97.        begin
  98.          SetBit(LATC,5);
  99.          Inc(poc);
  100.          rv_an0                 := ADRESH shl 8 + ADRESL;
  101.          rv_an0_flt             := ADFLTRH shl 8 + ADFLTRL;
  102.          rv_an0_acc             := ADACCH shl 8 + ADACCL;
  103.  
  104.          SendRS_word(poc);UART1_Write_Text('....');
  105.          SendRS_byte(ADCNT);UART1_Write_Text('....');
  106.          SendRS_word(rv_an0);UART1_Write_Text('....');
  107.          SendRS_word(rv_an0_acc);UART1_Write_Text('....');
  108.          SendRS_word(rv_an0_flt);UART1_Write_Text('....');
  109.          Uart1_CRLF;
  110.          ClearBit(LATC,5);
  111.          //Delay_ms(25);
  112.  
  113.          ClearBit(PIR1, ADIF);
  114.          //ClearBit(PIR9,TMR6IF);
  115.        end;
  116. end;
  117. //================================================
  118. begin
  119.   TRISC             :=%10000000;
  120.   LATC              :=0;
  121.   LATB              :=0;
  122.   TRISB             :=%00000000;
  123.   TRISA             :=%11111111;
  124.  
  125.   ANSELA            :=%00001111;  //AN0-3 nastavim jako analog
  126.   ANSELB            :=%00000000;  //vse digi
  127.   ANSELC            :=%00000000;  //vse digi
  128.  
  129.   U1CON0            :=%00110000;
  130.   UART1_Init(57600);                                // Initialize UART module at 19200 bps
  131.   UART_Set_Active(@UART1_Read, @UART1_Write, @UART1_Data_Ready, @UART1_Tx_Idle); // set UART1 active
  132.  
  133.   TMR6_Initialize();
  134.   ADCC_Initialize;
  135.    
  136.   poc:=0;
  137.   GIE_bit         := 1;
  138.   ADCC_Start(0);
  139.  
  140.   while (TRUE) do
  141.     begin
  142.     end;
  143.  
  144. end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement