A PHP Error was encountered

Severity: 8192

Message: strpos(): Non-string needles will be interpreted as strings in the future. Use an explicit chr() call to preserve the current behavior

Filename: database/DB_driver.php

Line Number: 1876

A PHP Error was encountered

Severity: 8192

Message: strpos(): Non-string needles will be interpreted as strings in the future. Use an explicit chr() call to preserve the current behavior

Filename: database/DB_driver.php

Line Number: 1876

A PHP Error was encountered

Severity: 8192

Message: strpos(): Non-string needles will be interpreted as strings in the future. Use an explicit chr() call to preserve the current behavior

Filename: database/DB_driver.php

Line Number: 1876

A PHP Error was encountered

Severity: 8192

Message: strpos(): Non-string needles will be interpreted as strings in the future. Use an explicit chr() call to preserve the current behavior

Filename: database/DB_driver.php

Line Number: 1876

A PHP Error was encountered

Severity: 8192

Message: strpos(): Non-string needles will be interpreted as strings in the future. Use an explicit chr() call to preserve the current behavior

Filename: database/DB_driver.php

Line Number: 1876

A PHP Error was encountered

Severity: 8192

Message: strpos(): Non-string needles will be interpreted as strings in the future. Use an explicit chr() call to preserve the current behavior

Filename: database/DB_driver.php

Line Number: 1876

A PHP Error was encountered

Severity: 8192

Message: strpos(): Non-string needles will be interpreted as strings in the future. Use an explicit chr() call to preserve the current behavior

Filename: database/DB_driver.php

Line Number: 1876

A PHP Error was encountered

Severity: 8192

Message: strpos(): Non-string needles will be interpreted as strings in the future. Use an explicit chr() call to preserve the current behavior

Filename: database/DB_driver.php

Line Number: 1876

A PHP Error was encountered

Severity: 8192

Message: strpos(): Non-string needles will be interpreted as strings in the future. Use an explicit chr() call to preserve the current behavior

Filename: database/DB_driver.php

Line Number: 1876

A PHP Error was encountered

Severity: 8192

Message: strpos(): Non-string needles will be interpreted as strings in the future. Use an explicit chr() call to preserve the current behavior

Filename: database/DB_driver.php

Line Number: 1876

A PHP Error was encountered

Severity: 8192

Message: Function create_function() is deprecated

Filename: geshi/geshi.php

Line Number: 4751

A PHP Error was encountered

Severity: 8192

Message: strpos(): Non-string needles will be interpreted as strings in the future. Use an explicit chr() call to preserve the current behavior

Filename: database/DB_driver.php

Line Number: 1876

A PHP Error was encountered

Severity: 8192

Message: strpos(): Non-string needles will be interpreted as strings in the future. Use an explicit chr() call to preserve the current behavior

Filename: database/DB_driver.php

Line Number: 1876

A PHP Error was encountered

Severity: 8192

Message: strpos(): Non-string needles will be interpreted as strings in the future. Use an explicit chr() call to preserve the current behavior

Filename: database/DB_driver.php

Line Number: 1876

A PHP Error was encountered

Severity: 8192

Message: strpos(): Non-string needles will be interpreted as strings in the future. Use an explicit chr() call to preserve the current behavior

Filename: database/DB_driver.php

Line Number: 1876

A PHP Error was encountered

Severity: 8192

Message: strpos(): Non-string needles will be interpreted as strings in the future. Use an explicit chr() call to preserve the current behavior

Filename: database/DB_driver.php

Line Number: 1876

Termin 6 MPS - mcpaste

Termin 6 MPS

