Advertisement
Wistaro

Infranor_psoc_IO_test

Jun 14th, 2017
421
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.60 KB | None | 0 0
  1. //----------------------------------------------------------------------------
  2. // Librairies
  3. //----------------------------------------------------------------------------
  4. #include "main.h"                               // all necessary librairies are included in main.h
  5.  
  6. //----------------------------------------------------------------------------
  7. // Extern variables declaration
  8. //----------------------------------------------------------------------------
  9.  
  10. //----------------------------------------------------------------------------
  11. // Global variables declaration
  12. //----------------------------------------------------------------------------
  13. int     ISR_Counter = 0;
  14. char counter_100ms;
  15.  
  16. char isOk = 1; //OK: 1, Default: 0
  17. char checked = 0; //0: not checked yet, 1:already checked
  18.  
  19. //----------------------------------------------------------------------------
  20. // Interrupts declaration
  21. //----------------------------------------------------------------------------
  22. #pragma interrupt_handler Timer_500us_ISR           // handle 500us interrupts
  23.  
  24. //----------------------------------------------------------------------------
  25. // Functions
  26. //----------------------------------------------------------------------------
  27. void Timer_500us_ISR(void)
  28.     {
  29.     M8C_EnableGInt;                                 // Re-activate interrupts for ADC process
  30.     Clear_Watchdog_Timer();
  31.  
  32.     ISR_Counter++;
  33.    
  34.     if(ISR_Counter >= 200) { //100ms       
  35.         ISR_Counter = 0;
  36.         counter_100ms++;
  37.     }
  38.    
  39.     if(counter_100ms == 5){ //every 500us
  40.        
  41.         if(checked == 0) {
  42.             sendData(0x44,0x44,0x45); //send 01010101
  43.             readData(0x44,0x44,0x45); //read and compare data
  44.             checked = 1;
  45.         }  
  46.             if(isOk == 0){
  47.                 PRT1DR^=0x01; //blink red led if default
  48.                
  49.                 /*debug*/
  50.                
  51.                 //PRT0DR^=0xFF;
  52.                 //PRT1DR^=0xFF;
  53.                 //PRT2DR^=0xFF;
  54.                
  55.             }
  56.            
  57.         counter_100ms = 0; 
  58.    
  59.     }
  60.    
  61.     }
  62.    
  63. void sendData(char data1, char data2, char data3){
  64.    
  65.     /*
  66.     * Registers: PRT0DR, PRT1DR and PRT2DR   
  67.     */
  68.  
  69.    
  70.     PRT0DR|=data1;
  71.     PRT1DR|=data2;                  //write data on output register
  72.     PRT2DR|=data3; 
  73. }
  74.  
  75. void readData(char data1, char data2, char data3){
  76.    
  77.     /*Read and compare to supplied data*/
  78.    
  79.     volatile char buff1, buff2, buff3;
  80.     char checkSum1,checkSum2,checkSum3; //contain expected registers values
  81.    
  82.     /*checkSum1 = data1 | (data1<<1);
  83.     checkSum2 = data2 | (data2<<1);
  84.     checkSum3 = data3 | (data3<<1);*/
  85.    
  86.     checkSum1 = 0xEC;
  87.     checkSum2 = 0x04;
  88.     checkSum3 = 0xC;
  89.    
  90.     buff1 = PRT0DR;
  91.     buff2 = PRT1DR;
  92.     buff3 = PRT2DR;
  93.    
  94.     if(buff1 != checkSum1 || buff3 != checkSum3 || buff2 != checkSum2){
  95.         isOk = 0;
  96.        
  97.     }else{
  98.         PRT1DR|=0x02; //set active ok led bit
  99.     }
  100.    
  101.    
  102.  
  103. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement