
// last modified: 3:30 PM 1/22/2011


#include <htc.h>
#include "microwire.h"

__CONFIG(0x2FB8);////micro specific


/* microwire clock pulse:

            T_CLOCK     
   ________|````````|________ 
   T_CLOCK           T_CLOCK    
*/

//CONFIGURE CLOCK AND DELAY TIMING FROM HERE:
#define T_CLOCK     3      //ms


#define DELAY()     __delay_ms(T_CLOCK);

//send clock pulse
#define CLOCK_PULSE()   DELAY();\
                        PIN_CLK = 1;\
                        DELAY();\
                        PIN_CLK = 0;\
                        DELAY()\
                        
                        


#define LATCH() PIN_DATA = 0;\
                DELAY();DELAY();\
                PIN_LE = 1;\
                DELAY();DELAY();DELAY();\
                PIN_LE = 0;\
                DELAY();DELAY();DELAY()

void send_LMX2324()
{
    unsigned char i = 0;
    
    //init outputs
    PIN_CLK = 0;
    PIN_DATA = 0;
    PIN_LE = 0;
    DELAY();
    
    
    //send N register data//////////////////////////////////////////////
    for(i = 18; i != 0; i--)
    {
        PIN_DATA = N_REG >> (i - 1);
        CLOCK_PULSE();
    }
    LATCH();//----------------------------------------------------------
    
    //send R register data//////////////////////////////////////////////
    for(i = 18; i != 0; i--)
    {
        PIN_DATA = R_REG >> (i - 1);
        CLOCK_PULSE();
    }
    LATCH();//----------------------------------------------------------


    //clear outputs
    PIN_CLK = 0;
    PIN_DATA = 0;
    PIN_LE = 0;
    DELAY();
    
}    

void main(void)
{
    unsigned int i = 0;
    //init
    TRISB = 0x00;//outbut for port b
    
    PIN_DATA = 0;
    PIN_CLK = 0;
    PIN_LE = 0;



    send_LMX2324();
    
    for(;;){};//do nothing
}