Von tobi, 9 Jahre vorher, geschrieben in C, aufgerufen 1'855 mal.
URL https://mcpaste.de/view/0e2824f0 Einbetten
Paste herunterladen oder Rohtext anzeigen
  1. #include "../h/pmc.h"
  2. #include "../h/tc.h"
  3. #include "../h/pio.h"
  4. #include "../h/aic.h"
  5. #include "./config.cfg"
  6.  
  7. // fuer die Initialisierung der Zaehler
  8. #define TC_INIT TC_CLKS_MCK2 | TC_LDBSTOP | TC_CAPT | TC_LDRA_RISING_EDGE | TC_LDRB_RISING_EDGE
  9.  
  10.  
  11. void init_Timer3(void);
  12. int MessungderMasse(void);
  13. void init_Waage(void);
  14. void init_keys(void);
  15. void init_leds(void);
  16. void itos(int, char *);
  17. void taste_irq_handler (void) __attribute__ ((interrupt));
  18.  
  19. volatile int key;
  20.  
  21. int main(void)
  22. {
  23.   /* ################ Structs definieren ##################### */
  24.         StructPMC* pmcbase      = PMC_BASE;             // Basisadresse des PMC
  25.         StructPIO* piobaseA     = PIOA_BASE;            // Basisadresse PIO A
  26.         StructPIO* piobaseB     = PIOB_BASE;            // Basisadresse PIO B
  27.         StructAIC* aicbase      = AIC_BASE;
  28.         pmcbase->PMC_PCER       = 0x6200;       // Peripheral Clocks einschalten für PIOB, PIOA, Timer3
  29.  
  30.   /* ################ Ende Structs ########################### */
  31.  
  32.  
  33.   /* ################### initalisierung ###################### */
  34.  
  35.         init_Timer3(); // init Pumpe
  36.         init_ser();
  37.         init_Waage();
  38.         init_keys();
  39.        
  40.   /*########### Interrupt Service Routine ausführbar machen ################*/
  41.         aicbase->AIC_IDCR = 1 << 14;
  42.         aicbase->AIC_ICCR = 1 << 14;
  43.         aicbase->AIC_SVR[PIOB_ID] = (unsigned int)taste_irq_handler;
  44.         aicbase->AIC_SMR[PIOB_ID] = 0x7;
  45.         aicbase->AIC_IECR = 1 << 14;
  46.         piobaseB->PIO_IER = KEY1 | KEY2;
  47.        
  48.   /* ################## ende initalisierung ################## */
  49.  
  50.         while(1)
  51.         {
  52.                 key = 0;
  53.                 puts(Begruessung);
  54.                 puts(Information);
  55.                
  56.  /* ################## Aufgabe 3 ################## */
  57.                 int MasseBecher;
  58.                 int Masse;
  59.                 Masse = 0;
  60.                 MasseBecher = 0;
  61.  
  62.                 do{
  63.                 aicbase->AIC_IECR = 1 << 14; // Interrupt einschalten
  64.                 while(key!=1)
  65.                 {
  66.                         pmcbase->PMC_SCDR = 1; // Prozessor ausgeschaltet zum Stomsparen
  67.                 }
  68.                 aicbase->AIC_IDCR = 1 << 14; // INterrupt ausschalten
  69.                 MasseBecher = MessungderMasse();
  70.                 if(MasseBecher > 1)     // Wenn Becher dasteht, Gewicht ausgeben
  71.                 {
  72.                         char arr[11];
  73.                         itos(MasseBecher, arr);
  74.                         puts(arr);
  75.                         puts("\r");
  76.                 }
  77.                 }while(MasseBecher<2);
  78. /* ################## Aufgabe 4 ################## */
  79.                 aicbase->AIC_IECR = 1 << 14; // Interrupt einschalten
  80.                 puts(zweiteTaste);
  81.                
  82.                 while(key!=2)
  83.                 {
  84.                         pmcbase->PMC_SCDR = 1; // Prozessor ausgeschaltet zum Stomsparen
  85.                 }
  86.                 aicbase->AIC_IDCR = 1 << 14; // Interrupt ausschalten
  87.                 MasseBecher = MessungderMasse();
  88.                 if(MasseBecher > 1)     // Wenn der Becher noch dasteht
  89.                 {
  90.                         piobaseA->PIO_PDR  = (1<<PIOTIOA3) ;    // Pumpen
  91.                         while((Masse - MasseBecher) < Einfuellmenge)
  92.                         {
  93.                                 int MasseAlt;
  94.                                 MasseAlt=Masse;
  95.                                 Masse = MessungderMasse();
  96.                                 if(MasseAlt != Masse)   // Wenn die Masse sich geändert hat
  97.                                 {
  98.                                         char arr[12];
  99.                                         itos(Masse-MasseBecher, arr);
  100.                                         puts(arr);      // ausgeben
  101.                                         puts("\r");
  102.                                 }
  103.                                 if(Masse+10 < MasseAlt) // wenn der Becher weggenommen wird
  104.                                 {
  105.                                         piobaseA->PIO_PER  = (1<<PIOTIOA3); // auf jeden Fall das Pumpen aufhören!
  106.                                         break;
  107.                                 }
  108.                         }
  109.                         piobaseA->PIO_PER  = (1<<PIOTIOA3);     // Pumpen aufhören!
  110.                 }
  111.                
  112.                 if((Masse-MasseBecher) < 49)    // Wenn der Becher zu früh weggenommen wurde
  113.                 {
  114.                         puts(ERROR_Becher);
  115.                 }
  116.                 else
  117.                 {
  118.                         puts(Success);
  119.                         puts(Success_Volume);
  120.                         char arr[12];
  121.                         itos(Masse-MasseBecher, arr);
  122.                         puts(arr);
  123.                         puts(unit);
  124.                         puts(Becherweg);
  125.                 }
  126.                 while(Masse!=0){
  127.                         Masse = MessungderMasse();
  128.                 }                      
  129.         }
  130.  
  131. }
  132.  
  133. void taste_irq_handler (void)
  134. {
  135.   StructPIO* piobaseA = PIOA_BASE;
  136.   StructPIO* piobaseB   = PIOB_BASE;            // Basisadresse PIO B
  137.   StructAIC* aicbase  = AIC_BASE;               // Basisadresse des Advanced interrupt controllers
  138.  
  139.  
  140.         if(!(piobaseB->PIO_PDSR & KEY1))
  141.         {
  142.                 key = 1;
  143.        
  144.         }
  145.         if(!(piobaseB->PIO_PDSR & KEY2))
  146.         {
  147.                 key = 2;
  148.         }
  149.        
  150.        
  151.         aicbase->AIC_EOICR = piobaseB->PIO_ISR; //Ende der Interruptserviceroutine
  152. }
  153.  
  154. void init_PIO(void)
  155. {
  156.         StructPMC* pmcbase = PMC_BASE;
  157.         StructPIO* piobaseA = PIOA_BASE;
  158.         StructPIO* piobaseB = PIOB_BASE;
  159.         pmcbase->PMC_PCER = 0x6000;             // PIOA, PIOB
  160.         piobaseA->PIO_PDR = 0x090;              // p4 p7
  161.        
  162. }
  163.  
  164.  
  165. void init_leds(void)
  166. {
  167.   StructPMC* pmcbase = PMC_BASE;
  168.   // Basisadresse des PMC
  169.   StructPIO* piobaseB = PIOB_BASE;
  170.   // Basisadresse PIO B
  171.   piobaseB->PIO_PER = ALL_LEDS;
  172.   piobaseB->PIO_OER = ALL_LEDS;
  173. }
  174.  
  175. void init_keys(void)
  176. {
  177.   StructPMC* pmcbase = PMC_BASE;
  178.   // Basisadresse des PMC
  179.   StructPIO* piobaseB = PIOB_BASE;
  180.   // Basisadresse PIO B
  181.   pmcbase->PMC_PCER = 0x4000; // Peripheral Clocks aktiv für PIOB
  182.   piobaseB->PIO_PER = KEY1 | KEY2;  // Key1 und 2 einschalten.
  183. }
  184.  
  185. void init_Waage(void)
  186. {
  187.         StructPMC* pmcbase = PMC_BASE;
  188.         StructTC* tcbase4 = TCB4_BASE;
  189.         StructTC* tcbase5 = TCB5_BASE;
  190.         StructPIO* piobaseA   = PIOA_BASE;              // Basisadresse PIO A
  191.  
  192.         piobaseA->PIO_PDR = 0x090;        // p4 p7
  193.        
  194.         pmcbase->PMC_PCER = 0x00f00; // Clock Timer5, Timer4 einschalten
  195.         // Timer4:
  196.         tcbase4->TC_CCR = TC_CLKDIS;    // CCR= CounterControlRegister; TC_CLKDIS=0x2
  197.         tcbase4->TC_CMR = TC_INIT;        // Timer Counter Mode Register
  198.         tcbase4->TC_CCR = TC_CLKEN;        // 0x1
  199.         tcbase4->TC_CCR = TC_SWTRG;        // 0x4
  200.         // Timer5:
  201.         tcbase5->TC_CCR = TC_CLKDIS;    // CCR= CounterControlRegister; TC_CLKDIS=0x2
  202.         tcbase5->TC_CMR = TC_INIT;        // Timer Counter Mode Register
  203.         tcbase5->TC_CCR = TC_CLKEN;        // 0x1
  204.         tcbase5->TC_CCR = TC_SWTRG;        // 0x4
  205. }
  206.  
  207.  
  208.  
  209. void init_Timer3( void )        // Pumpe
  210. {
  211.   StructTC* timerbase3  = TCB3_BASE;            // Basisadressse TC Block 1
  212.   StructPIO* piobaseA   = PIOA_BASE;            // Basisadresse PIO A
  213.   StructPMC* pmcbase    = PMC_BASE;             // Basisadresse des PMC
  214.  
  215.   pmcbase->PMC_PCER     = 0x200;        // Peripheral Clocks einschalten für Timer3
  216.  
  217.         timerbase3->TC_CCR = TC_CLKDIS;                 // Disable Clock
  218.  
  219.  // Initialize the mode of the timer 3
  220.   timerbase3->TC_CMR =
  221.     TC_ACPC_CLEAR_OUTPUT  |    //ACPC    : Register C clear TIOA
  222.     TC_ACPA_SET_OUTPUT    |    //ACPA    : Register A set TIOA
  223.     TC_WAVE               |    //WAVE    : Waveform mode
  224.     TC_CPCTRG             |    //CPCTRG  : Register C compare trigger enable
  225.     TC_CLKS_MCK8;              //TCCLKS  : MCKI / 8
  226.  
  227.   // Initialize the counter:
  228.   timerbase3->TC_RA = 31250;    //50% High
  229.   timerbase3->TC_RC = 62500;    //
  230.  
  231.   // Start the timer :
  232.   timerbase3->TC_CCR = TC_CLKEN ;                               // Timer Enable
  233.   timerbase3->TC_CCR = TC_SWTRG ;                               // Softwaretrigger
  234.   piobaseA->PIO_PER  = (1<<PIOTIOA3) ;  // Pinport A3 enable
  235.   piobaseA->PIO_OER  = (1<<PIOTIOA3) ;  // Outputenable
  236.   piobaseA->PIO_CODR = (1<<PIOTIOA3) ;  // Clear output data register -> kein anderes signal liegt an
  237. }
  238.  
  239.  
  240. int MessungderMasse(void){
  241.  
  242.         StructPMC* pmcbase = PMC_BASE;
  243.         StructPIO* piobaseA = PIOA_BASE;
  244.         StructPIO* piobaseB = PIOB_BASE;
  245.         StructTC* tcbase4 = TCB4_BASE;
  246.         StructTC* tcbase5 = TCB5_BASE;
  247.  
  248.  
  249.         volatile int captureRA1;
  250.         volatile int captureRB1;
  251.         volatile int capturediff1;
  252.         volatile float Periodendauer1;
  253.  
  254.         volatile int captureRA2;
  255.         volatile int captureRB2;
  256.         volatile int capturediff2;
  257.         volatile float Periodendauer2;
  258.  
  259.         volatile int ave = 0;
  260.         // Periodendauer der Waagensignale messen
  261.         // Signal an TIOA4 ca. 16kHz entspricht ca. einer Periodendauer von 62,5us
  262.         // durch den Teiler von 32 ergeben sich ca. 2ms
  263.         // Zähler mit positiver Flanke starten
  264.         int i = 0;
  265.         for(i=0;i<4;i++){
  266.         tcbase4->TC_CCR = TC_SWTRG;
  267.         tcbase5->TC_CCR = TC_SWTRG;
  268.  
  269.  
  270.         while (!( tcbase4->TC_SR & 0x40)); // Capture Register B wurde geladen (RB Loading Status) Messung abgeschlossen
  271.         captureRA1 = tcbase4->TC_RA; // Speichert TC_RA (1. Gemesser wert) in Variable
  272.         captureRB1 = tcbase4->TC_RB;
  273.  
  274.         while (!( tcbase5->TC_SR & 0x40)); // Capture Register B wurde geladen (Messung abgeschlossen
  275.         captureRA2 = tcbase5->TC_RA;
  276.         captureRB2 = tcbase5->TC_RB;
  277.  
  278.         capturediff2 = captureRB2 - captureRA2;
  279.         Periodendauer2 = capturediff2; // Zeit in us
  280.         capturediff1 = captureRB1 - captureRA1;
  281.         Periodendauer1 = capturediff1; // Zeit in us  
  282.    
  283.      
  284.  
  285.     volatile int C1 = c1;
  286.     volatile int C2 = c2;
  287.    
  288.         ave += (C1 * ((Periodendauer1/Periodendauer2)-1))-C2;
  289.     }
  290.    
  291.     return (ave/4)+2;
  292. }
  293.  
  294. void itos(int i, char * arr)
  295. {
  296.         if(i==0)
  297.         {
  298.                 arr[0]='0';
  299.                 arr[1]= 0 ;
  300.                 return;
  301.         }
  302.         int count;
  303.         int tmpi;
  304.         tmpi = i;
  305.         count = 0;
  306.         char cache;
  307.         int negative;
  308.         negative = 0;
  309.         if(i < 0 )      // Ist die Zahl negativ?
  310.         {
  311.                 negative = 1;
  312.                 tmpi = tmpi * -1;
  313.                 i = i * -1;
  314.         }
  315.         while(tmpi > 0) // wie viele Stellen hat unsere Zahl?
  316.         {
  317.                 tmpi = tmpi / 10;
  318.                 count++;
  319.         }
  320.         if(negative == 1)       // Wenn sie negativ ist, eine Stelle mehr, an Stelle 0 kommt das -
  321.         {
  322.         count++;
  323.         //chr[0] = '-';
  324.         }
  325.         int tmpcount;
  326.         tmpcount = count + 1;
  327.         char chr[tmpcount];     // Array erstellen (+1 für 0 an die ende)
  328.         chr[count] = 0;
  329.         if(negative == 1)       // Wenn sie negativ ist, eine Stelle mehr, an Stelle 0 kommt das -
  330.         {
  331.         chr[0] = '-';
  332.         }
  333.  
  334.         int j;
  335.         j= count - 1;
  336.         for(j;j-negative>=0;j--)        // Achtung Achtung bei negativen Zahlen hier eine Veränderung! oder so...
  337.         {
  338.                 cache = i%10;   // Das hinterste Zeichen isolieren
  339.                 i = i/10;       // Die Nächste Stelle nach ganz rechts
  340.                 chr[j] = cache + '0'; // und an die letzte Stelle des Arrays schreiben
  341.         }      
  342.         j=0;
  343.         for(j;j<11;j++)
  344.         {
  345.                 arr[j] = chr[j];
  346.         }
  347. }
  348.  

Antwort auf "Termin 6 MPS"

Hier kannst Du auf den Paste von oben antworten

A PHP Error was encountered

Severity: 8192

Message: strpos(): Non-string needles will be interpreted as strings in the future. Use an explicit chr() call to preserve the current behavior

Filename: database/DB_driver.php

Line Number: 1876