/********************************************************************************
 *    Description: ECE331 term project - Cable box IR transmitter.
 *    Source:      project_main.h
 *    Date:        11-14-2006
 *    Author:      Eric Lindberg, Andrew Toth
 ********************************************************************************/

#include <hidef.h>				              //Includes Code Warrior definitions	
#include "per_C32_L45J.h"


//macros
#define CLI()   {asm cli;}					    // enable global interrupts
#define SEI()   {asm sei;}				      // disable global interrupts

//macros to turn on/off the carrier wave
#define CARRIER_OFF {Pwm.pwmdty[4].byte = 255;}
#define CARRIER_ON {Pwm.pwmdty[4].byte = CARRIER_DTY;}

//function signatures
void SetLedindicator();
void SetClockSpeed();
void send_ir_signal(char);
void change_to_channel(int);
void output_init_pulse();
void output_zero_bit();
void output_one_bit();
void output_sync_pulse();
void send_code(ulong);
void delay_50_ms();
void clock_isr();
                          
//these timings correspond to how long the pwm output should be on or off
#define SHORT_HIGH 370
#define LONG_LOW   3472
#define SHORT_LOW  1748
#define LONG_HIGH  6750
#define SYNC_TIME_1 60000
#define SYNC_TIME_2 15000
#define FIFTY_MS 37500

//how long to wait between sending digits of a channel number
#define NUMBER_OF_50MS_DELAYS_BETWEEN_DIGITS 20

//Constant to disable the programmed channel change timer
// Works because the hours variable never equals -1.
#define PROG_DISABLED -1

//Some time-based constants
#define FIFTY_MS_IN_A_SECOND   20
#define SECONDS_IN_A_MINUTE 60
#define MINUTES_IN_AN_HOUR  60
#define HOURS_IN_A_DAY      24

//Number of bits in each binary code
#define BITS_IN_CODE        16
//Mask of the MSB
#define FIRST_BIT_MASK      0x8000

//Sets the pwm output to a 33kHz square wave. 
#define CARRIER_PER  182;
#define CARRIER_DTY  91; 

//Our osc clock is 24MHz
extern ulong busclk;
#define oscclk 24000
#define BaudRate 9600

//SCI includes
#include "sci.h"
extern int sprintf (const char *format, ...);
extern int printf (const char *format, ...);
extern int scanf (const char *format, ...);
#define XOn  0x11
#define XOff 0x13
#define RxBufSize 64
#define TxBufSize 32
#define XOnCount RxBufSize - 8
#define XOffCount 18
