Advertisement
Guest User

Untitled

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