pyrohaz

H62EDP Send Data Code

Feb 13th, 2015
319
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.34 KB | None | 0 0
  1.  
  2. #define START_B     1
  3. #define HIGH_B      2
  4. #define LOW_B       3
  5. #define STOP_B      4
  6.  
  7. //FSK
  8. void SendByteFSK(unsigned char B){
  9.     unsigned char SCnt, Skip;
  10.     char CBit;
  11.     unsigned int Cnt;
  12.    
  13.     for(CBit = -1; CBit<9; CBit++){
  14.         if(CBit == -1) Skip = START_B;
  15.         else if(CBit == 8) Skip = STOP_B;
  16.         else{
  17.         //Data sent LSB first
  18.             if(B & (1<<CBit)) Skip = HIGH_B;
  19.             else Skip = LOW_B;
  20.         }
  21.        
  22.         //Changing skip changed frequency, if skip is larger, sine wave is faster
  23.         for(Cnt = 0; Cnt<128; Cnt += Skip){
  24.             setDutyCycle(sinevals[C]);
  25.             //Delay1KTCYx(1);
  26.         }
  27.     }
  28. }
  29.  
  30. //ASK
  31. void SendByteASK(unsigned char B){
  32.     unsigned char SCnt, Ampl;
  33.     char CBit;
  34.     unsigned int Cnt;
  35.    
  36.     for(CBit = -1; CBit<9; CBit++){
  37.         if(CBit == -1) Ampl = START_B;
  38.         else if(CBit == 8) Ampl = STOP_B;
  39.         else{
  40.         //Data sent LSB first
  41.             if(B & (1<<CBit)) Ampl = HIGH_B;
  42.             else Ampl = LOW_B;
  43.         }
  44.        
  45.         //Constant frequency
  46.         for(Cnt = 0; Cnt<128; Cnt++){
  47.             //If Ampl is 4, amplitude will be 1, if Ampl is 3, amplitude will be 3/4 etc.
  48.             setDutyCycle((sinevals[C]*Ampl)>>2);
  49.             //Delay1KTCYx(1);
  50.         }
  51.     }
  52. }
  53.  
  54. //Style == 0 is ASK, Style == 1 is FSK
  55. void SendArray(unsigned char *Ar, unsigned int Len, unsigned char Style){
  56.     unsigned int Cnt;
  57.    
  58.     if(Style == 0) for(Cnt = 0; Cnt<Len; Cnt++) SendByteASK(Ar[Cnt]);
  59.     else for(Cnt = 0; Cnt<Len; Cnt++) SendByteFSK(Ar[Cnt]);
  60. }
Advertisement
Add Comment
Please, Sign In to add comment