It is currently Thu Sep 09, 2010 12:45 am




Post new topic Reply to topic  [ 1 post ] 
Using the HCS08 To Send Wireless Data ( Morse Code ) 
Author Message
Site Admin

Joined: Sat Jan 24, 2009 3:56 pm
Posts: 32
Post Using the HCS08 To Send Wireless Data ( Morse Code )
For this project I used processor expert and an output bean initialized to high.

Code:
/* arrayMask is defined globally as: arrayMask [8] = { 0x01, 0x02,0x04,0x08,0x10,0x20,0x40,0x80 }; */

/** This encodes zeros and ones as hi and creates an encoded 'clock pulse'
*  allowing rf reciever to send data correctly.  Pins are set low since the HCS08 does
*  not support active high interrupts!!
*/

void sendToRF(byte newbyte){                  // takes in a byte of data
     int cnt;
     for(cnt = 0; cnt < 8; cnt++)             // 8 iterations to go byte by byte with each mask
     {                   
        OUTPIN = 0;
       
        if(newbyte & arrayMask[cnt])          // do a bitwise AND to see if particular bit is a 1
            waitOne();                        // a one is low for XXXms
        else               
            waitZero();                       // a zero is low for XXXms
       
        OUTPIN = 1;
        waitLow();                            // pulse stays low for 100us
     }
      OUTPIN = 1;                           // return to a logic high state
      waitLow();
      waitLow();
      waitLow();
}


Code:
/* Waits can be adjusted to meet your individual needs.  In my actual implementation
    wait zero was reduced to almost no clock cycles since the receiver uses if / else logic
    which only requires that there be enough to distinguish a zero from a one.

void waitOne(void)
{
      int delay1 = 400;
      int delay2 = 10;   
      while(delay1 > 1)
      {
         --delay1;
         while(delay2 >= 1)
         {
            --delay2;
         }
      } 
}

void waitZero(void)
{                       
      int delay1 = 120;
      int delay2 = 10;   
      while(delay1 > 1)
      {
         --delay1;
         while(delay2 >= 1)
         {
            --delay2;
         }
      }   
}

void waitLow(void)
{
      int delay1 = 200;
      int delay2 = 10;   
      while(delay1 > 1)
      {
         --delay1;
         while(delay2 >= 1)
         {
            --delay2;
         }
      } 
}


This function is a hacked / modified version of the function I present in the Write To EEPROM example.

Code:
/** Read in data from EEprom.  Data is stored in MISO
*  register in which *data pointer is passed to SPI
*  read function.
*
*  Read sequence is as displayed in 25AA512 datasheet
*
*  Interrupts are disabled while all data is read back
*  beginning at address 0 up to the address stopped at.
*
*  The transmitter is connected to MISO and grabs data
*  as it is clocked into the MISO register. This occurs
*  at between 16-18 samples per second.
*/



void sendData(void){
 
  LED_0 = 1;
  LED_1 = 0;
  address_byte = &counter;            // reassign address_byte to be dependent on counter;
 
  for(counter = 0; counter <= address; counter++){

 
      if(!(counter % 100)){          // toggles when counter == 0 or a multiple of 100
          LED_0 = !LED_0;
          LED_1 = !LED_1;
      }
     
      testArray2[counter % 100] = SPI_READ(address_byte[0],address_byte[1]);
     
      if(((counter % 100) == 99) || (counter == address)){
     
          if(counter == address)
              temp = address % 100; 
          else
              temp = 100;
         
          for(ct = 0; ct < temp; ct++)
             sendToRF(testArray2[ct]);
      }
     
  }
}



For this project I used processor expert and an interrupt bean. The interrupt was set to trigger on low. This was because the events.c relied on counting how long the signal was low.

Code for the MC9S08QG8 on the receiver end:

The ISR

Code:
ISR(Got_Bit_Interrupt_Interrupt)
{
  IRQSC_IRQACK = 1;                    /* Clear the interrupt flag */
  Got_Bit_Interrupt_OnInterrupt();
}



Events.c

Code:
void Got_Bit_Interrupt_OnInterrupt(void)
{
    counter = 0xFFFF;
    do
      counter--;
    while(PTBD_PTBD7 == 0);
   
    if(counter < 0xFDEF)      // if greater than 1500 clock cycles
      bits[maskNum] = 0xFF;   // we got a '1'
    else
      bits[maskNum] = 0x00;   // we got a '0'
   
    maskNum++;
}


The main code on the receiver end:

Code:
/* Including used modules for compiling procedure */
#include "Cpu.h"
#include "Events.h"
#include "Got_Bit_Interrupt.h"
#include "High.h"
/* Include shared modules, which are used for whole project */
#include "PE_Types.h"
#include "PE_Error.h"
#include "PE_Const.h"
#include "IO_Map.h"
#include "RUNEXTERN.h"

/**********************************************************************************
**                                 DECLARATIONS                                 **
*********************************************************************************/

void sciInit(void);
void sendSCI(void);
void decoder(void);


/**********************************************************************************
**                               GLOBAL VARIABLES                               **
*********************************************************************************/

int count;
byte temp;
byte toSerial;
byte arrayMask[8] = {0x01,0x02,0x04,0x08,0x10,0x20,0x40,0x80};



/**********************************************************************************
**                                    MAIN                                      **
*********************************************************************************/

void main(void){

  /*** Processor Expert internal initialization. DON'T REMOVE THIS CODE!!! ***/
  PE_low_level_init();
  /*** End of Processor Expert internal initialization.                    ***/

  Cpu_DisableInt();
  sciInit();
  Cpu_EnableInt();
  decoder();       
     


  /*** Processor Expert end of main routine. DON'T MODIFY THIS CODE!!! ***/
  for(;;){}
  /*** Processor Expert end of main routine. DON'T WRITE CODE BELOW!!! ***/
} /*** End of main routine. DO NOT MODIFY THIS TEXT!!! ***/


/**********************************************************************************
**                                 SCI FUNCTIONS                                **
*********************************************************************************/

  void sciInit(void){ 
    SOPT1 = 0x10;
    SCIBD = 26;
    SCIC2 = 0x08;
  }
   
  void sendSCI(void){
        while(!SCIS1_TDRE);
        SCID = toSerial;
        decoder();
  }



/**********************************************************************************
**                            DECODER FUNCTIONS                           **
*********************************************************************************/


/** This encodes zeros and ones as hi and creates an encoded 'clock pulse'
*  allowing rf reciever to send data correctly
*/


  void decoder(void){
       maskNum = 0;
       toSerial = 0;
       while(maskNum < 8); 
       for(count = 0; count < 8; count++){
            temp = (bits[count] & arrayMask[count]);
            toSerial |= temp;
       }
       sendSCI();
  }


Sun Mar 22, 2009 3:32 pm
Profile
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 1 post ] 


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB © phpBB Group.
Designed by Vjacheslav Trushkin for Free Forum/DivisionCore.